settings dropdown individual, nexttick for textarea

This commit is contained in:
sanjayk03-dev
2024-01-22 00:47:11 +05:30
parent 04eeee5eba
commit 8a6f6f551e
3 changed files with 55 additions and 43 deletions

View File

@@ -12,6 +12,16 @@ module.exports = {
tab: "1", tab: "1",
confirmReset: false, confirmReset: false,
confirmSave: false, confirmSave: false,
selectedValues: [
"default",
"default",
"default",
"default",
"default",
"default",
"default",
"default",
],
newGcode: ["", "", "", "", "", "", "", ""], newGcode: ["", "", "", "", "", "", "", ""],
}; };
}, },
@@ -38,19 +48,24 @@ module.exports = {
utils.clickFileInput("gcode-file-input"); utils.clickFileInput("gcode-file-input");
}, },
load: async function () { load: async function () {
const file = this.state.selected; const file = this.selectedValues[this.tab - 1];
if(this.state.selected!='default'){ if (this.selectedValues[this.tab - 1] != "default") {
const response = await fetch(`/api/file/${file}`, { cache: "no-cache" }); const response = await fetch(`/api/file/${file}`, {
const text = await response.text(); cache: "no-cache",
});
const text = (await response.text()).split(" ").join("\n");
console.log(text); console.log(text);
if (text.length > 20e6) { if (text.length > 20e6) {
this.newGcode[this.tab - 1] = "File is large - gcode view disabled"; this.newGcode[this.tab - 1] = "File is large - gcode view disabled";
} else { } else {
this.newGcode[this.tab - 1] = text; this.newGcode[this.tab - 1] = text;
} }
}else{ } else {
this.newGcode=''; this.newGcode = "";
} }
Vue.nextTick(() => {
console.log("updated");
});
}, },
upload: function (e) { upload: function (e) {
const files = e.target.files || e.dataTransfer.files; const files = e.target.files || e.dataTransfer.files;
@@ -103,7 +118,6 @@ module.exports = {
xhr.open("PUT", `/api/file/${encodeURIComponent(filename)}`, true); xhr.open("PUT", `/api/file/${encodeURIComponent(filename)}`, true);
xhr.send(file); xhr.send(file);
}, },
saveMacros: async function () { saveMacros: async function () {
var macrosName = document.getElementById( var macrosName = document.getElementById(
@@ -113,33 +127,36 @@ module.exports = {
`macros-color-${this.tab - 1}` `macros-color-${this.tab - 1}`
).value; ).value;
if (this.state.selected == "default") { console.log(this.state.selected, this.state.selected_time);
var file = this.newGcode[this.tab - 1]; console.log(this.selectedValues[this.tab - 1]);
this.uploadGCode(macrosName, file);
}
this.config.macros[this.tab - 1].name = macrosName; // if (this.state.selected == "default") {
this.config.macros[this.tab - 1].color = macrosColor; // var file = this.newGcode[this.tab - 1];
this.config.macros[this.tab - 1].gcode_file_name = // this.uploadGCode(macrosName, file);
this.state.selected == "default" ? macrosName : this.state.selected; // }
this.config.macros[this.tab - 1].gcode_file_time =
this.state.selected_time; // this.config.macros[this.tab - 1].name = macrosName;
this.cancelMacros(this.tab - 1); // this.config.macros[this.tab - 1].color = macrosColor;
this.confirmSave = false; // this.config.macros[this.tab - 1].gcode_file_name =
try { // this.state.selected == "default" ? macrosName : this.state.selected;
await api.put("config/save", this.config); // this.config.macros[this.tab - 1].gcode_file_time =
console.log("Successfully saved"); // this.state.selected_time;
this.$dispatch("update"); // this.cancelMacros(this.tab - 1);
} catch (error) { // this.confirmSave = false;
console.error("Restore Failed: ", error); // try {
alert("Restore failed"); // 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 () { cancelMacros: function () {
document.getElementById(`macros-name-${this.tab - 1}`).value = ""; document.getElementById(`macros-name-${this.tab - 1}`).value = "";
document.getElementById(`macros-color-${this.tab - 1}`).value = "#ffffff"; document.getElementById(`macros-color-${this.tab - 1}`).value = "#ffffff";
document.getElementById(`gcodeSelect-${this.tab - 1}`).value = "default"; document.getElementById(`gcodeSelect-${this.tab - 1}`).value = "default";
this.newGcode[this.tab-1] = ''; this.newGcode[this.tab - 1] = "";
}, },
resetConfig: async function () { resetConfig: async function () {
this.config.macros = [ this.config.macros = [
@@ -202,7 +219,7 @@ module.exports = {
} }
}, },
}, },
printState: function (){ printState: function () {
console.log(this.state); console.log(this.state);
} },
}; };

View File

@@ -61,7 +61,7 @@ script#macros-template(type="text/x-template")
p.title G-Code p.title G-Code
.select-upload-gcode .select-upload-gcode
select#gcodeSelect-0(title="Select previously uploaded GCode programs.",selected 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") style="max-width:100%;height:40px;border-radius:5px")
option( selected='' value='default') Create G-Code option( selected='' value='default') Create G-Code
option(v-for="file in state.files", :value="file") {{file}} 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 p.title G-Code
.select-upload-gcode .select-upload-gcode
select#gcodeSelect-1(title="Select previously uploaded GCode programs.", 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") style="max-width:100%;height:40px;border-radius:5px")
option(selected='' value='default') Create G-Code option(selected='' value='default') Create G-Code
option(v-for="file in state.files", :value="file") {{file}} 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 p.title G-Code
.select-upload-gcode .select-upload-gcode
select#gcodeSelect-2(title="Select previously uploaded GCode programs.", 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") style="max-width:100%;height:40px;border-radius:5px")
option(selected='' value='default') Create G-Code option(selected='' value='default') Create G-Code
option(v-for="file in state.files", :value="file") {{file}} 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 p.title G-Code
.select-upload-gcode .select-upload-gcode
select#gcodeSelect-3(title="Select previously uploaded GCode programs.", 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") style="max-width:100%;height:40px;border-radius:5px")
option(selected='' value='default') Create G-Code option(selected='' value='default') Create G-Code
option(v-for="file in state.files", :value="file") {{file}} 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 p.title G-Code
.select-upload-gcode .select-upload-gcode
select#gcodeSelect-4(title="Select previously uploaded GCode programs.", 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") style="max-width:100%;height:40px;border-radius:5px")
option(selected='' value='default') Create G-Code option(selected='' value='default') Create G-Code
option(v-for="file in state.files", :value="file") {{file}} 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 p.title G-Code
.select-upload-gcode .select-upload-gcode
select#gcodeSelect-5(title="Select previously uploaded GCode programs.", 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") style="max-width:100%;height:40px;border-radius:5px")
option(selected='' value='default') Create G-Code option(selected='' value='default') Create G-Code
option(v-for="file in state.files", :value="file") {{file}} 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 p.title G-Code
.select-upload-gcode .select-upload-gcode
select#gcodeSelect-6(title="Select previously uploaded GCode programs.",selected 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") style="max-width:100%;height:40px;border-radius:5px")
option(selected='' value='default') Create G-Code option(selected='' value='default') Create G-Code
option(v-for="file in state.files", :value="file") {{file}} 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 p.title G-Code
.select-upload-gcode .select-upload-gcode
select#gcodeSelect-7(title="Select previously uploaded GCode programs.",selected 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") style="max-width:100%;height:40px;border-radius:5px")
option(selected='' value='default') Create G-Code option(selected='' value='default') Create G-Code
option(v-for="file in state.files", :value="file") {{file}} option(v-for="file in state.files", :value="file") {{file}}

View File

@@ -146,11 +146,6 @@ class State(object):
files.append(filename) files.append(filename)
files.sort() files.sort()
self.set('files', files) self.set('files', files)
self.log.info('===================')
for i in files:
self.log.info(i)
self.log.info('===================')
self.select_file(filename) self.select_file(filename)