shifting from config to state in macros

This commit is contained in:
sanjayk03-dev
2024-04-06 16:33:02 +05:30
parent 95d5537adc
commit dbb194e886
2 changed files with 22 additions and 22 deletions

View File

@@ -49,15 +49,10 @@ module.exports = {
return this.tab > 8; return this.tab > 8;
}, },
macros_gcode_list: function () { macros_gcode_list: function () {
return ( return this.state.macros_list.map(item => item.file_name).sort();
this.config.macros_list
// .filter(item => this.state.files.includes(item.file_name))
.map(item => item.file_name)
.sort()
);
}, },
macros_list: function () { macros_list: function () {
return this.config.macros.map(item => item.name); return this.state.macros.map(item => item.name);
}, },
initial_tab: function () { initial_tab: function () {
return this.tab == 0; return this.tab == 0;
@@ -74,7 +69,7 @@ module.exports = {
} }
}, },
editedColor: function (event) { editedColor: function (event) {
if (this.tab != 0 && this.config.macros[this.tab - 1].color != event.target.value) { if (this.tab != 0 && this.state.macros[this.tab - 1].color != event.target.value) {
this.$dispatch("macro-edited"); this.$dispatch("macro-edited");
} }
}, },
@@ -84,7 +79,7 @@ module.exports = {
} }
}, },
editedName: function (event) { editedName: function (event) {
if (this.tab != 0 && this.config.macros[this.tab - 1].name != event.target.value) { if (this.tab != 0 && this.state.macros[this.tab - 1].name != event.target.value) {
this.$dispatch("macro-edited"); this.$dispatch("macro-edited");
} }
}, },
@@ -121,11 +116,12 @@ module.exports = {
} else { } else {
this.newGcode = ""; this.newGcode = "";
} }
if (file != this.config.macros[this.tab - 1].file_name) { if (file != this.state.macros[this.tab - 1].file_name) {
this.$dispatch("macro-edited"); this.$dispatch("macro-edited");
} }
}, },
removeFromList: async function () { removeFromList: async function () {
this.config.macros_list = [...this.state.macros_list];
this.config.macros_list = this.config.macros_list.filter(item => item.file_name != this.fileName); this.config.macros_list = this.config.macros_list.filter(item => item.file_name != this.fileName);
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);
@@ -160,8 +156,9 @@ module.exports = {
const gcodeData = { const gcodeData = {
file_name: file.name, file_name: file.name,
}; };
if (!this.config.macros_list.some(item => item.file_name == file.name)) { if (!this.state.macros_list.some(item => item.file_name == file.name)) {
this.fileName = file.name; this.fileName = file.name;
this.config.macros_list = [...this.state.macros_list];
this.config.macros_list.push(gcodeData); this.config.macros_list.push(gcodeData);
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);
@@ -207,7 +204,8 @@ module.exports = {
const gcodeData = { const gcodeData = {
file_name: filename, file_name: filename,
}; };
if (!this.config.macros_list.some(item => item.file_name == filename)) { if (!this.state.macros_list.some(item => item.file_name == filename)) {
this.config.macros_list = [...this.state.macros_list];
this.config.macros_list.push(gcodeData); this.config.macros_list.push(gcodeData);
} }
}, },
@@ -216,7 +214,7 @@ module.exports = {
this.clear_macro(); this.clear_macro();
return; return;
} }
const macros = [...this.config.macros]; const macros = [...this.state.macros];
macros.splice(this.tab - 1, 1); macros.splice(this.tab - 1, 1);
const macros_list = macros.map(item => item.name); const macros_list = macros.map(item => item.name);
var macrosName = document.getElementById(`macros-name`).value; var macrosName = document.getElementById(`macros-name`).value;
@@ -240,7 +238,7 @@ module.exports = {
if (file.trim() != "") { if (file.trim() != "") {
this.upload_gcode(file_name, file); this.upload_gcode(file_name, file);
} }
this.config.macros = [...this.state.macros];
this.config.macros[this.tab - 1].name = macrosName; this.config.macros[this.tab - 1].name = macrosName;
this.config.macros[this.tab - 1].color = macrosColor; this.config.macros[this.tab - 1].color = macrosColor;
this.config.macros[this.tab - 1].file_name = file_name; this.config.macros[this.tab - 1].file_name = file_name;
@@ -257,7 +255,7 @@ module.exports = {
this.edited = false; this.edited = false;
}, },
check_gcode_with_macro: function () { check_gcode_with_macro: function () {
const macro_with_filename = this.config.macros.find( const macro_with_filename = this.state.macros.find(
item => this.fileName != "default" && item.file_name == this.fileName, item => this.fileName != "default" && item.file_name == this.fileName,
); );
if (macro_with_filename) { if (macro_with_filename) {
@@ -269,7 +267,7 @@ module.exports = {
}, },
delete_current: async function () { delete_current: async function () {
const filename = this.fileName; const filename = this.fileName;
const macro_with_filename = this.config.macros.filter( const macro_with_filename = this.state.macros.filter(
item => item.file_name != "default" && item.file_name == this.fileName, item => item.file_name != "default" && item.file_name == this.fileName,
); );
if (macro_with_filename.length != 0) { if (macro_with_filename.length != 0) {
@@ -281,6 +279,7 @@ module.exports = {
} else { } else {
api.delete(`file/${filename}`); api.delete(`file/${filename}`);
this.newGcode = ""; this.newGcode = "";
this.config.macros_list = [...this.state.macros_list];
this.config.macros_list = this.config.macros_list.filter(item => item.file_name !== filename); this.config.macros_list = this.config.macros_list.filter(item => item.file_name !== filename);
} }
try { try {
@@ -294,7 +293,7 @@ module.exports = {
this.deleteGCode = false; this.deleteGCode = false;
}, },
clear_macro: async function () { clear_macro: async function () {
if (this.tab == 0 || this.tab > this.config.macros.length) { if (this.tab == 0 || this.tab > this.state.macros.length) {
document.getElementById("macros-name").value = ""; document.getElementById("macros-name").value = "";
document.getElementById("macros-color").value = "#ffffff"; document.getElementById("macros-color").value = "#ffffff";
this.isChecked = true; this.isChecked = true;
@@ -302,7 +301,7 @@ module.exports = {
this.tab = "0"; this.tab = "0";
this.newGcode = ""; this.newGcode = "";
} else { } else {
const defaultValue = this.config.macros[this.tab - 1]; const defaultValue = this.state.macros[this.tab - 1];
document.getElementById("macros-name").value = defaultValue.name; document.getElementById("macros-name").value = defaultValue.name;
document.getElementById("macros-color").value = defaultValue.color; document.getElementById("macros-color").value = defaultValue.color;
this.isChecked = defaultValue.alert; this.isChecked = defaultValue.alert;
@@ -362,7 +361,7 @@ module.exports = {
alert: true, alert: true,
}, },
]; ];
const macros_list = this.config.macros_list.map(item => item.file_name).toString(); const macros_list = this.state.macros_list.map(item => item.file_name).toString();
api.delete(`file/DINCAIQABiDARixAxiABDIHCAMQABiABDIHCAQQABiABDIH${macros_list}`); api.delete(`file/DINCAIQABiDARixAxiABDIHCAMQABiABDIHCAQQABiABDIH${macros_list}`);
this.config.macros_list = []; this.config.macros_list = [];
this.clear_macro(); this.clear_macro();
@@ -377,7 +376,7 @@ module.exports = {
} }
}, },
add_new_macro: async function () { add_new_macro: async function () {
const length = this.config.macros.length; const length = this.state.macros.length;
if (length >= 20) { if (length >= 20) {
this.maxLimitReached = true; this.maxLimitReached = true;
return; return;
@@ -388,6 +387,7 @@ module.exports = {
file_name: "default", file_name: "default",
alert: true, alert: true,
}; };
this.config.macros = [...this.state.macros];
this.config.macros.push(newMacros); this.config.macros.push(newMacros);
this.addMacros = false; this.addMacros = false;
try { try {
@@ -403,7 +403,7 @@ module.exports = {
this.clear_macro(); this.clear_macro();
return; return;
} }
this.config.macros.splice(this.tab - 1, 1); this.config.macros = this.state.macros.splice(this.tab - 1, 1);
this.clear_macro(); this.clear_macro();
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);

View File

@@ -221,7 +221,7 @@ class Config(object):
tmpl['template'], with_defaults) tmpl['template'], with_defaults)
else: else:
self.values[name]=value self.values[name]=value
self.log.info('>>config to state'+name) self.log.info('>> config to state'+name)
self.ctrl.state.config(name,value) self.ctrl.state.config(name,value)
return return