Skip to content

Commit

Permalink
Add download option
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Dec 28, 2024
1 parent 1c7e4f9 commit 686eba4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 34 deletions.
58 changes: 54 additions & 4 deletions apps/showcase/components/layout/AppDesigner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,24 @@
</template>

<script>
import { $dt } from '@primevue/themes';
import EventBus from '@/app/AppEventBus';
import { $dt, updatePreset } from '@primevue/themes';
export default {
setup() {
const runtimeConfig = useRuntimeConfig();
return {
designerApiBase: runtimeConfig.public.designerApiBase
};
},
provide() {
return {
designerService: {
refreshACTokens: this.refreshACTokens,
saveTheme: this.saveTheme,
downloadTheme: this.downloadTheme
downloadTheme: this.downloadTheme,
applyTheme: this.applyTheme
}
};
},
Expand All @@ -55,8 +64,49 @@ export default {
onHide() {
this.deferredTabs = true;
},
downloadTheme(theme) {
// TODO: Fetch from endpoint
async downloadTheme(theme) {
try {
const response = await $fetch(this.designerApiBase + '/theme/download/' + this.$appState.designer.licenseKey + '/' + theme.t_key, {
responseType: 'blob'
});
if (response.error) {
this.$toast.add({ severity: 'error', summary: 'An Error Occurred', detail: error.message, life: 3000 });
} else {
const blobUrl = window.URL.createObjectURL(response);
const link = document.createElement('a');
link.href = blobUrl;
link.download = theme.t_name + '.zip';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(blobUrl);
}
} catch (err) {
console.log(err);
this.$toast.add({ severity: 'error', summary: 'An Error Occurred', detail: 'Failed to download file', life: 3000 });
}
},
async updateTheme(theme) {
const { error } = await $fetch(this.designerApiBase + '/theme/update', {
method: 'POST',
body: {
key: theme.key,
preset: theme.preset,
config: theme.config,
license_key: this.$appState.designer.licenseKey
}
});
if (error) {
this.$toast.add({ severity: 'error', summary: 'An error occured', detail: error.message, life: 3000 });
}
},
applyTheme(theme) {
this.updateTheme(theme);
updatePreset(theme.preset);
EventBus.emit('theme-palette-change');
},
camelCaseToDotCase(name) {
return name.replace(/([a-z])([A-Z])/g, '$1.$2').toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ export default {
default: true
}
},
inject: ['designerService'],
methods: {
onKeyDown(event) {
if (event.code === 'Enter' || event.code === 'NumpadEnter') {
this.apply();
this.designerService.applyTheme(this.$appState.designer.theme);
event.preventDefault();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,17 @@
</template>

<script>
import EventBus from '@/app/AppEventBus';
import { updatePreset } from '@primevue/themes';
export default {
setup() {
const runtimeConfig = useRuntimeConfig();
return {
designerApiBase: runtimeConfig.public.designerApiBase
};
},
inject: ['designerService'],
methods: {
download() {
this.designerService.downloadTheme(this.$appState.desiger.theme);
this.designerService.downloadTheme({
t_key: this.$appState.designer.theme.key,
t_name: this.$appState.designer.theme.name
});
},
apply() {
this.updateTheme();
updatePreset(this.$appState.designer.theme.preset);
EventBus.emit('theme-palette-change');
},
async updateTheme() {
const { error } = await $fetch(this.designerApiBase + '/theme/update', {
method: 'POST',
body: {
key: this.$appState.designer.theme.key,
preset: this.$appState.designer.theme.preset,
config: this.$appState.designer.theme.config,
license_key: this.$appState.designer.licenseKey
}
});
if (error) {
this.$toast.add({ severity: 'error', summary: 'An error occured', detail: error.message, life: 3000 });
}
this.designerService.applyTheme(this.$appState.designer.theme);
}
}
};
Expand Down

0 comments on commit 686eba4

Please sign in to comment.