reseting to config , reset to delete

This commit is contained in:
sanjayk03-dev
2024-01-27 12:24:54 +05:30
parent 23590b24df
commit 2cd9dedd40
6 changed files with 108 additions and 218 deletions

View File

@@ -42,6 +42,7 @@ module.exports = {
tab: "auto", tab: "auto",
ask_home: true, ask_home: true,
showGcodeMessage: false, showGcodeMessage: false,
showNoGcodeMessage: false,
}; };
}, },
@@ -202,11 +203,11 @@ module.exports = {
}, },
gcodeFiles: function () { gcodeFiles: function () {
const filesWithNoMacros = this.state.files.filter( const filesWithNoMacros = this.state.files.filter(
item => !this.config.macrosList.some(compareItem => compareItem.gcode_file_name == item), item => !this.config.macrosList.some(compareItem => compareItem.file_name == item),
); );
console.log("filesWithNoMacros: ", filesWithNoMacros); console.log("filesWithNoMacros: ", filesWithNoMacros);
console.log("this.config.gcodeList", this.config.gcodeList); console.log("this.config.gcodeList", this.config.gcodeList);
const gcodelist = this.config.gcodeList.map(item => item.gcode_file_name); const gcodelist = this.config.gcodeList.map(item => item.file_name);
const unionSet = new Set([...filesWithNoMacros, ...gcodelist]); const unionSet = new Set([...filesWithNoMacros, ...gcodelist]);
const files = [...unionSet]; const files = [...unionSet];
console.log("final files: ", files); console.log("final files: ", files);
@@ -376,10 +377,10 @@ module.exports = {
return; return;
} }
const isAlreadyPresent = this.config.gcodeList.find(element => element.gcode_file_name == file.name); const isAlreadyPresent = this.config.gcodeList.find(element => element.file_name == file.name);
if (isAlreadyPresent == undefined) { if (isAlreadyPresent == undefined) {
console.log("new gcode file"); console.log("new gcode file");
this.config.gcodeList.push({ gcode_file_name: file.name }); this.config.gcodeList.push({ file_name: file.name });
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);
this.$dispatch("update"); this.$dispatch("update");
@@ -391,7 +392,7 @@ module.exports = {
console.log("Already exists"); console.log("Already exists");
} }
if (this.config.macrosList.some(obj => obj.gcode_file_name == file.name)) { if (this.config.macrosList.some(obj => obj.file_name == file.name)) {
console.log("It is also a macros"); console.log("It is also a macros");
// this.config.gcodeList.push(file.name); // this.config.gcodeList.push(file.name);
} }
@@ -406,12 +407,12 @@ module.exports = {
}, },
delete_current: function () { delete_current: function () {
if (this.config.macrosList.find(item => item.gcode_file_name == this.state.selected) == undefined) { if (this.config.macrosList.find(item => item.file_name == this.state.selected) == undefined) {
if (this.state.selected) { if (this.state.selected) {
api.delete(`file/${this.state.selected}`); api.delete(`file/${this.state.selected}`);
} }
} else { } else {
this.config.gcodeList = this.config.gcodeList.filter(item => item.gcode_file_name != this.state.selected); this.config.gcodeList = this.config.gcodeList.filter(item => item.file_name != this.state.selected);
} }
this.deleteGCode = false; this.deleteGCode = false;
@@ -423,7 +424,7 @@ module.exports = {
}, },
delete_all_except_macros: async function () { delete_all_except_macros: async function () {
const macrosList = this.config.macrosList.map(item => item.gcode_file_name).toString(); const macrosList = this.config.macrosList.map(item => item.file_name).toString();
api.delete(`file/EgZjaHJvbWUqCggBEAAYsQMYgAQyBggAEEUYOTIKCAE${macrosList}`); api.delete(`file/EgZjaHJvbWUqCggBEAAYsQMYgAQyBggAEEUYOTIKCAE${macrosList}`);
this.config.gcodeList = []; this.config.gcodeList = [];
try { try {
@@ -545,18 +546,18 @@ module.exports = {
SvelteComponents.showDialog("Probe", { probeType }); SvelteComponents.showDialog("Probe", { probeType });
}, },
runMacros: function (id) { runMacros: function (id) {
if ( if (this.config.macros[id].file_name == "") {
this.config.macros[id].gcode_file_name != this.state.selected || this.showNoGcodeMessage = true;
this.config.macros[id].gcode_file_time != this.state.selected_time } else {
) { if (this.config.macros[id].file_name != this.state.selected) {
this.state.selected = this.config.macros[id].gcode_file_name; this.state.selected = this.config.macros[id].file_name; //TODO :get file
this.state.selected_time = this.config.macros[id].gcode_file_time; }
} try {
try { this.loadGCode();
this.loadGCode(); this.start_pause();
this.start_pause(); } catch (error) {
} catch (error) { console.warn("Error running program: ", error);
console.warn("Error running program: ", error); }
} }
}, },
}, },

View File

@@ -17,36 +17,28 @@ module.exports = {
newGcode: ["", "", "", "", "", "", "", ""], newGcode: ["", "", "", "", "", "", "", ""],
defaultMacrosList: [ defaultMacrosList: [
{ {
gcode_file_name: "FireLaser.ngc", file_name: "",
gcode_file_time: 1705008250.2333415,
}, },
{ {
gcode_file_name: "GoHomeXYZ.ngc", file_name: "",
gcode_file_time: 1705008321.710827,
}, },
{ {
gcode_file_name: "ParkRearRightWW.ngc", file_name: "",
gcode_file_time: 1705008360.977644,
}, },
{ {
gcode_file_name: "SpindleWarmUp1Minute.ngc", file_name: "",
gcode_file_time: 1705008372.967075,
}, },
{ {
gcode_file_name: "TurnOnSpindle.ngc", file_name: "",
gcode_file_time: 1705008405.5059154,
}, },
{ {
gcode_file_name: "TurnOffSpindleAndLaser.ngc", file_name: "",
gcode_file_time: 1705008384.6566093,
}, },
{ {
gcode_file_name: "VacOn.ngc", file_name: "",
gcode_file_time: 1705008413.7756715,
}, },
{ {
gcode_file_name: "TurnOffVac.ngc", file_name: "",
gcode_file_time: 1705008395.476232,
}, },
], ],
}; };
@@ -66,7 +58,7 @@ module.exports = {
return this.mach_state == "READY"; return this.mach_state == "READY";
}, },
macrosList: function () { macrosList: function () {
return this.config.macrosList.map(el => el.gcode_file_name); return this.config.macrosList.map(el => el.file_name);
}, },
getMacrosColor: function () { getMacrosColor: function () {
return this.config.macros[this.tab - 1]["color"]; return this.config.macros[this.tab - 1]["color"];
@@ -82,9 +74,6 @@ module.exports = {
updateNewGcode: function (event) { updateNewGcode: function (event) {
this.newGcode[this.tab - 1] = event.target.value; this.newGcode[this.tab - 1] = event.target.value;
}, },
isPresent: function (obj) {
return this.defaultMacrosList.find(item => item.gcode_file_name == obj.gcode_file_name);
},
loadMacrosGcode: async function () { loadMacrosGcode: async function () {
const file = this.selectedValues[this.tab - 1]; const file = this.selectedValues[this.tab - 1];
if (this.selectedValues[this.tab - 1] != "default") { if (this.selectedValues[this.tab - 1] != "default") {
@@ -92,11 +81,8 @@ module.exports = {
cache: "no-cache", cache: "no-cache",
}); });
const text = (await response.text()).split(" ").join("\n"); const text = (await response.text()).split(" ").join("\n");
console.log(text);
// this.newGcode[this.tab - 1]=text;
this.$set("newGcode[this.tab-1]", text); this.$set("newGcode[this.tab-1]", text);
} else { } else {
// this.newGcode[this.tab - 1]="";
this.$set("newGcode[this.tab-1]", ""); this.$set("newGcode[this.tab-1]", "");
} }
console.log("newGcode: ", this.newGcode[this.tab - 1]); console.log("newGcode: ", this.newGcode[this.tab - 1]);
@@ -122,10 +108,9 @@ module.exports = {
} }
const gcodeData = { const gcodeData = {
gcode_file_name: file.name, file_name: file.name,
gcode_file_time: this.state.selected_time,
}; };
if (!this.config.macrosList.some(item => item.gcode_file_name == file.name)) { if (!this.config.macrosList.some(item => item.file_name == file.name)) {
console.log("new gcode file"); console.log("new gcode file");
this.config.macrosList.push(gcodeData); this.config.macrosList.push(gcodeData);
try { try {
@@ -175,10 +160,9 @@ module.exports = {
xhr.send(file); xhr.send(file);
const gcodeData = { const gcodeData = {
gcode_file_name: filename, file_name: filename,
gcode_file_time: this.state.selected_time,
}; };
if (!this.config.macrosList.some(item => item.gcode_file_name == filename)) { if (!this.config.macrosList.some(item => item.file_name == filename)) {
console.log("new item"); console.log("new item");
this.config.macrosList.push(gcodeData); this.config.macrosList.push(gcodeData);
@@ -206,9 +190,8 @@ module.exports = {
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].gcode_file_name = file_name; this.config.macros[this.tab - 1].file_name = file_name;
this.config.macros[this.tab - 1].gcode_file_time = this.state.selected_time; console.log("config.macros[this.tab - 1].file_name", this.config.macros[this.tab - 1].file_name);
console.log("config.macros[this.tab - 1].gcode_file_name", this.config.macros[this.tab - 1].gcode_file_name);
this.confirmSave = false; this.confirmSave = false;
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);
@@ -224,32 +207,26 @@ module.exports = {
if (this.selectedValues[this.tab - 1] == "default") { if (this.selectedValues[this.tab - 1] == "default") {
this.$set("newGcode[this.tab-1]", ""); this.$set("newGcode[this.tab-1]", "");
} else { } else {
if (!this.isPresent({ gcode_file_name: this.selectedValues[this.tab - 1] })) { api.delete(`file/${this.selectedValues[this.tab - 1]}`);
console.log("this is not default macros"); this.$set("newGcode[this.tab-1]", "");
api.delete(`file/${this.selectedValues[this.tab - 1]}`); this.config.macrosList = this.config.macrosList.filter(
this.$set("newGcode[this.tab-1]", ""); item => item.file_name !== this.selectedValues[this.tab - 1],
this.config.macrosList = this.config.macrosList.filter( );
item => item.gcode_file_name !== this.selectedValues[this.tab - 1], this.$set("this.selectedValues[this.tab - 1]", "default");
); try {
try { await api.put("config/save", this.config);
await api.put("config/save", this.config); this.$dispatch("update");
this.$dispatch("update"); } catch (error) {
} catch (error) { console.error("Restore Failed: ", error);
console.error("Restore Failed: ", error); alert("Restore failed");
alert("Restore failed");
}
} else {
alert("You cannot delete GCode of Default Macros");
} }
} }
this.deleteGCode = false; this.deleteGCode = false;
}, },
delete_all_macros: async function () { delete_all_macros: async function () {
const itemsToDelete = this.config.macrosList.filter(el => !this.isPresent(el)); const macrosList = this.config.macrosList.map(item => item.file_name).toString();
const macrosList = itemsToDelete.map(item => item.gcode_file_name).toString();
api.delete(`file/DINCAIQABiDARixAxiABDIHCAMQABiABDIHCAQQABiABDIH${macrosList}`); api.delete(`file/DINCAIQABiDARixAxiABDIHCAMQABiABDIHCAQQABiABDIH${macrosList}`);
this.config.macrosList = this.defaultMacrosList; this.config.macrosList = this.defaultMacrosList;
this.deleteGCode = false;
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);
this.$dispatch("update"); this.$dispatch("update");
@@ -259,63 +236,56 @@ module.exports = {
} }
}, },
cancelMacros: function () { cancelMacros: function () {
const defaultValue = this.config.macros[this.tab-1]; const defaultValue = this.config.macros[this.tab - 1];
document.getElementById(`macros-name-${this.tab - 1}`).value = defaultValue.name; document.getElementById(`macros-name-${this.tab - 1}`).value = defaultValue.name;
document.getElementById(`macros-color-${this.tab - 1}`).value = defaultValue.color; document.getElementById(`macros-color-${this.tab - 1}`).value = defaultValue.color;
document.getElementById(`gcodeSelect-${this.tab - 1}`).value = "default"; document.getElementById(`gcodeSelect-${this.tab - 1}`).value = "default";
this.newGcode[this.tab - 1] = ""; this.$set("newGcode[this.tab-1]", "");
}, },
resetConfig: async function () { deleteAllMacros: async function () {
this.config.macros = [ this.config.macros = [
{ {
name: "FireLaser", name: "Macros 1",
color: "#dedede", color: "#dedede",
gcode_file_name: "FireLaser.ngc", file_name: "",
gcode_file_time: 1705008250.2333415,
}, },
{ {
name: "Home", name: "Macros 2",
color: "#dedede", color: "#dedede",
gcode_file_name: "GoHomeXYZ.ngc", file_name: "",
gcode_file_time: 1705008321.710827,
}, },
{ {
name: "Park", name: "Macros 3",
color: "#dedede", color: "#dedede",
gcode_file_name: "ParkRearRightWW.ngc", file_name: "",
gcode_file_time: 1705008360.977644,
}, },
{ {
name: "Spindle Warmup", name: "Macros 4",
color: "#dedede", color: "#dedede",
gcode_file_name: "SpindleWarmUp1Minute.ngc", file_name: "",
gcode_file_time: 1705008372.967075,
}, },
{ {
name: "Spindle ON", name: "Macros 5",
color: "#dedede", color: "#dedede",
gcode_file_name: "TurnOnSpindle.ngc", file_name: "",
gcode_file_time: 1705008405.5059154,
}, },
{ {
name: "Spindle OFF", name: "Macros 6",
color: "#dedede", color: "#dedede",
gcode_file_name: "TurnOffSpindleAndLaser.ngc", file_name: "",
gcode_file_time: 1705008384.6566093,
}, },
{ {
name: "Vacuum ON", name: "Macros 7",
color: "#dedede", color: "#dedede",
gcode_file_name: "VacOn.ngc", file_name: "",
gcode_file_time: 1705008413.7756715,
}, },
{ {
name: "Vacuum OFF", name: "Macros 8",
color: "#dedede", color: "#dedede",
gcode_file_name: "TurnOffVac.ngc", file_name: "",
gcode_file_time: 1705008395.476232,
}, },
]; ];
this.delete_all_macros();
this.confirmReset = false; this.confirmReset = false;
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);
@@ -332,40 +302,7 @@ module.exports = {
console.log(this.config); console.log(this.config);
}, },
resetMacrosList: async function () { resetMacrosList: async function () {
this.config.macrosList = [ this.config.macrosList = this.defaultMacrosList;
{
gcode_file_name: "FireLaser.ngc",
gcode_file_time: 1705008250.2333415,
},
{
gcode_file_name: "GoHomeXYZ.ngc",
gcode_file_time: 1705008321.710827,
},
{
gcode_file_name: "ParkRearRightWW.ngc",
gcode_file_time: 1705008360.977644,
},
{
gcode_file_name: "SpindleWarmUp1Minute.ngc",
gcode_file_time: 1705008372.967075,
},
{
gcode_file_name: "TurnOnSpindle.ngc",
gcode_file_time: 1705008405.5059154,
},
{
gcode_file_name: "TurnOffSpindleAndLaser.ngc",
gcode_file_time: 1705008384.6566093,
},
{
gcode_file_name: "VacOn.ngc",
gcode_file_time: 1705008413.7756715,
},
{
gcode_file_name: "TurnOffVac.ngc",
gcode_file_time: 1705008395.476232,
},
];
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);
this.$dispatch("update"); this.$dispatch("update");

View File

@@ -10,6 +10,14 @@ script#control-view-template(type="text/x-template")
div(slot="footer") div(slot="footer")
label Simulating {{(toolpath_progress || 0) | percent}} label Simulating {{(toolpath_progress || 0) | percent}}
message(:show.sync="showNoGcodeMessage")
h3(slot="header") GCode Not Set
div(slot="body")
p Configure the GCode for the selected macros to use it
div(slot="footer")
button.pure-button(@click="showNoGcodeMessage=false") OK
table(style="table-layout: fixed; width: 100%;") table(style="table-layout: fixed; width: 100%;")
tr(style="height: fit-content;") tr(style="height: fit-content;")
td(style="white-space: nowrap; width: 410px;", rowspan="2") td(style="white-space: nowrap; width: 410px;", rowspan="2")

View File

@@ -1,14 +1,14 @@
script#macros-template(type="text/x-template") script#macros-template(type="text/x-template")
#macros #macros
message(:show.sync="confirmReset") message(:show.sync="confirmReset")
h3(slot="header") Reset All Macros? h3(slot="header") Delete All Macros?
div(slot="body") div(slot="body")
p Are you sure you want to reset all macros? p Are you sure you want to Delete all macros?
div(slot="footer") div(slot="footer")
button.pure-button(@click="confirmReset=false") Cancel button.pure-button(@click="confirmReset=false") Cancel
button.pure-button.pure-button-primary(@click="resetConfig") button.pure-button.pure-button-primary(@click="deleteAllMacros")
| Reset | Delete All
message(:show.sync="confirmSave") message(:show.sync="confirmSave")
h3(slot="header") Confirm Save? h3(slot="header") Confirm Save?
@@ -24,9 +24,6 @@ script#macros-template(type="text/x-template")
p(slot="body") p(slot="body")
div(slot="footer") div(slot="footer")
button.pure-button(@click="deleteGCode = false") Cancel button.pure-button(@click="deleteGCode = false") Cancel
button.pure-button.button-error(@click="delete_all_macros")
.fa.fa-trash
|  All Macros
button.pure-button.button-success(@click="delete_current") button.pure-button.button-success(@click="delete_current")
.fa.fa-trash .fa.fa-trash
|  Selected |  Selected

View File

@@ -537,52 +537,44 @@
"type": "list", "type": "list",
"default": [ "default": [
{ {
"name": "FireLaser", "name": "Macros 1",
"color": "#dedede", "color": "#dedede",
"gcode_file_name": "FireLaser.ngc", "file_name": ""
"gcode_file_time": 1705008250.2333415
}, },
{ {
"name": "Home", "name": "Macros 2",
"color": "#dedede", "color": "#dedede",
"gcode_file_name": "GoHomeXYZ.ngc", "file_name": ""
"gcode_file_time": 1705008321.710827
}, },
{ {
"name": "Park", "name": "Macros 3",
"color": "#dedede", "color": "#dedede",
"gcode_file_name": "ParkRearRightWW.ngc", "file_name": ""
"gcode_file_time": 1705008360.977644
}, },
{ {
"name": "Spindle Warmup", "name": "Macros 4",
"color": "#dedede", "color": "#dedede",
"gcode_file_name": "SpindleWarmUp1Minute.ngc", "file_name": ""
"gcode_file_time": 1705008372.967075
}, },
{ {
"name": "Spindle ON", "name": "Macros 5",
"color": "#dedede", "color": "#dedede",
"gcode_file_name": "TurnOnSpindle.ngc", "file_name": ""
"gcode_file_time": 1705008405.5059154
}, },
{ {
"name": "Spindle OFF", "name": "Macros 6",
"color": "#dedede", "color": "#dedede",
"gcode_file_name": "TurnOffSpindleAndLaser.ngc", "file_name": ""
"gcode_file_time": 1705008384.6566093
}, },
{ {
"name": "Vacuum ON", "name": "Macros 7",
"color": "#dedede", "color": "#dedede",
"gcode_file_name": "VacOn.ngc", "file_name": ""
"gcode_file_time": 1705008413.7756715
}, },
{ {
"name": "Vacuum OFF", "name": "Macros 8",
"color": "#dedede", "color": "#dedede",
"gcode_file_name": "TurnOffVac.ngc", "file_name": ""
"gcode_file_time": 1705008395.476232
} }
], ],
"template": { "template": {
@@ -594,76 +586,31 @@
"type": "string", "type": "string",
"default": "#e6e6e6" "default": "#e6e6e6"
}, },
"gcode_file_name": { "file_name": {
"type": "string", "type": "string",
"default": "" "default": ""
},
"gcode_file_time": {
"type": "int",
"default": 1705008395
} }
} }
}, },
"macrosList": { "macrosList": {
"type": "list", "type": "list",
"default": [ "default": [],
{
"gcode_file_name": "FireLaser.ngc",
"gcode_file_time": 1705008250.2333415
},
{
"gcode_file_name": "GoHomeXYZ.ngc",
"gcode_file_time": 1705008321.710827
},
{
"gcode_file_name": "ParkRearRightWW.ngc",
"gcode_file_time": 1705008360.977644
},
{
"gcode_file_name": "SpindleWarmUp1Minute.ngc",
"gcode_file_time": 1705008372.967075
},
{
"gcode_file_name": "TurnOnSpindle.ngc",
"gcode_file_time": 1705008405.5059154
},
{
"gcode_file_name": "TurnOffSpindleAndLaser.ngc",
"gcode_file_time": 1705008384.6566093
},
{
"gcode_file_name": "VacOn.ngc",
"gcode_file_time": 1705008413.7756715
},
{
"gcode_file_name": "TurnOffVac.ngc",
"gcode_file_time": 1705008395.476232
}
],
"template": { "template": {
"gcode_file_name": { "file_name": {
"type": "string", "type": "string",
"default": "" "default": ""
},
"gcode_file_time": {
"type": "int",
"default": 1705008395
} }
} }
}, },
"gcodeList":{ "gcodeList": {
"type":"list", "type": "list",
"default":[], "default": [],
"template": { "template": {
"gcode_file_name": { "file_name": {
"type": "string", "type": "string",
"default": "" "default": ""
},
"gcode_file_time": {
"type": "int",
"default": 1705008395
} }
} }
}, },

View File

@@ -1159,7 +1159,7 @@ tt.save
button button
border-radius 8px border-radius 8px
border-width 1px border-width 1px
border 0 border 1
.input-field .input-field
margin-top 10px margin-top 10px