From 4c584e792a4341181ce7f33af378e372e3dbba6a Mon Sep 17 00:00:00 2001 From: sanjayk03-dev Date: Wed, 27 Mar 2024 12:26:34 +0530 Subject: [PATCH] saving folderdata in config --- src/js/control-view.js | 45 ++++++++++++++++++++---------- src/resources/config-template.json | 26 +++++++++++++++++ 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/js/control-view.js b/src/js/control-view.js index e72fda5..37abf75 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -384,13 +384,16 @@ module.exports = { const isAlreadyPresent = this.config.non_macros_list.find(element => element.file_name == file.name); if (isAlreadyPresent == undefined) { this.config.non_macros_list.push({ file_name: file.name }); - try { - await api.put("config/save", this.config); - this.$dispatch("update"); - } catch (error) { - console.error("Restore Failed: ", error); - alert("Restore failed"); - } + } + if (this.config.gcode_list.find(item => item.name == file.name && item.type == "file") == undefined) { + this.config.gcode_list.push({ name: file.name, type: "file", files: [] }); + } + try { + await api.put("config/save", this.config); + this.$dispatch("update"); + } catch (error) { + console.error("Restore Failed: ", error); + alert("Restore failed"); } SvelteComponents.showDialog("Upload", { @@ -427,13 +430,27 @@ module.exports = { const isAlreadyPresent = this.config.non_macros_list.find(element => element.file_name == file.name); if (isAlreadyPresent == undefined) { this.config.non_macros_list.push({ file_name: file.name }); - try { - await api.put("config/save", this.config); - this.$dispatch("update"); - } catch (error) { - console.error("Restore Failed: ", error); - alert("Restore failed"); - } + } + const folder = this.config.gcode_list.find(item => item.type == "folder" && item.name == folderName); + if (folder) { + folder.files.push({ file_name: file.name }); + } else { + this.config.gcode_list.push({ + name: folderName, + type: "folder", + files: [ + { + file_name: file.name, + }, + ], + }); + } + try { + await api.put("config/save", this.config); + this.$dispatch("update"); + } catch (error) { + console.error("Restore Failed: ", error); + alert("Restore failed"); } SvelteComponents.showDialog("Upload", { diff --git a/src/resources/config-template.json b/src/resources/config-template.json index 51e8595..b186c2a 100644 --- a/src/resources/config-template.json +++ b/src/resources/config-template.json @@ -627,6 +627,32 @@ } }, + "gcode_list": { + "type": "list", + "default": [], + "template": { + "name": { + "type": "string", + "default": "" + }, + "type": { + "type": "enum", + "values": ["file", "folder"], + "default": "folder" + }, + "files": { + "type": "list", + "default": [], + "template": { + "file_name": { + "type": "string", + "default": "" + } + } + } + } + }, + "admin": { "auto-check-upgrade": { "type": "bool",