state.gcodeList to config.gcodeList

This commit is contained in:
sanjayk03-dev
2024-01-26 16:18:49 +05:30
parent 100c8697de
commit ec757089f6
6 changed files with 103 additions and 30 deletions

View File

@@ -116,7 +116,7 @@ module.exports = new Vue({
wifiName: "not connected",
macros:[{},{},{},{},{},{},{},{}],
macrosList:[],
GCodeList:[]
gcodeList:[]
},
state: {
messages: [],

View File

@@ -205,8 +205,9 @@ module.exports = {
item => !this.config.macrosList.some(compareItem => compareItem.gcode_file_name == item),
);
console.log("filesWithNoMacros: ", filesWithNoMacros);
console.log("this.state.GCodeList", this.state.GCodeList);
const unionSet = new Set([...filesWithNoMacros, ...this.state.GCodeList]);
console.log("this.config.gcodeList", config.gcodeList);
const gcodelist = this.config.gcodeList.map(item => item.gcode_file_name);
const unionSet = new Set([...filesWithNoMacros, ...gcodelist]);
const files = [...unionSet];
console.log("files: ", files);
return files;
@@ -375,10 +376,10 @@ module.exports = {
return;
}
const isAlreadyPresent = this.state.GCodeList.find(element => element == file.name);
const isAlreadyPresent = this.config.gcodeList.find(element => element.gcode_file_name == file.name);
if (isAlreadyPresent == undefined) {
console.log("new gcode file");
this.state.GCodeList.push(file.name);
this.config.gcodeList.push({ gcode_file_name: file.name });
try {
await api.put("config/save", this.config);
this.$dispatch("update");
@@ -392,7 +393,7 @@ module.exports = {
if (this.config.macrosList.some(obj => obj.gcode_file_name == file.name)) {
console.log("It is a macros, remove it from macrosList");
// this.config.GCodeList.push(file.name);
// this.config.gcodeList.push(file.name);
}
SvelteComponents.showDialog("Upload", {
@@ -410,7 +411,7 @@ module.exports = {
api.delete(`file/${this.state.selected}`);
}
} else {
this.state.GCodeList = this.state.GCodeList.filter(item => item != this.state.selected);
this.config.gcodeList = this.config.gcodeList.filter(item => item.gcode_file_name != this.state.selected);
}
this.deleteGCode = false;
@@ -421,10 +422,17 @@ module.exports = {
this.deleteGCode = false;
},
delete_all_except_macros: function () {
delete_all_except_macros: async function () {
const macrosList = this.config.macrosList.map(item => item.gcode_file_name).toString();
api.delete(`file/EgZjaHJvbWUqCggBEAAYsQMYgAQyBggAEEUYOTIKCAE${macrosList}`);
this.state.GCodeList = [];
this.config.gcodeList = [];
try {
await api.put("config/save", this.config);
this.$dispatch("update");
} catch (error) {
console.error("Restore Failed: ", error);
alert("Restore failed");
}
this.deleteGCode = false;
},

View File

@@ -41,7 +41,6 @@ class Config(object):
self.log = ctrl.log.get('Config')
self.values = {}
self.values['GCodeList'] = []
try:
self.version = "1.4.0"
@@ -63,7 +62,6 @@ class Config(object):
try:
self._upgrade(config)
config['GCodeList'] = self.get('GCodeList', ["Test.ngc"])
except Exception: self.log.exception('Internal error: Failed to upgrade config')
except Exception as e:

View File

@@ -87,7 +87,6 @@ class State(object):
self.reset()
self.load_files()
self.load_gcodes()
observer = Observer()
observer.schedule(UploadChangeHandler(self), self.ctrl.get_upload(), recursive=True)
@@ -140,17 +139,6 @@ class State(object):
return files
def load_gcodes(self):
GCodeList = []
# GCodeList = copy.deepcopy(self.get('files'))
# macrosList = self.ctrl.config.get('macrosList', [])
# macro_names = [macro["gcode_file_name"] for macro in macrosList]
# GCodeList = [file for file in files if file not in macro_names]
self.set('GCodeList', GCodeList)
def clear_files(self):
self.select_file('')
self.set('files', [])

View File

@@ -535,18 +535,78 @@
"macros": {
"type": "list",
"default": [],
"default": [
{
"name": "FireLaser",
"color": "#dedede",
"gcode_file_name": "FireLaser.ngc",
"gcode_file_time": 1705008250.2333415
},
{
"name": "Home",
"color": "#dedede",
"gcode_file_name": "GoHomeXYZ.ngc",
"gcode_file_time": 1705008321.710827
},
{
"name": "Park",
"color": "#dedede",
"gcode_file_name": "ParkRearRightWW.ngc",
"gcode_file_time": 1705008360.977644
},
{
"name": "Spindle Warmup",
"color": "#dedede",
"gcode_file_name": "SpindleWarmUp1Minute.ngc",
"gcode_file_time": 1705008372.967075
},
{
"name": "Spindle ON",
"color": "#dedede",
"gcode_file_name": "TurnOnSpindle.ngc",
"gcode_file_time": 1705008405.5059154
},
{
"name": "Spindle OFF",
"color": "#dedede",
"gcode_file_name": "TurnOffSpindleAndLaser.ngc",
"gcode_file_time": 1705008384.6566093
},
{
"name": "Vacuum ON",
"color": "#dedede",
"gcode_file_name": "VacOn.ngc",
"gcode_file_time": 1705008413.7756715
},
{
"name": "Vacuum OFF",
"color": "#dedede",
"gcode_file_name": "TurnOffVac.ngc",
"gcode_file_time": 1705008395.476232
}
],
"template": {
"name": { "type": "string", "default": "" },
"color": { "type": "string", "default": "#e6e6e6" },
"gcode_file_name": { "type": "string", "default": "" },
"gcode_file_time": { "type": "int", "default": 1705008395 }
"name": {
"type": "string",
"default": ""
},
"color": {
"type": "string",
"default": "#e6e6e6"
},
"gcode_file_name": {
"type": "string",
"default": ""
},
"gcode_file_time": {
"type": "int",
"default": 1705008395
}
}
},
"macrosList": {
"type": "list",
"index": "12345678",
"default": [
{
"gcode_file_name": "FireLaser.ngc",
@@ -582,6 +642,24 @@
}
],
"template": {
"gcode_file_name": {
"type": "string",
"default": ""
},
"gcode_file_time": {
"type": "int",
"default": 1705008395
}
}
},
"gcodeList":{
"type":"list",
"default":[],
"template": {
"gcode_file_name": {
"type": "string",
"default": ""
},
"gcode_file_time": {
"type": "int",
"default": 1705008395

View File

@@ -682,7 +682,8 @@ span.unit
border-radius 5px
margin-left 1rem
background-color #5a9ad7
color #fff display flex
color #fff
display flex
align-items center
justify-content space-around