From ff6b7fdc9e1ff0edbcc0cab3bf3b1a3e39a3fe64 Mon Sep 17 00:00:00 2001 From: sanjayk03-dev Date: Fri, 12 Jan 2024 00:32:01 +0530 Subject: [PATCH] changed str to int for tab --- src/js/macros.js | 34 +++++++++++++++++++--------------- src/pug/templates/macros.pug | 32 ++++++++++++++++---------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/js/macros.js b/src/js/macros.js index 30ddb35..f8c30a2 100644 --- a/src/js/macros.js +++ b/src/js/macros.js @@ -9,10 +9,10 @@ module.exports = { data: function () { return { - tab: "1", + tab: 1, confirmReset: false, confirmSave: false, - currentTab:undefined, + currentTab:1, newGcode: ["", "", "", "", "", "", "", ""], }; }, @@ -38,17 +38,20 @@ module.exports = { }, methods: { updateNewGcode(event) { - this.newGcode[this.currentTab] = event.target.value; + this.newGcode[this.tab] = event.target.value; }, open: function () { utils.clickFileInput("gcode-file-input"); }, load: function () { const file_time = this.state.selected_time; + console.log(this.state.selected_time, "\n ",file_time); const file = this.state.selected; + console.log(this.state.selected); + console.log(this.state.line); this.$broadcast("gcode-load", file); this.$broadcast("gcode-line", this.state.line); - this.newGCode[this.currentTab] = ""; + this.newGcode[this.tab] = ""; }, upload: function (e) { const files = e.target.files || e.dataTransfer.files; @@ -78,24 +81,25 @@ module.exports = { }); }, saveMacros: async function () { + console.log(this.state.selected); var macrosName = document.getElementById( - `macros-name-${this.currentTab}` + `macros-name-${this.tab}` ).value; var macrosColor = document.getElementById( - `macros-color-${this.currentTab}` + `macros-color-${this.tab}` ).value; - console.log(this.currentTab); + console.log(this.tab); console.log(macrosColor, macrosName); - this.config.macros[this.currentTab].name = macrosName; + this.config.macros[this.tab].name = macrosName; console.log(this.config.macros[this.tab-1]); - this.config.macros[this.currentTab].color = macrosColor; - this.config.macros[this.currentTab].gcode_file_name = this.state.selected; - this.config.macros[this.currentTab].gcode_file_time = + this.config.macros[this.tab].color = macrosColor; + this.config.macros[this.tab].gcode_file_name = this.state.selected; + this.config.macros[this.tab].gcode_file_time = this.state.selected_time; console.log(this.config.macros); - this.cancelMacros(this.currentTab); + this.cancelMacros(this.tab); this.confirmSave = false; try { await api.put("config/save", this.config); @@ -107,9 +111,9 @@ module.exports = { } }, cancelMacros: function () { - document.getElementById(`macros-name-${this.currentTab}`).value = ""; - document.getElementById(`macros-color-${this.currentTab}`).value = "#ffffff"; - document.getElementById(`gcodeSelect-${this.currentTab}`).value = "default"; + document.getElementById(`macros-name-${this.tab}`).value = ""; + document.getElementById(`macros-color-${this.tab}`).value = "#ffffff"; + document.getElementById(`gcodeSelect-${this.tab}`).value = "default"; this.$broadcast("gcode-clear"); }, resetConfig: async function () { diff --git a/src/pug/templates/macros.pug b/src/pug/templates/macros.pug index f700605..c77490c 100644 --- a/src/pug/templates/macros.pug +++ b/src/pug/templates/macros.pug @@ -28,28 +28,28 @@ script#macros-template(type="text/x-template") u Note: | Reset the macros to default macros recommended by Onefinity CNC. .tabs - input#tab1(type="radio", name="tabs",checked="" @click="tab = '1'") + input#tab1(type="radio", name="tabs",checked="" @click="tab = 1") label(for="tab1",style="height:50px;width:100px") Macros 1 - input#tab2(type="radio", name="tabs", @click="tab = '2'") + input#tab2(type="radio", name="tabs", @click="tab = 2") label(for="tab2",style="height:50px;width:100px") Macros 2 - input#tab3(type="radio", name="tabs", @click="tab = '3'") + input#tab3(type="radio", name="tabs", @click="tab = 3") label(for="tab3",style="height:50px;width:100px") Macros 3 - input#tab4(type="radio", name="tabs", @click="tab = '4'") + input#tab4(type="radio", name="tabs", @click="tab = 4") label(for="tab4",style="height:50px;width:100px") Macros 4 - input#tab5(type="radio", name="tabs", @click="tab = '5'") + input#tab5(type="radio", name="tabs", @click="tab = 5") label(for="tab5",style="height:50px;width:100px") Macros 5 - input#tab6(type="radio", name="tabs", @click="tab = '6'") + input#tab6(type="radio", name="tabs", @click="tab = 6") label(for="tab6",style="height:50px;width:100px") Macros 6 - input#tab7(type="radio", name="tabs", @click="tab = '7'") + input#tab7(type="radio", name="tabs", @click="tab = 7") label(for="tab7",style="height:50px;width:100px") Macros 7 - input#tab8(type="radio", name="tabs", @click="tab = '8'") + input#tab8(type="radio", name="tabs", @click="tab = 8") label(for="tab8",style="height:50px;width:100px") Macros 8 section#content1.tab-content @@ -77,7 +77,7 @@ script#macros-template(type="text/x-template") .gcodeContainer textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") gcode-viewer(v-if="state.selected !== 'default'") - button.submit-macros(title="Save Macros",@click="()=>{currentTab=0; confirmSave=true}", + button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel @@ -107,7 +107,7 @@ script#macros-template(type="text/x-template") .gcodeContainer textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") gcode-viewer(v-if="state.selected !== 'default'") - button.submit-macros(title="Save Macros",@click="()=>{currentTab=1; confirmSave=true}", + button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel @@ -137,7 +137,7 @@ script#macros-template(type="text/x-template") .gcodeContainer textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") gcode-viewer(v-if="state.selected !== 'default'") - button.submit-macros(title="Save Macros",@click="()=>{currentTab=2; confirmSave=true}", + button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel @@ -167,7 +167,7 @@ script#macros-template(type="text/x-template") .gcodeContainer textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") gcode-viewer(v-if="state.selected !== 'default'") - button.submit-macros(title="Save Macros",@click="()=>{currentTab=3; confirmSave=true}", + button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel @@ -197,7 +197,7 @@ script#macros-template(type="text/x-template") .gcodeContainer textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") gcode-viewer(v-if="state.selected !== 'default'") - button.submit-macros(title="Save Macros",@click="()=>{currentTab=4; confirmSave=true}", + button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel @@ -227,7 +227,7 @@ script#macros-template(type="text/x-template") .gcodeContainer textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") gcode-viewer(v-if="state.selected !== 'default'") - button.submit-macros(title="Save Macros",@click="()=>{currentTab=5; confirmSave=true}", + button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel @@ -257,7 +257,7 @@ script#macros-template(type="text/x-template") .gcodeContainer textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") gcode-viewer(v-if="state.selected !== 'default'") - button.submit-macros(title="Save Macros",@click="()=>{currentTab=6; confirmSave=true}", + button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel @@ -287,7 +287,7 @@ script#macros-template(type="text/x-template") .gcodeContainer textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") gcode-viewer(v-if="state.selected !== 'default'") - button.submit-macros(title="Save Macros",@click="()=>{currentTab=7; confirmSave=true}", + button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel