推进 INI 面板 workflow status helper
This commit is contained in:
@@ -18,6 +18,10 @@ directly. The legacy `window.getMachineSessionStateReport()` and
|
||||
`window.getMachineSessionStateReportExport()` globals remain as compatibility
|
||||
shims.
|
||||
|
||||
For control-page polling, use
|
||||
`window.linuxCncIniPanelApi.getMachineSessionWorkflowStatus()`. It returns a
|
||||
smaller workflow-facing object derived from the same report data.
|
||||
|
||||
## `createIniPanelStateSummary(input)`
|
||||
|
||||
`input` may contain:
|
||||
@@ -103,6 +107,23 @@ This helper wraps the report in a stable export payload:
|
||||
|
||||
It is a small export-layer helper for future copy/download/UI SDK wrappers.
|
||||
|
||||
## `createMachineSessionWorkflowStatus(state)`
|
||||
|
||||
This helper derives a lightweight status object for upper-level control pages:
|
||||
|
||||
```js
|
||||
{
|
||||
readiness: { ini: "...", interp: "...", opfs: "..." },
|
||||
lastAction: "run-gcode",
|
||||
error: null,
|
||||
session: { snapshotLabel: "...", workflow: "...", gcode: "..." },
|
||||
run: { status: "ok", canonicalEventCount: 2, motionSnapshotCount: 2, iniWasmPath: "..." }
|
||||
}
|
||||
```
|
||||
|
||||
It is intended for polling or status panels that need current UI workflow
|
||||
state without parsing logs, DOM nodes, or transient window state.
|
||||
|
||||
## Boundary Rules
|
||||
|
||||
- Do not parse G-code text in this helper.
|
||||
|
||||
@@ -49,6 +49,7 @@ import {
|
||||
createMachineSessionStateSnapshot,
|
||||
createMachineSessionStateReport,
|
||||
createMachineSessionStateReportExport,
|
||||
createMachineSessionWorkflowStatus,
|
||||
} from "./panel-state-summary.js";
|
||||
|
||||
const SAMPLE_PATH =
|
||||
@@ -161,6 +162,10 @@ function getMachineSessionStateReportExport() {
|
||||
return createMachineSessionStateReportExport(window.linuxCncIniPanelMachineSessionState);
|
||||
}
|
||||
|
||||
function getMachineSessionWorkflowStatus() {
|
||||
return createMachineSessionWorkflowStatus(window.linuxCncIniPanelMachineSessionState);
|
||||
}
|
||||
|
||||
function updatePanelMachineSessionState(patch = {}) {
|
||||
panelMachineSessionState = createMachineSessionStateSnapshot({
|
||||
...panelMachineSessionState,
|
||||
@@ -177,9 +182,11 @@ function updatePanelMachineSessionState(patch = {}) {
|
||||
window.linuxCncIniPanelApi = {
|
||||
getMachineSessionStateReport,
|
||||
getMachineSessionStateReportExport,
|
||||
getMachineSessionWorkflowStatus,
|
||||
};
|
||||
window.getMachineSessionStateReport = getMachineSessionStateReport;
|
||||
window.getMachineSessionStateReportExport = getMachineSessionStateReportExport;
|
||||
window.getMachineSessionWorkflowStatus = getMachineSessionWorkflowStatus;
|
||||
window.linuxCncIniPanelMachineSessionState = panelMachineSessionState;
|
||||
|
||||
function setBadge(node, text, className = "badge") {
|
||||
|
||||
@@ -118,3 +118,14 @@ export function createMachineSessionStateReportExport(state = {}, options = {})
|
||||
text: `${JSON.stringify(report, null, 2)}\n`,
|
||||
};
|
||||
}
|
||||
|
||||
export function createMachineSessionWorkflowStatus(state = {}) {
|
||||
const report = createMachineSessionStateReport(state);
|
||||
return {
|
||||
readiness: report.readiness,
|
||||
lastAction: report.status.lastAction,
|
||||
error: report.status.error,
|
||||
session: report.session,
|
||||
run: report.run,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -368,8 +368,12 @@ TOOL_TABLE = browser-tool.tbl
|
||||
"INI panel OPFS readiness",
|
||||
);
|
||||
const uiApi = uiDocument.defaultView.linuxCncIniPanelApi;
|
||||
if (!uiApi?.getMachineSessionStateReport || !uiApi?.getMachineSessionStateReportExport) {
|
||||
throw new Error("INI panel API namespace did not expose state report getters");
|
||||
if (
|
||||
!uiApi?.getMachineSessionStateReport ||
|
||||
!uiApi?.getMachineSessionStateReportExport ||
|
||||
!uiApi?.getMachineSessionWorkflowStatus
|
||||
) {
|
||||
throw new Error("INI panel API namespace did not expose state getters");
|
||||
}
|
||||
|
||||
uiDocument.getElementById("ini-editor").value = iniText;
|
||||
@@ -773,6 +777,37 @@ TOOL_TABLE = browser-tool.tbl
|
||||
"snapshot",
|
||||
"UI machine session state report export program source",
|
||||
);
|
||||
const machineSessionWorkflowStatus = uiApi.getMachineSessionWorkflowStatus();
|
||||
assertEqual(
|
||||
machineSessionWorkflowStatus.lastAction,
|
||||
"run-gcode",
|
||||
"UI machine session workflow status last action",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionWorkflowStatus.error,
|
||||
null,
|
||||
"UI machine session workflow status error",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionWorkflowStatus.readiness.opfs,
|
||||
"OPFS: ready",
|
||||
"UI machine session workflow status OPFS readiness",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionWorkflowStatus.session.workflow,
|
||||
"save-session-snapshot",
|
||||
"UI machine session workflow status session workflow",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionWorkflowStatus.run.status,
|
||||
"ok",
|
||||
"UI machine session workflow status run status",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionWorkflowStatus.run.canonicalEventCount,
|
||||
2,
|
||||
"UI machine session workflow status canonical event count",
|
||||
);
|
||||
assertEqual(
|
||||
uiDocument.defaultView.getMachineSessionStateReport().status.lastAction,
|
||||
machineSessionStateReport.status.lastAction,
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
createMachineSessionStateSnapshot,
|
||||
createMachineSessionStateReport,
|
||||
createMachineSessionStateReportExport,
|
||||
createMachineSessionWorkflowStatus,
|
||||
} from "../../../runtime/ui/ini-panel/panel-state-summary.js";
|
||||
|
||||
const summary = createIniPanelStateSummary({
|
||||
@@ -330,14 +331,63 @@ assert.deepEqual(
|
||||
},
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
createMachineSessionWorkflowStatus({
|
||||
badges: {
|
||||
ini: "INI WASM: ready",
|
||||
interp: "Interpreter WASM: ready",
|
||||
opfs: "OPFS: ready",
|
||||
},
|
||||
fields: {
|
||||
sessionSnapshot: "ui-machine-session/ui-machine-session.json",
|
||||
sessionIni: "/work/session-machine.ini",
|
||||
sessionGcode: "linuxcnc/gcode/ui-session.ngc",
|
||||
runStatus: "ok",
|
||||
runWorkflow: "save-session-snapshot",
|
||||
},
|
||||
run: {
|
||||
runStatus: "ok",
|
||||
canonicalEventCount: 2,
|
||||
motionSnapshotCount: 2,
|
||||
},
|
||||
lastAction: "run-gcode",
|
||||
error: null,
|
||||
}),
|
||||
{
|
||||
readiness: {
|
||||
ini: "INI WASM: ready",
|
||||
interp: "Interpreter WASM: ready",
|
||||
opfs: "OPFS: ready",
|
||||
},
|
||||
lastAction: "run-gcode",
|
||||
error: null,
|
||||
session: {
|
||||
snapshotLabel: "ui-machine-session/ui-machine-session.json",
|
||||
workflow: "save-session-snapshot",
|
||||
ini: "/work/session-machine.ini",
|
||||
parameters: null,
|
||||
toolTable: null,
|
||||
gcode: "linuxcnc/gcode/ui-session.ngc",
|
||||
},
|
||||
run: {
|
||||
status: "ok",
|
||||
canonicalEventCount: 2,
|
||||
motionSnapshotCount: 2,
|
||||
iniWasmPath: null,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
{
|
||||
getMachineSessionStateReport: typeof globalThis.window?.linuxCncIniPanelApi?.getMachineSessionStateReport,
|
||||
getMachineSessionStateReportExport: typeof globalThis.window?.linuxCncIniPanelApi?.getMachineSessionStateReportExport,
|
||||
getMachineSessionWorkflowStatus: typeof globalThis.window?.linuxCncIniPanelApi?.getMachineSessionWorkflowStatus,
|
||||
},
|
||||
{
|
||||
getMachineSessionStateReport: "undefined",
|
||||
getMachineSessionStateReportExport: "undefined",
|
||||
getMachineSessionWorkflowStatus: "undefined",
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user