From a048b2ddbd5ea51efec6d5e687edff96e05cc739 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Mon, 1 Jan 2024 15:39:55 -0500 Subject: [PATCH] Add ability to export a JSON file to send in an API request --- composables/useProjectStoreFactory.js | 18 +++++++++++++++++- pages/index.vue | 9 +++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/composables/useProjectStoreFactory.js b/composables/useProjectStoreFactory.js index 2e35c16..22f492f 100644 --- a/composables/useProjectStoreFactory.js +++ b/composables/useProjectStoreFactory.js @@ -1,10 +1,10 @@ import download from 'downloadjs'; import { v4 as uuid } from 'uuid'; -import { cloneDeep, replace } from 'lodash'; import { defineStore } from 'pinia'; import useIndexedDb from './useIndexedDb'; import { namespace } from './useProjectStores'; import useTemplateStore from './useTemplateStore'; +import { cloneDeep, replace, omit } from 'lodash'; export default function (id, initialValue = null) { const storage = useIndexedDb( @@ -74,6 +74,22 @@ export default function (id, initialValue = null) { download(JSON.stringify(state, null, 2), `${name}.json`); }, + /** + * Export the project into a JSON file for an API request. + */ + exportForApi() { + const state = this.clone(); + + const json = { + settings: omit(state.settings, ['image']), + editors: state.page.editors, + }; + + const name = state.tab.name || 'json'; + + download(JSON.stringify(json, null, 2), `${name}.json`); + }, + /** * Save the project as a template. */ diff --git a/pages/index.vue b/pages/index.vue index ef3fa68..28c2b22 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -228,14 +228,19 @@ export default { { separator: true, }, + { + name: 'export-json', + title: 'Export JSON (API Request)', + click: () => currentProject.value?.exportForApi(), + }, { name: 'export-config', - title: 'Export Configuration', + title: 'Export JSON Configuration', click: () => currentProject.value?.export(), }, { name: 'import-config', - title: 'Import Configuration', + title: 'Import JSON Configuration', click: importNewProject, }, {