推进 INI 面板 session snapshot workflow helper
This commit is contained in:
@@ -41,6 +41,9 @@ import {
|
||||
sessionSnapshotMetadataLogLines,
|
||||
sessionSnapshotSummaryLogLines,
|
||||
} from "./session-summary.js";
|
||||
import {
|
||||
saveMachineSessionSnapshotWorkflow,
|
||||
} from "./session-workflow.js";
|
||||
|
||||
const SAMPLE_PATH =
|
||||
"../../../vendor/linuxcnc/configs/sim/axis/vismach/5axis/table-dual-rotary/xyzab-tdr.ini";
|
||||
@@ -566,35 +569,28 @@ document.getElementById("save-machine-files").addEventListener("click", async ()
|
||||
|
||||
document.getElementById("save-session-snapshot").addEventListener("click", async () => {
|
||||
try {
|
||||
await saveMachineTextFiles(MACHINE_ID, {
|
||||
ini: editor.value,
|
||||
toolTable: DEFAULT_TOOL_TABLE,
|
||||
parameters: DEFAULT_PARAMETERS,
|
||||
const workflow = await saveMachineSessionSnapshotWorkflow({
|
||||
machineId: MACHINE_ID,
|
||||
snapshotId: UI_SESSION.snapshotId,
|
||||
snapshotFilename: UI_SESSION.snapshotFilename,
|
||||
snapshotLabel: sessionSnapshotLabel(UI_SESSION),
|
||||
iniText: editor.value,
|
||||
toolTableText: DEFAULT_TOOL_TABLE,
|
||||
parameterText: DEFAULT_PARAMETERS,
|
||||
gcodeFilename: UI_SESSION.defaultGcodeFilename,
|
||||
gcodeText: DEFAULT_GCODE,
|
||||
metadata: sessionSnapshotMetadata(),
|
||||
saveMachineTextFiles,
|
||||
saveGcodeProgram,
|
||||
saveMachineSessionSnapshot,
|
||||
});
|
||||
await saveGcodeProgram(UI_SESSION.defaultGcodeFilename, DEFAULT_GCODE);
|
||||
const snapshot = await saveMachineSessionSnapshot(
|
||||
UI_SESSION.snapshotId,
|
||||
MACHINE_ID,
|
||||
{
|
||||
filename: UI_SESSION.snapshotFilename,
|
||||
gcodeFilename: UI_SESSION.defaultGcodeFilename,
|
||||
metadata: sessionSnapshotMetadata(),
|
||||
},
|
||||
);
|
||||
setField("sessionIni", snapshot.payload.files.ini);
|
||||
setField("sessionParameters", snapshot.payload.files.parameters);
|
||||
setField("sessionToolTable", snapshot.payload.files.toolTable);
|
||||
setField("sessionGcode", snapshot.payload.files.gcode);
|
||||
setField("sessionSnapshot", sessionSnapshotLabel(UI_SESSION));
|
||||
const summary = createSessionSnapshotSummary(snapshot, sessionSnapshotLabel(UI_SESSION));
|
||||
for (const [name, value] of Object.entries(workflow.fields)) {
|
||||
setField(name, value);
|
||||
}
|
||||
setLog(
|
||||
[
|
||||
"Saved machine session snapshot to OPFS.",
|
||||
...sessionSnapshotSummaryLogLines(summary),
|
||||
`INI: ${summary.iniOpfsPath}`,
|
||||
`Parameter file: ${summary.parameterOpfsPath}`,
|
||||
`Tool table file: ${summary.toolTableOpfsPath}`,
|
||||
`G-code: ${summary.gcodeOpfsPath}`,
|
||||
...workflow.logLines,
|
||||
].join("\n"),
|
||||
);
|
||||
} catch (error) {
|
||||
|
||||
65
wasm-port/runtime/ui/ini-panel/session-workflow.js
Normal file
65
wasm-port/runtime/ui/ini-panel/session-workflow.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
createSessionSnapshotSummary,
|
||||
sessionSnapshotSummaryLogLines,
|
||||
} from "./session-summary.js";
|
||||
|
||||
export function createSessionSnapshotFieldState(summary) {
|
||||
return {
|
||||
sessionIni: summary.iniOpfsPath,
|
||||
sessionParameters: summary.parameterOpfsPath,
|
||||
sessionToolTable: summary.toolTableOpfsPath,
|
||||
sessionGcode: summary.gcodeOpfsPath,
|
||||
sessionSnapshot: summary.snapshotLabel,
|
||||
};
|
||||
}
|
||||
|
||||
export function sessionSnapshotSaveLogLines(summary) {
|
||||
return [
|
||||
...sessionSnapshotSummaryLogLines(summary),
|
||||
`INI: ${summary.iniOpfsPath}`,
|
||||
`Parameter file: ${summary.parameterOpfsPath}`,
|
||||
`Tool table file: ${summary.toolTableOpfsPath}`,
|
||||
`G-code: ${summary.gcodeOpfsPath}`,
|
||||
];
|
||||
}
|
||||
|
||||
export async function saveMachineSessionSnapshotWorkflow({
|
||||
machineId,
|
||||
snapshotId,
|
||||
snapshotFilename,
|
||||
snapshotLabel,
|
||||
iniText,
|
||||
toolTableText,
|
||||
parameterText,
|
||||
gcodeFilename,
|
||||
gcodeText,
|
||||
metadata,
|
||||
saveMachineTextFiles,
|
||||
saveGcodeProgram,
|
||||
saveMachineSessionSnapshot,
|
||||
}) {
|
||||
await Promise.all([
|
||||
saveMachineTextFiles(machineId, {
|
||||
ini: iniText,
|
||||
toolTable: toolTableText,
|
||||
parameters: parameterText,
|
||||
}),
|
||||
saveGcodeProgram(gcodeFilename, gcodeText),
|
||||
]);
|
||||
const snapshot = await saveMachineSessionSnapshot(
|
||||
snapshotId,
|
||||
machineId,
|
||||
{
|
||||
filename: snapshotFilename,
|
||||
gcodeFilename,
|
||||
metadata,
|
||||
},
|
||||
);
|
||||
const summary = createSessionSnapshotSummary(snapshot, snapshotLabel);
|
||||
return {
|
||||
snapshot,
|
||||
summary,
|
||||
fields: createSessionSnapshotFieldState(summary),
|
||||
logLines: sessionSnapshotSaveLogLines(summary),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user