From 305e22507608d521c1ef5802373e61b68615c8d9 Mon Sep 17 00:00:00 2001 From: sanjayk03-dev Date: Mon, 22 Jan 2024 15:42:00 +0530 Subject: [PATCH] changed to computed --- src/js/control-view.js | 15 +++++++++++---- src/js/macros.js | 19 ++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/js/control-view.js b/src/js/control-view.js index 5dbf4db..0c0f659 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -202,10 +202,18 @@ module.exports = { const p = this.plan_time / this.toolpath.time; return Math.min(1, p); }, - gcode_files: function (){ + gcode_files: async function (){ const files=this.state.files.filter(item => !this.config.macrosList.some(compareItem => compareItem.gcode_file_name == item)); console.log(files); - console.log(this.config.gcodeList); + this.config.gcodeList=files; + try { + await api.put("config/save", this.config); + console.log("Successfully saved"); + this.$dispatch("update"); + } catch (error) { + console.error("Restore Failed: ", error); + alert("Restore failed"); + } return files; } }, @@ -372,10 +380,9 @@ module.exports = { return; } - console.log(file.name); if(this.config.macrosList.some(obj => obj.gcode_file_name == files.name)){ console.log("It is a macros, remove it from macrosList") - this.config.gcodeList.push(file.name); + // this.config.gcodeList.push(file.name); } SvelteComponents.showDialog("Upload", { diff --git a/src/js/macros.js b/src/js/macros.js index 75db10f..8f9d790 100644 --- a/src/js/macros.js +++ b/src/js/macros.js @@ -23,7 +23,6 @@ module.exports = { "default", ], newGcode: ["", "", "", "", "", "", "", ""], - macrosList: this.config.macrosList.map((el) => el.gcode_file_name), }; }, computed: { @@ -40,11 +39,17 @@ module.exports = { is_ready: function () { return this.mach_state == "READY"; }, - }, - methods: { - updateNewGcode(event) { + updateNewGcode: function (event) { this.newGcode[this.tab - 1] = event.target.value; }, + loadGcode: function (data){ + this.newGcode[this.tab - 1] = data; + }, + macrosList: function (){ + return this.config.macrosList.map((el) => el.gcode_file_name); + } + }, + methods: { open: function () { utils.clickFileInput("gcode-file-input"); }, @@ -56,12 +61,12 @@ module.exports = { }); const text = (await response.text()).split(" ").join("\n"); if (text.length > 20e6) { - this.newGcode[this.tab - 1] = "File is large - gcode view disabled"; + this.loadGcode("File is large - gcode view disabled"); } else { - this.newGcode[this.tab - 1] = text; + this.loadGcode(text); } } else { - this.newGcode[this.tab - 1] = ""; + this.loadGcode(""); } console.log(this.newGcode[this.tab - 1]); },