接入 INI panel session readiness workflow
This commit is contained in:
@@ -18,6 +18,9 @@ import {
|
||||
import {
|
||||
loadMachineSessionFromOpfs,
|
||||
} from "../../opfs/linuxcnc-machine-session-bridge.js";
|
||||
import {
|
||||
readMachineSessionReadiness,
|
||||
} from "../../opfs/machine-session-readiness.js";
|
||||
import {
|
||||
loadMachineSessionSnapshot,
|
||||
saveMachineSessionSnapshot,
|
||||
@@ -37,6 +40,7 @@ import {
|
||||
} from "./run-workflow.js";
|
||||
import {
|
||||
loadMachineSessionIntoWasmWorkflow,
|
||||
readMachineSessionReadinessWorkflow,
|
||||
restoreMachineSessionSnapshotWorkflow,
|
||||
saveMachineSessionSnapshotWorkflow,
|
||||
} from "./session-workflow.js";
|
||||
@@ -486,6 +490,14 @@ async function loadMachineSessionIntoWasm() {
|
||||
return loadedSession;
|
||||
}
|
||||
|
||||
function readCurrentMachineSessionReadiness() {
|
||||
return readMachineSessionReadiness(MACHINE_ID, {
|
||||
sessionId: UI_SESSION.snapshotId,
|
||||
snapshotFilename: UI_SESSION.snapshotFilename,
|
||||
gcodeFilename: UI_SESSION.defaultGcodeFilename,
|
||||
});
|
||||
}
|
||||
|
||||
async function loadSample() {
|
||||
setLog(`Fetching ${SAMPLE_PATH}`);
|
||||
const response = await fetch(SAMPLE_PATH);
|
||||
@@ -674,6 +686,7 @@ document.getElementById("restore-session-snapshot").addEventListener("click", as
|
||||
snapshotLabel: sessionSnapshotLabel(UI_SESSION),
|
||||
loadMachineSessionSnapshot,
|
||||
loadMachineTextFiles,
|
||||
readReadiness: readCurrentMachineSessionReadiness,
|
||||
});
|
||||
editor.value = workflow.editorIniText;
|
||||
setField("sessionIni", workflow.fields.sessionIni);
|
||||
@@ -684,6 +697,7 @@ document.getElementById("restore-session-snapshot").addEventListener("click", as
|
||||
restoredSessionSnapshot = workflow.snapshot;
|
||||
updatePanelMachineSessionState({
|
||||
sessionSnapshot: workflow.summary,
|
||||
sessionReadiness: workflow.readiness,
|
||||
sessionLoad: null,
|
||||
selectedProgram: null,
|
||||
fields: workflow.fields,
|
||||
@@ -707,17 +721,27 @@ document.getElementById("restore-session-snapshot").addEventListener("click", as
|
||||
|
||||
document.getElementById("load-session").addEventListener("click", async () => {
|
||||
try {
|
||||
const readinessWorkflow = await readMachineSessionReadinessWorkflow({
|
||||
readReadiness: readCurrentMachineSessionReadiness,
|
||||
});
|
||||
const workflow = await loadMachineSessionIntoWasmWorkflow({
|
||||
loadSession: () => loadMachineSessionIntoWasm(),
|
||||
});
|
||||
loadedSession = workflow.loadedSession;
|
||||
updatePanelMachineSessionState({
|
||||
sessionReadiness: readinessWorkflow.readiness,
|
||||
sessionLoad: workflow.loadSummary,
|
||||
fields: workflow.fields,
|
||||
fields: {
|
||||
...readinessWorkflow.fields,
|
||||
...workflow.fields,
|
||||
},
|
||||
lastAction: "load-session",
|
||||
error: null,
|
||||
});
|
||||
setLog(workflow.logLines.join("\n"));
|
||||
setLog([
|
||||
...readinessWorkflow.logLines,
|
||||
...workflow.logLines,
|
||||
].join("\n"));
|
||||
} catch (error) {
|
||||
updatePanelMachineSessionState({
|
||||
lastAction: "load-session",
|
||||
@@ -736,6 +760,7 @@ document.getElementById("restore-load-session").addEventListener("click", async
|
||||
snapshotLabel: sessionSnapshotLabel(UI_SESSION),
|
||||
loadMachineSessionSnapshot,
|
||||
loadMachineTextFiles,
|
||||
readReadiness: readCurrentMachineSessionReadiness,
|
||||
loadSession: () => loadMachineSessionIntoWasm(),
|
||||
});
|
||||
editor.value = workflow.editorIniText;
|
||||
@@ -750,6 +775,7 @@ document.getElementById("restore-load-session").addEventListener("click", async
|
||||
}
|
||||
updatePanelMachineSessionState({
|
||||
sessionSnapshot: workflow.summary,
|
||||
sessionReadiness: workflow.readiness,
|
||||
sessionLoad: workflow.loadSummary,
|
||||
selectedProgram: null,
|
||||
fields: workflow.fields,
|
||||
|
||||
@@ -52,6 +52,47 @@ export function machineSessionLoadWorkflowLogLines(summary) {
|
||||
];
|
||||
}
|
||||
|
||||
export function createMachineSessionReadinessFieldState(readiness) {
|
||||
return {
|
||||
sessionReadinessPhase: readiness.phase,
|
||||
sessionReadinessReady: readiness.ready ? "ready" : "blocked",
|
||||
sessionReadinessMissing: readiness.missing.length === 0 ? "none" : readiness.missing.join(", "),
|
||||
};
|
||||
}
|
||||
|
||||
export function machineSessionReadinessLogLines(readiness) {
|
||||
const checks = Array.isArray(readiness.checks) ? readiness.checks : [];
|
||||
return [
|
||||
`Session readiness: ${readiness.ready ? "ready" : "blocked"}`,
|
||||
...checks.map((check) => {
|
||||
const status = check.ok ? "ok" : `blocked (${check.error})`;
|
||||
return `${check.name}: ${check.path} -> ${status}`;
|
||||
}),
|
||||
...(readiness.snapshotCheck
|
||||
? [
|
||||
`snapshot: ${readiness.snapshotCheck.path} -> ${
|
||||
readiness.snapshotCheck.ok ? "ok" : `blocked (${readiness.snapshotCheck.error})`
|
||||
}`,
|
||||
]
|
||||
: []),
|
||||
];
|
||||
}
|
||||
|
||||
export async function readMachineSessionReadinessWorkflow({
|
||||
readiness,
|
||||
readReadiness,
|
||||
} = {}) {
|
||||
const sessionReadiness = readiness ?? await readReadiness?.();
|
||||
if (!sessionReadiness) {
|
||||
throw new Error("A machine session readiness reader is required.");
|
||||
}
|
||||
return {
|
||||
readiness: sessionReadiness,
|
||||
fields: createMachineSessionReadinessFieldState(sessionReadiness),
|
||||
logLines: machineSessionReadinessLogLines(sessionReadiness),
|
||||
};
|
||||
}
|
||||
|
||||
export async function loadMachineSessionIntoWasmWorkflow({ loadSession }) {
|
||||
if (typeof loadSession !== "function") {
|
||||
throw new Error("A machine session loader is required.");
|
||||
@@ -114,6 +155,7 @@ export async function restoreMachineSessionSnapshotWorkflow({
|
||||
snapshotLabel,
|
||||
loadMachineSessionSnapshot,
|
||||
loadMachineTextFiles,
|
||||
readReadiness = null,
|
||||
loadSession = null,
|
||||
}) {
|
||||
const snapshot = await loadMachineSessionSnapshot(
|
||||
@@ -129,21 +171,36 @@ export async function restoreMachineSessionSnapshotWorkflow({
|
||||
editorIniText: files.ini,
|
||||
summary,
|
||||
fields,
|
||||
readiness: null,
|
||||
loadSummary: null,
|
||||
loadedSession: null,
|
||||
logLines: sessionSnapshotRestoreLogLines(summary),
|
||||
};
|
||||
if (readReadiness) {
|
||||
const readinessWorkflow = await readMachineSessionReadinessWorkflow({ readReadiness });
|
||||
result.readiness = readinessWorkflow.readiness;
|
||||
result.fields = {
|
||||
...result.fields,
|
||||
...readinessWorkflow.fields,
|
||||
};
|
||||
result.logLines = [
|
||||
...result.logLines,
|
||||
...readinessWorkflow.logLines,
|
||||
];
|
||||
}
|
||||
if (loadSession) {
|
||||
const loadWorkflow = await loadMachineSessionIntoWasmWorkflow({ loadSession });
|
||||
result.loadedSession = loadWorkflow.loadedSession;
|
||||
result.loadSummary = loadWorkflow.loadSummary;
|
||||
result.fields = {
|
||||
...fields,
|
||||
...(result.readiness ? createMachineSessionReadinessFieldState(result.readiness) : {}),
|
||||
...loadWorkflow.fields,
|
||||
sessionGcode: summary.gcodeOpfsPath,
|
||||
};
|
||||
result.logLines = [
|
||||
...sessionSnapshotSummaryLogLines(summary),
|
||||
...(result.readiness ? machineSessionReadinessLogLines(result.readiness) : []),
|
||||
...loadWorkflow.logLines,
|
||||
`G-code: ${summary.gcodeOpfsPath ?? "-"}`,
|
||||
];
|
||||
|
||||
@@ -18,6 +18,11 @@ import {
|
||||
createControlPageSessionLoadState,
|
||||
loadMachineSessionForControlPageWorkflow,
|
||||
} from "./control-page-session-workflow.js";
|
||||
import {
|
||||
createMachineSessionReadinessFieldState,
|
||||
machineSessionReadinessLogLines,
|
||||
readMachineSessionReadinessWorkflow,
|
||||
} from "./session-workflow.js";
|
||||
import {
|
||||
createMachineSessionReadonlyStatus,
|
||||
createMachineSessionReadonlyStatusApiManifest,
|
||||
@@ -32,6 +37,11 @@ export {
|
||||
createControlPageSessionLoadState,
|
||||
loadMachineSessionForControlPageWorkflow,
|
||||
} from "./control-page-session-workflow.js";
|
||||
export {
|
||||
createMachineSessionReadinessFieldState,
|
||||
machineSessionReadinessLogLines,
|
||||
readMachineSessionReadinessWorkflow,
|
||||
} from "./session-workflow.js";
|
||||
export {
|
||||
createMachineSessionReadonlyStatus,
|
||||
createMachineSessionReadonlyStatusApiManifest,
|
||||
|
||||
Reference in New Issue
Block a user