allow for local settings in exports (octoprint, gridhost) to persist in workspace settings along side the existing localStorage
This commit is contained in:
parent
fd7e5a1f0e
commit
c3efac5a59
2 changed files with 49 additions and 22 deletions
|
|
@ -900,6 +900,7 @@ const conf = exports({
|
||||||
favorites:{},
|
favorites:{},
|
||||||
// map of device to last process setting (name)
|
// map of device to last process setting (name)
|
||||||
devproc: {},
|
devproc: {},
|
||||||
|
// application ui and control preferences (Q menu)
|
||||||
controller:{
|
controller:{
|
||||||
view: null,
|
view: null,
|
||||||
dark: false,
|
dark: false,
|
||||||
|
|
@ -933,7 +934,7 @@ const conf = exports({
|
||||||
ortho: false,
|
ortho: false,
|
||||||
devel: false
|
devel: false
|
||||||
},
|
},
|
||||||
// hidden ui groups
|
// default hidden ui groups
|
||||||
hidden: {
|
hidden: {
|
||||||
"fdm-base": true,
|
"fdm-base": true,
|
||||||
"fdm-cool": true,
|
"fdm-cool": true,
|
||||||
|
|
@ -941,7 +942,7 @@ const conf = exports({
|
||||||
"fdm-supp": true,
|
"fdm-supp": true,
|
||||||
"fdm-xprt": true
|
"fdm-xprt": true
|
||||||
},
|
},
|
||||||
// label state preferences
|
// label state preferences (slice/preview toggles)
|
||||||
labels: {
|
labels: {
|
||||||
'CAM-3-arrows': false,
|
'CAM-3-arrows': false,
|
||||||
'FDM-3-engage': false,
|
'FDM-3-engage': false,
|
||||||
|
|
@ -953,6 +954,8 @@ const conf = exports({
|
||||||
synth: {},
|
synth: {},
|
||||||
// widget extra info for slicing (extruder mapping)
|
// widget extra info for slicing (extruder mapping)
|
||||||
widget: {},
|
widget: {},
|
||||||
|
// legacy localStorage settings (like octo print)
|
||||||
|
local: {},
|
||||||
mode: 'FDM',
|
mode: 'FDM',
|
||||||
id: genID(),
|
id: genID(),
|
||||||
ver: CVER
|
ver: CVER
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,17 @@ kiri.export = exportFile;
|
||||||
|
|
||||||
let printSeq = parseInt(local['kiri-print-seq'] || local['print-seq'] || "0") + 1;
|
let printSeq = parseInt(local['kiri-print-seq'] || local['print-seq'] || "0") + 1;
|
||||||
|
|
||||||
|
function localGet(key) {
|
||||||
|
let sloc = api.conf.get().local;
|
||||||
|
return sloc[key] || local[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
function localSet(key, val) {
|
||||||
|
let sloc = api.conf.get().local;
|
||||||
|
sloc[key] = local[key] = val;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
function exportFile(options) {
|
function exportFile(options) {
|
||||||
let mode = api.mode.get();
|
let mode = api.mode.get();
|
||||||
let names = api.widgets.all().map(w => w.meta ? w.meta.file : undefined)
|
let names = api.widgets.all().map(w => w.meta ? w.meta.file : undefined)
|
||||||
|
|
@ -91,7 +102,7 @@ function callExportSLA(options, names) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportLaserDialog(data, names) {
|
function exportLaserDialog(data, names) {
|
||||||
local['kiri-print-seq'] = printSeq++;
|
localSet('kiri-print-seq', printSeq++);
|
||||||
|
|
||||||
const fileroot = names[0] || "laser";
|
const fileroot = names[0] || "laser";
|
||||||
const filename = `${fileroot}-${(printSeq.toString().padStart(3,"0"))}`;
|
const filename = `${fileroot}-${(printSeq.toString().padStart(3,"0"))}`;
|
||||||
|
|
@ -132,8 +143,15 @@ function exportLaserDialog(data, names) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bindField(field, varname) {
|
||||||
|
$(field).onblur = function() {
|
||||||
|
console.log('save', field, 'to', varname);
|
||||||
|
localSet(varname, $(field).value.trim());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function exportGCodeDialog(gcode, sections, info, names) {
|
function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
local['kiri-print-seq'] = printSeq++;
|
localSet('kiri-print-seq', printSeq++);
|
||||||
|
|
||||||
let settings = api.conf.get(),
|
let settings = api.conf.get(),
|
||||||
MODE = api.mode.get_id(),
|
MODE = api.mode.get_id(),
|
||||||
|
|
@ -182,8 +200,8 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
local['octo-host'] = host.trim();
|
localSet('octo-host', host.trim());
|
||||||
local['octo-apik'] = apik.trim();
|
localSet('octo-apik', apik.trim());
|
||||||
|
|
||||||
filename = $('print-filename').value;
|
filename = $('print-filename').value;
|
||||||
form.append("file", getBlob(), filename+"."+fileext);
|
form.append("file", getBlob(), filename+"."+fileext);
|
||||||
|
|
@ -227,7 +245,7 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
|
|
||||||
grid_local = devs;
|
grid_local = devs;
|
||||||
|
|
||||||
let gdev = local['grid-local'];
|
let gdev = localGet('grid-local');
|
||||||
let gloc = $('grid-local');
|
let gloc = $('grid-local');
|
||||||
let html = [];
|
let html = [];
|
||||||
for (let uuid in devs) {
|
for (let uuid in devs) {
|
||||||
|
|
@ -240,7 +258,7 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
if (html.length) {
|
if (html.length) {
|
||||||
gloc.innerHTML = html.join('\n');
|
gloc.innerHTML = html.join('\n');
|
||||||
gloc.onchange = (ev) => {
|
gloc.onchange = (ev) => {
|
||||||
local['grid-local'] = gloc.options[gloc.selectedIndex].value
|
localSet('grid-local', gloc.options[gloc.selectedIndex].value);
|
||||||
};
|
};
|
||||||
$('send-to-gridhead').style.display = 'flex';
|
$('send-to-gridhead').style.display = 'flex';
|
||||||
$('send-to-gridspool').style.display = 'flex';
|
$('send-to-gridspool').style.display = 'flex';
|
||||||
|
|
@ -302,8 +320,8 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
xhtr.onreadystatechange = function() {
|
xhtr.onreadystatechange = function() {
|
||||||
if (xhtr.readyState === 4) {
|
if (xhtr.readyState === 4) {
|
||||||
if (xhtr.status >= 200 && xhtr.status < 300) {
|
if (xhtr.status >= 200 && xhtr.status < 300) {
|
||||||
local['grid-host'] = host;
|
localSet('grid-host', host);
|
||||||
local['grid-apik'] = apik;
|
localSet('grid-apik', apik);
|
||||||
let res = JSON.parse(xhtr.responseText);
|
let res = JSON.parse(xhtr.responseText);
|
||||||
let sel = false;
|
let sel = false;
|
||||||
let match = false;
|
let match = false;
|
||||||
|
|
@ -312,11 +330,11 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
grid_targets = {};
|
grid_targets = {};
|
||||||
for (let key in res) {
|
for (let key in res) {
|
||||||
first = first || key;
|
first = first || key;
|
||||||
if (!local['grid-target']) {
|
if (!localGet('grid-target')) {
|
||||||
local['grid-target'] = key;
|
localSet('grid-target', key);
|
||||||
sel = true;
|
sel = true;
|
||||||
} else {
|
} else {
|
||||||
sel = local['grid-target'] === key;
|
sel = localGet('grid-target') === key;
|
||||||
}
|
}
|
||||||
match = match || sel;
|
match = match || sel;
|
||||||
grid_targets[html.length] = key;
|
grid_targets[html.length] = key;
|
||||||
|
|
@ -329,7 +347,7 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!match) {
|
if (!match) {
|
||||||
local['grid-target'] = first;
|
localSet('grid-target', first);
|
||||||
}
|
}
|
||||||
grid_target.innerHTML = html.join('\n');
|
grid_target.innerHTML = html.join('\n');
|
||||||
} else if (xhtr.status === 401) {
|
} else if (xhtr.status === 401) {
|
||||||
|
|
@ -352,7 +370,7 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
let xhtr = new XMLHttpRequest(),
|
let xhtr = new XMLHttpRequest(),
|
||||||
host = grid_host.value,
|
host = grid_host.value,
|
||||||
apik = grid_apik.value,
|
apik = grid_apik.value,
|
||||||
target = local['grid-target'] || '';
|
target = localGet('grid-target') || '';
|
||||||
|
|
||||||
if (target === '') {
|
if (target === '') {
|
||||||
api.show.alert('invalid or missing target');
|
api.show.alert('invalid or missing target');
|
||||||
|
|
@ -371,8 +389,8 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
local['grid-host'] = host.trim();
|
localSet('grid-host', host.trim());
|
||||||
local['grid-apik'] = apik.trim();
|
localSet('grid-apik', apik.trim());
|
||||||
|
|
||||||
xhtr.onreadystatechange = function() {
|
xhtr.onreadystatechange = function() {
|
||||||
if (xhtr.readyState === 4) {
|
if (xhtr.readyState === 4) {
|
||||||
|
|
@ -471,6 +489,12 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
calcWeight();
|
calcWeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// persist fields when changed
|
||||||
|
bindField('octo-host', 'octo-host');
|
||||||
|
bindField('octo-apik', 'octo-apik');
|
||||||
|
bindField('grid-host', 'grid-host');
|
||||||
|
bindField('grid-apik', 'grid-apik');
|
||||||
|
|
||||||
// in cam mode, show zip file option
|
// in cam mode, show zip file option
|
||||||
let downloadZip = $('print-zip');
|
let downloadZip = $('print-zip');
|
||||||
downloadZip.style.display = sections ? 'flex' : 'none';
|
downloadZip.style.display = sections ? 'flex' : 'none';
|
||||||
|
|
@ -642,8 +666,8 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
$('oph1nt').style.display = 'none';
|
$('oph1nt').style.display = 'none';
|
||||||
$('send-to-gridhost').style.display = 'none';
|
$('send-to-gridhost').style.display = 'none';
|
||||||
}
|
}
|
||||||
octo_host.value = local['octo-host'] || '';
|
octo_host.value = localGet('octo-host') || '';
|
||||||
octo_apik.value = local['octo-apik'] || '';
|
octo_apik.value = localGet('octo-apik') || '';
|
||||||
} catch (e) { console.log(e) }
|
} catch (e) { console.log(e) }
|
||||||
|
|
||||||
// grid:host setup
|
// grid:host setup
|
||||||
|
|
@ -657,10 +681,10 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
grid_apik = $('grid-apik');
|
grid_apik = $('grid-apik');
|
||||||
grid_target = $('grid-target');
|
grid_target = $('grid-target');
|
||||||
grid_target.onchange = function(ev) {
|
grid_target.onchange = function(ev) {
|
||||||
local['grid-target'] = grid_targets[grid_target.selectedIndex];
|
localSet('grid-target', grid_targets[grid_target.selectedIndex]);
|
||||||
};
|
};
|
||||||
grid_host.value = local['grid-host'] || '';
|
grid_host.value = localGet('grid-host') || '';
|
||||||
grid_apik.value = local['grid-apik'] || '';
|
grid_apik.value = localGet('grid-apik') || '';
|
||||||
gridhost_probe();
|
gridhost_probe();
|
||||||
} catch (e) { console.log(e) }
|
} catch (e) { console.log(e) }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue