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",
ask_home: true,
showGcodeMessage: false,
showNoGcodeMessage: false,
};
},
@@ -202,11 +203,11 @@ module.exports = {
},
gcodeFiles: function () {
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("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 files = [...unionSet];
console.log("final files: ", files);
@@ -376,10 +377,10 @@ module.exports = {
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) {
console.log("new gcode file");
this.config.gcodeList.push({ gcode_file_name: file.name });
this.config.gcodeList.push({ file_name: file.name });
try {
await api.put("config/save", this.config);
this.$dispatch("update");
@@ -391,7 +392,7 @@ module.exports = {
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");
// this.config.gcodeList.push(file.name);
}
@@ -406,12 +407,12 @@ module.exports = {
},
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) {
api.delete(`file/${this.state.selected}`);
}
} 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;
@@ -423,7 +424,7 @@ module.exports = {
},
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}`);
this.config.gcodeList = [];
try {
@@ -545,18 +546,18 @@ module.exports = {
SvelteComponents.showDialog("Probe", { probeType });
},
runMacros: function (id) {
if (
this.config.macros[id].gcode_file_name != this.state.selected ||
this.config.macros[id].gcode_file_time != this.state.selected_time
) {
this.state.selected = this.config.macros[id].gcode_file_name;
this.state.selected_time = this.config.macros[id].gcode_file_time;
}
try {
this.loadGCode();
this.start_pause();
} catch (error) {
console.warn("Error running program: ", error);
if (this.config.macros[id].file_name == "") {
this.showNoGcodeMessage = true;
} else {
if (this.config.macros[id].file_name != this.state.selected) {
this.state.selected = this.config.macros[id].file_name; //TODO :get file
}
try {
this.loadGCode();
this.start_pause();
} catch (error) {
console.warn("Error running program: ", error);
}
}
},
},

View File

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

View File

@@ -9,6 +9,14 @@ script#control-view-template(type="text/x-template")
div(slot="footer")
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%;")
tr(style="height: fit-content;")

View File

@@ -1,14 +1,14 @@
script#macros-template(type="text/x-template")
#macros
message(:show.sync="confirmReset")
h3(slot="header") Reset All Macros?
h3(slot="header") Delete All Macros?
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")
button.pure-button(@click="confirmReset=false") Cancel
button.pure-button.pure-button-primary(@click="resetConfig")
| Reset
button.pure-button.pure-button-primary(@click="deleteAllMacros")
| Delete All
message(:show.sync="confirmSave")
h3(slot="header") Confirm Save?
@@ -24,9 +24,6 @@ script#macros-template(type="text/x-template")
p(slot="body")
div(slot="footer")
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")
.fa.fa-trash
|  Selected

View File

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

View File

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