From f90e0604c510f66a77f56cd2d401e15c78365f47 Mon Sep 17 00:00:00 2001 From: Corey Condardo Date: Tue, 2 Jul 2024 14:53:31 -0400 Subject: [PATCH 1/5] simple download of node data --- src/stores/NodeStore.js | 17 +++++++++++++++++ src/views/HomeIndex.vue | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/stores/NodeStore.js b/src/stores/NodeStore.js index 5e9b7e1..793561d 100644 --- a/src/stores/NodeStore.js +++ b/src/stores/NodeStore.js @@ -108,6 +108,22 @@ export const useNodeStore = defineStore( return node.parentNode ? getRootNode(node.parentNode) : node; }; + const saveStore = () => { + const nodesJson = JSON.parse(JSON.stringify(nodes.value)); + const nodesString = JSON.stringify(nodesJson); + + // create the downloadable file + const blob = new Blob([nodesString], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + link.download = 'solutionNavigatorSave.json'; // Name of the file to be downloaded + document.body.appendChild(link); // Append the link to the body + link.click(); // Programmatically click the link to trigger the download + document.body.removeChild(link); // Remove the link from the body + URL.revokeObjectURL(url); // Clean up the URL object + }; + return { nodes, nodesList, @@ -120,6 +136,7 @@ export const useNodeStore = defineStore( refreshUpdatedAt, enforceNodeTreeConsistency, getRootNode, + saveStore, }; }, { persist: true }, diff --git a/src/views/HomeIndex.vue b/src/views/HomeIndex.vue index 09d3fac..4fd3630 100644 --- a/src/views/HomeIndex.vue +++ b/src/views/HomeIndex.vue @@ -8,7 +8,7 @@ import { useConfirm } from 'primevue/useconfirm'; const router = useRouter(); const route = useRoute(); -const { addNode, deleteNode } = useNodeStore(); +const { addNode, deleteNode, saveStore } = useNodeStore(); const confirm = useConfirm(); const handleAddNode = () => { @@ -35,12 +35,17 @@ const deleteConfirmation = (nodeUuid) => { const handleNodeNotFound = () => { router.push({ name: 'node.not-found' }); }; + +const handleSaveStore = () => { + saveStore(); +};