not deleting default macros
This commit is contained in:
119
src/js/macros.js
119
src/js/macros.js
@@ -15,6 +15,40 @@ module.exports = {
|
||||
deleteGCode: false,
|
||||
selectedValues: ["default", "default", "default", "default", "default", "default", "default", "default"],
|
||||
newGcode: ["", "", "", "", "", "", "", ""],
|
||||
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,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -34,8 +68,11 @@ module.exports = {
|
||||
macrosList: function () {
|
||||
return this.config.macrosList.map(el => el.gcode_file_name);
|
||||
},
|
||||
getMacrosData: function (key) {
|
||||
return this.config.macros[this.tab - 1][key];
|
||||
getMacrosColor: function () {
|
||||
return this.config.macros[this.tab - 1]['color'];
|
||||
},
|
||||
getMacrosName: function () {
|
||||
return this.config.macros[this.tab - 1]['name'];
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
@@ -45,6 +82,9 @@ module.exports = {
|
||||
updateNewGcode: function (event) {
|
||||
this.newGcode[this.tab - 1] = event.target.value;
|
||||
},
|
||||
isPresent: function (obj) {
|
||||
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") {
|
||||
@@ -138,7 +178,8 @@ module.exports = {
|
||||
gcode_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[gcode_file_name] !== filename)) {
|
||||
console.log('new item');
|
||||
this.config.macrosList.push(gcodeData);
|
||||
}
|
||||
|
||||
@@ -180,58 +221,31 @@ module.exports = {
|
||||
},
|
||||
delete_current: async function () {
|
||||
console.log("delete a gcode");
|
||||
if(this.selectedValues[this.tab - 1] == "default"){
|
||||
if (this.selectedValues[this.tab - 1] == "default") {
|
||||
this.$set("newGcode[this.tab-1]", "");
|
||||
}else{
|
||||
api.delete(`file/${this.selectedValues[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 {
|
||||
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");
|
||||
}
|
||||
}
|
||||
this.deleteGCode = false;
|
||||
},
|
||||
delete_all_macros: async function () {
|
||||
const 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,
|
||||
},
|
||||
];
|
||||
const isPresent = obj => defaultMacrosList.find(item => item.gcode_file_name == obj.gcode_file_name);
|
||||
const itemsToDelete = this.config.macrosList.filter(el => !isPresent(el));
|
||||
const itemsToDelete = this.config.macrosList.filter(el => !this.isPresent(el));
|
||||
const macrosList = itemsToDelete.map(item => item.gcode_file_name).toString();
|
||||
api.delete(`file/DINCAIQABiDARixAxiABDIHCAMQABiABDIHCAQQABiABDIH${macrosList}`);
|
||||
this.config.macrosList = defaultMacrosList;
|
||||
@@ -250,13 +264,6 @@ module.exports = {
|
||||
document.getElementById(`gcodeSelect-${this.tab - 1}`).value = "default";
|
||||
this.newGcode[this.tab - 1] = "";
|
||||
},
|
||||
// macrosList: function () {
|
||||
// const macros = this.state.files.filter(
|
||||
// (name) => !this.config.macros.some((obj) => obj.name === name)
|
||||
// );
|
||||
// console.log("Only Macros: ", macros);
|
||||
// return macros;
|
||||
// },
|
||||
resetConfig: async function () {
|
||||
this.config.macros = [
|
||||
{
|
||||
|
||||
@@ -18,8 +18,9 @@ script#macros-template(type="text/x-template")
|
||||
div(slot="footer")
|
||||
button.pure-button(@click="confirmSave=false") Cancel
|
||||
button.pure-button.pure-button-primary(@click="saveMacros") Confirm
|
||||
|
||||
message(:show.sync="deleteGCode")
|
||||
h3(slot="header") Delete GCode?
|
||||
h3(slot="header") Delete?
|
||||
p(slot="body")
|
||||
div(slot="footer")
|
||||
button.pure-button(@click="deleteGCode = false") Cancel
|
||||
@@ -67,8 +68,8 @@ script#macros-template(type="text/x-template")
|
||||
.macros-form
|
||||
p.title Name
|
||||
.input-container
|
||||
input.input-color(type="color",id="macros-color-0",v-model="getMacrosData('color')")
|
||||
input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-0" v-model="getMacrosData('name')")
|
||||
input.input-color(type="color",id="macros-color-0",v-model="getMacrosColor")
|
||||
input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-0" v-model="getMacrosName")
|
||||
p.title G-Code
|
||||
.select-upload-gcode
|
||||
select#gcodeSelect-0(title="Select previously uploaded GCode programs.",selected
|
||||
@@ -85,7 +86,7 @@ script#macros-template(type="text/x-template")
|
||||
input(type="file", @change="uploadMacrosGcode", :disabled="!is_ready",
|
||||
accept=".nc,.ngc,.gcode,.gc")
|
||||
button.pure-button(title="Delete Macros GCodes",@click="deleteGCode = true",
|
||||
:disabled="!state.selected",style="height:40px;width:130px;font-weight:normal;border-radius:5px;margin-left:4px;background-color:#5a9ad7;color:#fff;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete GCode
|
||||
:disabled="!selectedValues[tab-1]=='default'",style="height:40px;width:130px;font-weight:normal;border-radius:5px;background-color:#5a9ad7;color:#fff;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete
|
||||
.fa.fa-trash
|
||||
br
|
||||
.gcodeContainer
|
||||
@@ -118,7 +119,7 @@ script#macros-template(type="text/x-template")
|
||||
input(type="file", @change="uploadMacrosGcode", :disabled="!is_ready",
|
||||
accept=".nc,.ngc,.gcode,.gc")
|
||||
button.pure-button(title="Delete Macros GCodes",@click="deleteGCode = true",
|
||||
:disabled="!state.selected",style="height:50px;width:170px;font-weight:normal;color:#fff;background-color:#5a9ad7;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete GCode
|
||||
:disabled="!selectedValues[tab-1]=='default'",style="height:40px;width:130px;font-weight:normal;border-radius:5px;background-color:#5a9ad7;color:#fff;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete
|
||||
.fa.fa-trash
|
||||
br
|
||||
.gcodeContainer
|
||||
@@ -151,7 +152,7 @@ script#macros-template(type="text/x-template")
|
||||
input(type="file", @change="uploadMacrosGcode", :disabled="!is_ready",
|
||||
accept=".nc,.ngc,.gcode,.gc")
|
||||
button.pure-button(title="Delete Macros GCodes",@click="deleteGCode = true",
|
||||
:disabled="!state.selected",style="height:50px;width:170px;font-weight:normal;color:#fff;background-color:#5a9ad7;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete GCode
|
||||
:disabled="!selectedValues[tab-1]=='default'",style="height:40px;width:130px;font-weight:normal;border-radius:5px;background-color:#5a9ad7;color:#fff;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete
|
||||
.fa.fa-trash
|
||||
br
|
||||
.gcodeContainer
|
||||
@@ -184,7 +185,7 @@ script#macros-template(type="text/x-template")
|
||||
input(type="file", @change="uploadMacrosGcode", :disabled="!is_ready",
|
||||
accept=".nc,.ngc,.gcode,.gc")
|
||||
button.pure-button(title="Delete Macros GCodes",@click="deleteGCode = true",
|
||||
:disabled="!state.selected",style="height:50px;width:170px;font-weight:normal;color:#fff;background-color:#5a9ad7;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete GCode
|
||||
:disabled="!selectedValues[tab-1]=='default'",style="height:40px;width:130px;font-weight:normal;border-radius:5px;background-color:#5a9ad7;color:#fff;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete
|
||||
.fa.fa-trash
|
||||
br
|
||||
.gcodeContainer
|
||||
@@ -217,7 +218,7 @@ script#macros-template(type="text/x-template")
|
||||
input(type="file", @change="uploadMacrosGcode", :disabled="!is_ready",
|
||||
accept=".nc,.ngc,.gcode,.gc")
|
||||
button.pure-button(title="Delete Macros GCodes",@click="deleteGCode = true",
|
||||
:disabled="!state.selected",style="height:50px;width:170px;font-weight:normal;color:#fff;background-color:#5a9ad7;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete GCode
|
||||
:disabled="!selectedValues[tab-1]=='default'",style="height:40px;width:130px;font-weight:normal;border-radius:5px;background-color:#5a9ad7;color:#fff;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete
|
||||
.fa.fa-trash
|
||||
br
|
||||
.gcodeContainer
|
||||
@@ -250,7 +251,7 @@ script#macros-template(type="text/x-template")
|
||||
input(type="file", @change="uploadMacrosGcode", :disabled="!is_ready",
|
||||
accept=".nc,.ngc,.gcode,.gc")
|
||||
button.pure-button(title="Delete Macros GCodes",@click="deleteGCode = true",
|
||||
:disabled="!state.selected",style="height:50px;width:170px;font-weight:normal;color:#fff;background-color:#5a9ad7;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete GCode
|
||||
:disabled="!selectedValues[tab-1]=='default'",style="height:40px;width:130px;font-weight:normal;border-radius:5px;background-color:#5a9ad7;color:#fff;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete
|
||||
.fa.fa-trash
|
||||
br
|
||||
.gcodeContainer
|
||||
@@ -283,7 +284,7 @@ script#macros-template(type="text/x-template")
|
||||
input(type="file", @change="uploadMacrosGcode", :disabled="!is_ready",
|
||||
accept=".nc,.ngc,.gcode,.gc")
|
||||
button.pure-button(title="Delete Macros GCodes",@click="deleteGCode = true",
|
||||
:disabled="!state.selected",style="height:50px;width:170px;font-weight:normal;color:#fff;background-color:#5a9ad7;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete GCode
|
||||
:disabled="!selectedValues[tab-1]=='default'",style="height:40px;width:130px;font-weight:normal;border-radius:5px;background-color:#5a9ad7;color:#fff;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete
|
||||
.fa.fa-trash
|
||||
br
|
||||
.gcodeContainer
|
||||
@@ -316,7 +317,7 @@ script#macros-template(type="text/x-template")
|
||||
input(type="file", @change="uploadMacrosGcode", :disabled="!is_ready",
|
||||
accept=".nc,.ngc,.gcode,.gc")
|
||||
button.pure-button(title="Delete Macros GCodes",@click="deleteGCode = true",
|
||||
:disabled="!state.selected",style="height:50px;width:170px;font-weight:normal;color:#fff;background-color:#5a9ad7;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete GCode
|
||||
:disabled="!selectedValues[tab-1]=='default'",style="height:40px;width:130px;font-weight:normal;border-radius:5px;background-color:#5a9ad7;color:#fff;display:flex;align-items:center;justify-content:space-around;margin-left:1rem") Delete
|
||||
.fa.fa-trash
|
||||
br
|
||||
.gcodeContainer
|
||||
|
||||
@@ -968,7 +968,7 @@ tt.save
|
||||
vertical-align middle
|
||||
|
||||
.modal-container
|
||||
width 300px
|
||||
width 350px
|
||||
margin 0px auto
|
||||
padding 20px 30px
|
||||
background-color #fff
|
||||
@@ -983,6 +983,8 @@ tt.save
|
||||
|
||||
.modal-footer
|
||||
text-align right
|
||||
display flex
|
||||
justify-content space-between
|
||||
|
||||
.modal-enter, .modal-leave
|
||||
opacity 0
|
||||
|
||||
Reference in New Issue
Block a user