From 8a6f6f551ecdba78a72fbe5f2e4d2f0c5ce67f6c Mon Sep 17 00:00:00 2001 From: sanjayk03-dev Date: Mon, 22 Jan 2024 00:47:11 +0530 Subject: [PATCH] settings dropdown individual, nexttick for textarea --- src/js/macros.js | 77 ++++++++++++++++++++++-------------- src/pug/templates/macros.pug | 16 ++++---- src/py/bbctrl/State.py | 5 --- 3 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/js/macros.js b/src/js/macros.js index 4afc414..ac1a144 100644 --- a/src/js/macros.js +++ b/src/js/macros.js @@ -12,6 +12,16 @@ module.exports = { tab: "1", confirmReset: false, confirmSave: false, + selectedValues: [ + "default", + "default", + "default", + "default", + "default", + "default", + "default", + "default", + ], newGcode: ["", "", "", "", "", "", "", ""], }; }, @@ -38,19 +48,24 @@ module.exports = { utils.clickFileInput("gcode-file-input"); }, load: async function () { - const file = this.state.selected; - if(this.state.selected!='default'){ - const response = await fetch(`/api/file/${file}`, { cache: "no-cache" }); - const text = await response.text(); + const file = this.selectedValues[this.tab - 1]; + if (this.selectedValues[this.tab - 1] != "default") { + const response = await fetch(`/api/file/${file}`, { + cache: "no-cache", + }); + const text = (await response.text()).split(" ").join("\n"); console.log(text); if (text.length > 20e6) { this.newGcode[this.tab - 1] = "File is large - gcode view disabled"; } else { this.newGcode[this.tab - 1] = text; } - }else{ - this.newGcode=''; + } else { + this.newGcode = ""; } + Vue.nextTick(() => { + console.log("updated"); + }); }, upload: function (e) { const files = e.target.files || e.dataTransfer.files; @@ -103,7 +118,6 @@ module.exports = { xhr.open("PUT", `/api/file/${encodeURIComponent(filename)}`, true); xhr.send(file); - }, saveMacros: async function () { var macrosName = document.getElementById( @@ -113,33 +127,36 @@ module.exports = { `macros-color-${this.tab - 1}` ).value; - if (this.state.selected == "default") { - var file = this.newGcode[this.tab - 1]; - this.uploadGCode(macrosName, file); - } + console.log(this.state.selected, this.state.selected_time); + console.log(this.selectedValues[this.tab - 1]); - this.config.macros[this.tab - 1].name = macrosName; - this.config.macros[this.tab - 1].color = macrosColor; - this.config.macros[this.tab - 1].gcode_file_name = - this.state.selected == "default" ? macrosName : this.state.selected; - this.config.macros[this.tab - 1].gcode_file_time = - this.state.selected_time; - this.cancelMacros(this.tab - 1); - this.confirmSave = false; - 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"); - } + // if (this.state.selected == "default") { + // var file = this.newGcode[this.tab - 1]; + // this.uploadGCode(macrosName, file); + // } + + // this.config.macros[this.tab - 1].name = macrosName; + // this.config.macros[this.tab - 1].color = macrosColor; + // this.config.macros[this.tab - 1].gcode_file_name = + // this.state.selected == "default" ? macrosName : this.state.selected; + // this.config.macros[this.tab - 1].gcode_file_time = + // this.state.selected_time; + // this.cancelMacros(this.tab - 1); + // this.confirmSave = false; + // 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"); + // } }, cancelMacros: function () { document.getElementById(`macros-name-${this.tab - 1}`).value = ""; document.getElementById(`macros-color-${this.tab - 1}`).value = "#ffffff"; document.getElementById(`gcodeSelect-${this.tab - 1}`).value = "default"; - this.newGcode[this.tab-1] = ''; + this.newGcode[this.tab - 1] = ""; }, resetConfig: async function () { this.config.macros = [ @@ -202,7 +219,7 @@ module.exports = { } }, }, - printState: function (){ + printState: function () { console.log(this.state); - } + }, }; diff --git a/src/pug/templates/macros.pug b/src/pug/templates/macros.pug index a1e8f44..6c99659 100644 --- a/src/pug/templates/macros.pug +++ b/src/pug/templates/macros.pug @@ -61,7 +61,7 @@ script#macros-template(type="text/x-template") p.title G-Code .select-upload-gcode select#gcodeSelect-0(title="Select previously uploaded GCode programs.",selected - v-model="state.selected",@change="load", :disabled="!is_ready", + v-model="selectedValues[tab - 1]",@change="load", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option( selected='' value='default') Create G-Code option(v-for="file in state.files", :value="file") {{file}} @@ -91,7 +91,7 @@ script#macros-template(type="text/x-template") p.title G-Code .select-upload-gcode select#gcodeSelect-1(title="Select previously uploaded GCode programs.", - v-model="state.selected", @change="load", :disabled="!is_ready", + v-model="selectedValues[tab - 1]", @change="load", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option(selected='' value='default') Create G-Code option(v-for="file in state.files", :value="file") {{file}} @@ -121,7 +121,7 @@ script#macros-template(type="text/x-template") p.title G-Code .select-upload-gcode select#gcodeSelect-2(title="Select previously uploaded GCode programs.", - v-model="state.selected", @change="load", :disabled="!is_ready", + v-model="selectedValues[tab - 1]", @change="load", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option(selected='' value='default') Create G-Code option(v-for="file in state.files", :value="file") {{file}} @@ -151,7 +151,7 @@ script#macros-template(type="text/x-template") p.title G-Code .select-upload-gcode select#gcodeSelect-3(title="Select previously uploaded GCode programs.", - v-model="state.selected", @change="load", :disabled="!is_ready", + v-model="selectedValues[tab - 1]", @change="load", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option(selected='' value='default') Create G-Code option(v-for="file in state.files", :value="file") {{file}} @@ -181,7 +181,7 @@ script#macros-template(type="text/x-template") p.title G-Code .select-upload-gcode select#gcodeSelect-4(title="Select previously uploaded GCode programs.", - v-model="state.selected", @change="load", :disabled="!is_ready", + v-model="selectedValues[tab - 1]", @change="load", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option(selected='' value='default') Create G-Code option(v-for="file in state.files", :value="file") {{file}} @@ -211,7 +211,7 @@ script#macros-template(type="text/x-template") p.title G-Code .select-upload-gcode select#gcodeSelect-5(title="Select previously uploaded GCode programs.", - v-model="state.selected", @change="load", :disabled="!is_ready", + v-model="selectedValues[tab - 1]", @change="load", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option(selected='' value='default') Create G-Code option(v-for="file in state.files", :value="file") {{file}} @@ -241,7 +241,7 @@ script#macros-template(type="text/x-template") p.title G-Code .select-upload-gcode select#gcodeSelect-6(title="Select previously uploaded GCode programs.",selected - v-model="state.selected",@change="load", :disabled="!is_ready", + v-model="selectedValues[tab - 1]",@change="load", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option(selected='' value='default') Create G-Code option(v-for="file in state.files", :value="file") {{file}} @@ -271,7 +271,7 @@ script#macros-template(type="text/x-template") p.title G-Code .select-upload-gcode select#gcodeSelect-7(title="Select previously uploaded GCode programs.",selected - v-model="state.selected",@change="load", :disabled="!is_ready", + v-model="selectedValues[tab - 1]",@change="load", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option(selected='' value='default') Create G-Code option(v-for="file in state.files", :value="file") {{file}} diff --git a/src/py/bbctrl/State.py b/src/py/bbctrl/State.py index 0b4753b..bab5877 100644 --- a/src/py/bbctrl/State.py +++ b/src/py/bbctrl/State.py @@ -146,11 +146,6 @@ class State(object): files.append(filename) files.sort() self.set('files', files) - self.log.info('===================') - for i in files: - self.log.info(i) - self.log.info('===================') - self.select_file(filename)