macros check

This commit is contained in:
sanjayk03-dev
2024-04-08 18:21:33 +05:30
parent 53efe8de45
commit d671d81cc0

View File

@@ -106,14 +106,15 @@ module.exports = {
const response = await fetch(`/api/file/EgZjaHJvbWUqCggBEAAYsQMYgAQyBggAEEUYOTIKCAE${file}`, { const response = await fetch(`/api/file/EgZjaHJvbWUqCggBEAAYsQMYgAQyBggAEEUYOTIKCAE${file}`, {
cache: "no-cache", cache: "no-cache",
}); });
console.log("response", response);
if (response.status == 200) { if (response.status == 200) {
const text = await response.text(); const text = await response.text();
this.newGcode = text; this.newGcode = text;
} else if (response.status == 400) { } else if (response.status == 400) {
return (this.GCodeNotFound = true); this.GCodeNotFound = true;
return;
} else { } else {
return alert("error loading"); alert("error loading");
return;
} }
} else { } else {
this.newGcode = ""; this.newGcode = "";
@@ -126,7 +127,11 @@ module.exports = {
this.config.macros_list = [...this.state.macros_list]; 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);
this.config.macros = [...this.state.macros]; this.config.macros = [...this.state.macros];
this.config.macros.filter(item => item.file_name == this.fileName).forEach(item => (item.file_name = "default")); this.config.macros
.filter(item => item.file_name == this.fileName)
.forEach(item => {
item.file_name = "default";
});
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);
this.$dispatch("update"); this.$dispatch("update");
@@ -187,7 +192,7 @@ module.exports = {
if (xhr.status >= 200 && xhr.status < 300) { if (xhr.status >= 200 && xhr.status < 300) {
console.log("File uploaded successfully"); console.log("File uploaded successfully");
} else { } else {
console.error("File upload failed:", xhr.statusText); alert("File upload failed:", xhr.statusText);
} }
}; };
@@ -210,7 +215,6 @@ module.exports = {
}; };
this.config.macros_list = [...this.state.macros_list]; this.config.macros_list = [...this.state.macros_list];
if (!this.state.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);
} }
}, },
@@ -238,13 +242,13 @@ module.exports = {
return; return;
} }
var file = this.newGcode;
var file_name = var file_name =
this.fileName == "default" this.fileName == "default"
? this.newGcode.trim() != "" ? file.trim() != ""
? formattedFilename + ".ngc" ? formattedFilename + ".ngc"
: "default" : "default"
: this.fileName; : this.fileName;
var file = this.newGcode;
if (file.trim() != "") { if (file.trim() != "") {
this.upload_gcode(file_name, file); this.upload_gcode(file_name, file);
@@ -285,7 +289,7 @@ module.exports = {
} else { } else {
this.config.macros = [...this.state.macros]; this.config.macros = [...this.state.macros];
const macro_with_filename = this.config.macros.filter( const macro_with_filename = this.config.macros.filter(
item => item.file_name != "default" && item.file_name == this.fileName, item => item.file_name != "default" && item.file_name == filename,
); );
if (macro_with_filename.length != 0) { if (macro_with_filename.length != 0) {
this.macroFound = false; this.macroFound = false;