diff --git a/src/js/app.js b/src/js/app.js index d3881da..78a426f 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -115,8 +115,8 @@ module.exports = new Vue({ ip: "<>", wifiName: "not connected", macros:[{},{},{},{},{},{},{},{}], - macrosList:[], - gcodeList:[] + macros_list:[], + non_macros_list:[] }, state: { messages: [], diff --git a/src/js/control-view.js b/src/js/control-view.js index d1477a2..19f64a0 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -204,12 +204,10 @@ module.exports = { }, gcodeFiles: function () { const filesWithNoMacros = this.state.files.filter( - item => !this.config.macrosList.some(compareItem => compareItem.file_name == item), + item => !this.config.macros_list.some(compareItem => compareItem.file_name == item), ); - const gcodelist = this.config.gcodeList.map(item => item.file_name); - console.log(filesWithNoMacros); - console.log(gcodelist); - const unionSet = new Set([...filesWithNoMacros, ...gcodelist]); + const gcodeList = this.config.non_macros_list.map(item => item.file_name); + const unionSet = new Set([...filesWithNoMacros, ...gcodeList]); const files = [...unionSet].sort(); return files; }, @@ -379,9 +377,9 @@ module.exports = { return; } - const isAlreadyPresent = this.config.gcodeList.find(element => element.file_name == file.name); + const isAlreadyPresent = this.config.non_macros_list.find(element => element.file_name == file.name); if (isAlreadyPresent == undefined) { - this.config.gcodeList.push({ file_name: file.name }); + this.config.non_macros_list.push({ file_name: file.name }); try { await api.put("config/save", this.config); this.$dispatch("update"); @@ -422,17 +420,17 @@ module.exports = { return; } - // const isAlreadyPresent = this.config.gcodeList.find(element => element.file_name == file.name); - // if (isAlreadyPresent == undefined) { - // this.config.gcodeList.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 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"); + } + } SvelteComponents.showDialog("Upload", { file, @@ -445,13 +443,13 @@ module.exports = { }, delete_current: function () { - if (this.config.macrosList.find(item => item.file_name == this.state.selected) == undefined) { + if (this.config.macros_list.find(item => item.file_name == this.state.selected) == undefined) { if (this.state.selected) { - this.config.gcodeList = this.config.gcodeList.filter(item => item.file_name != this.state.selected); + this.config.non_macros_list = this.config.non_macros_list.filter(item => item.file_name != this.state.selected); api.delete(`file/${this.state.selected}`); } } else { - this.config.gcodeList = this.config.gcodeList.filter(item => item.file_name != this.state.selected); + this.config.non_macros_list = this.config.non_macros_list.filter(item => item.file_name != this.state.selected); } this.deleteGCode = false; @@ -463,9 +461,9 @@ module.exports = { }, delete_all_except_macros: async function () { - const macrosList = this.config.macrosList.map(item => item.file_name).toString(); + const macrosList = this.config.macros_list.map(item => item.file_name).toString(); api.delete(`file/EgZjaHJvbWUqCggBEAAYsQMYgAQyBggAEEUYOTIKCAE${macrosList}`); - this.config.gcodeList = []; + this.config.non_macros_list = []; try { await api.put("config/save", this.config); this.$dispatch("update"); diff --git a/src/js/macros.js b/src/js/macros.js index 0de3410..813b44c 100644 --- a/src/js/macros.js +++ b/src/js/macros.js @@ -46,10 +46,10 @@ module.exports = { macrosLength: function () { return this.tab > 8; }, - macrosGCodeList: function () { - return this.config.macrosList.map(el => el.file_name).sort(); + macros_gcode_list: function () { + return this.config.macros_list.map(el => el.file_name).sort(); }, - macrosList: function () { + macros_list: function () { return this.config.macros.map(item => item.name); }, initial_tab: function () { @@ -138,9 +138,9 @@ module.exports = { const gcodeData = { file_name: file.name, }; - if (!this.config.macrosList.some(item => item.file_name == file.name)) { + if (!this.config.macros_list.some(item => item.file_name == file.name)) { this.fileName = file.name; - this.config.macrosList.push(gcodeData); + this.config.macros_list.push(gcodeData); try { await api.put("config/save", this.config); this.$dispatch("update"); @@ -187,8 +187,8 @@ module.exports = { const gcodeData = { file_name: filename, }; - if (!this.config.macrosList.some(item => item.file_name == filename)) { - this.config.macrosList.push(gcodeData); + if (!this.config.macros_list.some(item => item.file_name == filename)) { + this.config.macros_list.push(gcodeData); } }, saveMacros: async function () { @@ -198,7 +198,7 @@ module.exports = { } const macros = [...this.config.macros]; macros.splice(this.tab - 1, 1); - const macrosList = macros.map(item => item.name); + const macros_list = macros.map(item => item.name); var macrosName = document.getElementById("macros-name").value; var macrosColor = document.getElementById("macros-color").value; var macrosAlert = this.isChecked; @@ -208,7 +208,7 @@ module.exports = { .replace(/#/g, "-") .replace(/\?/g, "-"); - if (macrosList.includes(formattedFilename)) { + if (macros_list.includes(formattedFilename)) { this.sameName = true; this.confirmSave = false; return; @@ -244,7 +244,7 @@ module.exports = { api.delete(`file/${filename}`); this.newGcode = ""; this.config.macros[this.tab - 1].file_name = "default"; - this.config.macrosList = this.config.macrosList.filter(item => item.file_name !== filename); + this.config.macros_list = this.config.macros_list.filter(item => item.file_name !== filename); } try { await api.put("config/save", this.config); @@ -257,9 +257,9 @@ module.exports = { this.deleteGCode = false; }, delete_all_macros: async function () { - const macrosList = this.config.macrosList.map(item => item.file_name).toString(); - api.delete(`file/DINCAIQABiDARixAxiABDIHCAMQABiABDIHCAQQABiABDIH${macrosList}`); - this.config.macrosList = []; + const macros_list = this.config.macros_list.map(item => item.file_name).toString(); + api.delete(`file/DINCAIQABiDARixAxiABDIHCAMQABiABDIHCAQQABiABDIH${macros_list}`); + this.config.macros_list = []; }, clearMacros: async function () { if (this.tab == 0 || this.tab > this.config.macros.length) { diff --git a/src/pug/templates/macros.pug b/src/pug/templates/macros.pug index 2666bea..531b236 100644 --- a/src/pug/templates/macros.pug +++ b/src/pug/templates/macros.pug @@ -76,7 +76,7 @@ script#macros-template(type="text/x-template") v-model="tab",@change="clearMacros", style="width:250px;height:50px;border-radius:10px;padding-left:15px;font-weight:bold;margin-left:30px") option( selected='' value='0') Select a Macros - option(v-for="(index,file) in macrosList", :value="index+1") {{file}} + option(v-for="(index,file) in macros_list", :value="index+1") {{file}} .macros-form p.title Macros Name .input-container @@ -91,7 +91,7 @@ script#macros-template(type="text/x-template") v-model="fileName",@change="loadMacrosGcode", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option( selected='' value='default') Create G-Code - option(v-for="file in macrosGCodeList", :value="file") {{file}} + option(v-for="file in macros_gcode_list", :value="file") {{file}} button.config-button.button-blue(title="Upload a new GCode program.", @click="open", :disabled="!is_ready") Upload diff --git a/src/resources/config-template.json b/src/resources/config-template.json index 54ae0f1..51e8595 100644 --- a/src/resources/config-template.json +++ b/src/resources/config-template.json @@ -605,7 +605,7 @@ } }, - "macrosList": { + "macros_list": { "type": "list", "default": [], "template": { @@ -616,7 +616,7 @@ } }, - "gcodeList": { + "non_macros_list": { "type": "list", "default": [], "template": {