推进 INI 面板 load-session workflow helper
This commit is contained in:
@@ -34,14 +34,11 @@ import {
|
||||
import {
|
||||
runGcodeSessionWorkflow,
|
||||
} from "./run-workflow.js";
|
||||
import {
|
||||
createMachineSessionLoadSummary,
|
||||
machineSessionLoadLogLines,
|
||||
} from "./session-load-summary.js";
|
||||
import {
|
||||
sessionSnapshotSummaryLogLines,
|
||||
} from "./session-summary.js";
|
||||
import {
|
||||
loadMachineSessionIntoWasmWorkflow,
|
||||
restoreMachineSessionSnapshotWorkflow,
|
||||
saveMachineSessionSnapshotWorkflow,
|
||||
} from "./session-workflow.js";
|
||||
@@ -712,24 +709,17 @@ document.getElementById("restore-session-snapshot").addEventListener("click", as
|
||||
|
||||
document.getElementById("load-session").addEventListener("click", async () => {
|
||||
try {
|
||||
await loadMachineSessionIntoWasm();
|
||||
const loadSummary = createMachineSessionLoadSummary(loadedSession);
|
||||
const workflow = await loadMachineSessionIntoWasmWorkflow({
|
||||
loadSession: () => loadMachineSessionIntoWasm(),
|
||||
});
|
||||
loadedSession = workflow.loadedSession;
|
||||
updatePanelMachineSessionState({
|
||||
sessionLoad: loadSummary,
|
||||
fields: {
|
||||
sessionIni: loadSummary.iniWasmPath,
|
||||
sessionParameters: loadSummary.parameterWasmPath,
|
||||
sessionToolTable: loadSummary.toolTableWasmPath,
|
||||
},
|
||||
sessionLoad: workflow.loadSummary,
|
||||
fields: workflow.fields,
|
||||
lastAction: "load-session",
|
||||
error: null,
|
||||
});
|
||||
setLog(
|
||||
[
|
||||
"Loaded machine session into the interpreter WASM filesystem.",
|
||||
...machineSessionLoadLogLines(loadSummary),
|
||||
].join("\n"),
|
||||
);
|
||||
setLog(workflow.logLines.join("\n"));
|
||||
} catch (error) {
|
||||
updatePanelMachineSessionState({
|
||||
lastAction: "load-session",
|
||||
|
||||
@@ -37,6 +37,35 @@ export function sessionSnapshotRestoreLogLines(summary) {
|
||||
];
|
||||
}
|
||||
|
||||
export function createMachineSessionLoadFieldState(summary) {
|
||||
return {
|
||||
sessionIni: summary.iniWasmPath,
|
||||
sessionParameters: summary.parameterWasmPath,
|
||||
sessionToolTable: summary.toolTableWasmPath,
|
||||
};
|
||||
}
|
||||
|
||||
export function machineSessionLoadWorkflowLogLines(summary) {
|
||||
return [
|
||||
"Loaded machine session into the interpreter WASM filesystem.",
|
||||
...machineSessionLoadLogLines(summary),
|
||||
];
|
||||
}
|
||||
|
||||
export async function loadMachineSessionIntoWasmWorkflow({ loadSession }) {
|
||||
if (typeof loadSession !== "function") {
|
||||
throw new Error("A machine session loader is required.");
|
||||
}
|
||||
const loadedSession = await loadSession();
|
||||
const loadSummary = createMachineSessionLoadSummary(loadedSession);
|
||||
return {
|
||||
loadedSession,
|
||||
loadSummary,
|
||||
fields: createMachineSessionLoadFieldState(loadSummary),
|
||||
logLines: machineSessionLoadWorkflowLogLines(loadSummary),
|
||||
};
|
||||
}
|
||||
|
||||
export async function saveMachineSessionSnapshotWorkflow({
|
||||
machineId,
|
||||
snapshotId,
|
||||
|
||||
@@ -1,10 +1,68 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
createMachineSessionLoadFieldState,
|
||||
loadMachineSessionIntoWasmWorkflow,
|
||||
machineSessionLoadWorkflowLogLines,
|
||||
restoreMachineSessionSnapshotWorkflow,
|
||||
saveMachineSessionSnapshotWorkflow,
|
||||
} from "../../../runtime/ui/ini-panel/session-workflow.js";
|
||||
|
||||
const loadedSessionFixture = {
|
||||
ini: {
|
||||
opfsPath: "linuxcnc/machines/xyzab-tdr/machine.ini",
|
||||
wasmPath: "/work/session-machine.ini",
|
||||
},
|
||||
parameters: {
|
||||
opfsPath: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
|
||||
wasmPath: "/work/session-linuxcnc.var",
|
||||
result: "restore_parameters=0",
|
||||
},
|
||||
toolTable: {
|
||||
opfsPath: "linuxcnc/machines/xyzab-tdr/tool.tbl",
|
||||
wasmPath: "/work/session-tool.tbl",
|
||||
result: "tooldata_load=0",
|
||||
},
|
||||
};
|
||||
|
||||
const loadWorkflowCalls = [];
|
||||
const loadWorkflow = await loadMachineSessionIntoWasmWorkflow({
|
||||
loadSession: async () => {
|
||||
loadWorkflowCalls.push(["loadSession"]);
|
||||
return loadedSessionFixture;
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(loadWorkflowCalls, [["loadSession"]]);
|
||||
assert.deepEqual(loadWorkflow.loadSummary, {
|
||||
iniOpfsPath: "linuxcnc/machines/xyzab-tdr/machine.ini",
|
||||
iniWasmPath: "/work/session-machine.ini",
|
||||
parameterOpfsPath: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
|
||||
parameterWasmPath: "/work/session-linuxcnc.var",
|
||||
parameterResult: "restore_parameters=0",
|
||||
toolTableOpfsPath: "linuxcnc/machines/xyzab-tdr/tool.tbl",
|
||||
toolTableWasmPath: "/work/session-tool.tbl",
|
||||
toolTableResult: "tooldata_load=0",
|
||||
});
|
||||
assert.deepEqual(loadWorkflow.fields, {
|
||||
sessionIni: "/work/session-machine.ini",
|
||||
sessionParameters: "/work/session-linuxcnc.var",
|
||||
sessionToolTable: "/work/session-tool.tbl",
|
||||
});
|
||||
assert.deepEqual(createMachineSessionLoadFieldState(loadWorkflow.loadSummary), loadWorkflow.fields);
|
||||
assert.deepEqual(machineSessionLoadWorkflowLogLines(loadWorkflow.loadSummary), [
|
||||
"Loaded machine session into the interpreter WASM filesystem.",
|
||||
"INI: linuxcnc/machines/xyzab-tdr/machine.ini -> /work/session-machine.ini",
|
||||
"Parameter file: linuxcnc/machines/xyzab-tdr/linuxcnc.var -> /work/session-linuxcnc.var",
|
||||
"Parameters: restore_parameters=0",
|
||||
"Tool table file: linuxcnc/machines/xyzab-tdr/tool.tbl -> /work/session-tool.tbl",
|
||||
"Tool table: tooldata_load=0",
|
||||
]);
|
||||
await assert.rejects(
|
||||
() => loadMachineSessionIntoWasmWorkflow({}),
|
||||
/machine session loader/,
|
||||
);
|
||||
|
||||
const calls = [];
|
||||
const saveWorkflow = await saveMachineSessionSnapshotWorkflow({
|
||||
machineId: "xyzab-tdr",
|
||||
@@ -199,22 +257,7 @@ const restoreLoadWorkflow = await restoreMachineSessionSnapshotWorkflow({
|
||||
},
|
||||
loadSession: async () => {
|
||||
restoreLoadCalls.push(["loadSession"]);
|
||||
return {
|
||||
ini: {
|
||||
opfsPath: "linuxcnc/machines/xyzab-tdr/machine.ini",
|
||||
wasmPath: "/work/session-machine.ini",
|
||||
},
|
||||
parameters: {
|
||||
opfsPath: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
|
||||
wasmPath: "/work/session-linuxcnc.var",
|
||||
result: "restore_parameters=0",
|
||||
},
|
||||
toolTable: {
|
||||
opfsPath: "linuxcnc/machines/xyzab-tdr/tool.tbl",
|
||||
wasmPath: "/work/session-tool.tbl",
|
||||
result: "tooldata_load=0",
|
||||
},
|
||||
};
|
||||
return loadedSessionFixture;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user