推进 INI 面板 readonly status API

This commit is contained in:
2026-06-15 05:40:41 +08:00
parent deb8b7cdd3
commit 3280f3a53e
11 changed files with 302 additions and 1 deletions

View File

@@ -15,6 +15,8 @@ import {
getIniPanelEntryByHref,
getVisibleIniPanelEntries,
createMachineSessionControlPageController,
createMachineSessionReadonlyStatus,
readMachineSessionReadonlyStatus,
loadMachineSessionForControlPageWorkflow,
createControlPageSessionLoadState,
refreshMachineSessionControlPage,
@@ -24,7 +26,8 @@ import {
```
`ui-shell.js` re-exports the entry manifest, the read-only control-page
controller, and the control-view renderer. It does not implement CNC behavior.
controller, the unified read-only status API, and the control-view renderer. It
does not implement CNC behavior.
## Pages
@@ -50,6 +53,9 @@ and `label`.
Outer shells can call `createIniPanelShellViewModel()` when they need one
read-only model with `pages`, `launcherLinks`, and `controlPage` helpers for
mounting the existing control-page controller, refresh workflow, and renderer.
Use `controlPage.readStatus` or `readMachineSessionReadonlyStatus()` when an
outer shell needs one stable read of `stateBundle`, `workflowStatus`,
`overview`, `controlView`, `session`, `runReadiness`, and `run`.
The control-page refresh workflow lives in
`runtime/ui/ini-panel/control-page-refresh-workflow.js`. Use

View File

@@ -4,6 +4,9 @@ import {
import {
loadMachineSessionForControlPageWorkflow,
} from "./control-page-session-workflow.js";
import {
readMachineSessionReadonlyStatus,
} from "./readonly-status-api.js";
export function createMachineSessionControlPageController({
panelFrame,
@@ -61,6 +64,13 @@ export function createMachineSessionControlPageController({
});
}
function readStatus() {
return readMachineSessionReadonlyStatus({
getPanelApi,
getControlView,
});
}
function startPolling() {
if (!refreshTimer) {
refreshTimer = setIntervalFn(render, pollMs);
@@ -85,6 +95,7 @@ export function createMachineSessionControlPageController({
getPanelWindow,
loadSessionState,
mount,
readStatus,
refresh,
render,
startPolling,

View File

@@ -0,0 +1,41 @@
export function createMachineSessionReadonlyStatus({
stateBundle = null,
workflowStatus = null,
controlView = null,
} = {}) {
const overview = stateBundle?.overview ?? workflowStatus?.overview ?? null;
return {
stateBundle,
workflowStatus,
overview,
controlView,
report: stateBundle?.report ?? null,
runReadiness: workflowStatus?.runReadiness ?? stateBundle?.report?.runReadiness ?? null,
run: workflowStatus?.run ?? stateBundle?.report?.run ?? null,
session: workflowStatus?.session ?? stateBundle?.report?.session ?? null,
status: {
lastAction: workflowStatus?.lastAction ?? overview?.status?.lastAction ?? null,
error: workflowStatus?.error ?? overview?.status?.error ?? null,
runStatus: workflowStatus?.run?.status ?? stateBundle?.report?.run?.status ?? null,
},
};
}
export function readMachineSessionReadonlyStatus({ getPanelApi, getControlView } = {}) {
if (typeof getPanelApi !== "function") {
throw new Error("A panel API getter is required.");
}
if (typeof getControlView !== "function") {
throw new Error("A control view getter is required.");
}
const panelApi = getPanelApi();
if (!panelApi) {
return createMachineSessionReadonlyStatus();
}
return createMachineSessionReadonlyStatus({
stateBundle: panelApi.getMachineSessionStateBundle?.() ?? null,
workflowStatus: panelApi.getMachineSessionWorkflowStatus?.() ?? null,
controlView: getControlView(),
});
}

View File

@@ -18,6 +18,10 @@ import {
createControlPageSessionLoadState,
loadMachineSessionForControlPageWorkflow,
} from "./control-page-session-workflow.js";
import {
createMachineSessionReadonlyStatus,
readMachineSessionReadonlyStatus,
} from "./readonly-status-api.js";
export {
controlPageStatusText,
createControlPageRefreshState,
@@ -27,6 +31,10 @@ export {
createControlPageSessionLoadState,
loadMachineSessionForControlPageWorkflow,
} from "./control-page-session-workflow.js";
export {
createMachineSessionReadonlyStatus,
readMachineSessionReadonlyStatus,
} from "./readonly-status-api.js";
export {
INI_PANEL_ENTRIES,
getIniPanelEntryByHref,
@@ -62,6 +70,7 @@ export function createIniPanelShellViewModel(entries = getVisibleIniPanelEntries
controlPage: {
createController: createMachineSessionControlPageController,
loadSessionState: loadMachineSessionForControlPageWorkflow,
readStatus: readMachineSessionReadonlyStatus,
refresh: refreshMachineSessionControlPage,
renderView: renderMachineSessionControlView,
},

View File

@@ -87,6 +87,21 @@ panelFrame.contentWindow = { linuxCncIniPanelApi: panelApi };
assert.equal(controller.getPanelApi(), panelApi);
assert.equal(controller.getControlView(), expectedView);
assert.deepEqual(controller.readStatus(), {
stateBundle: expectedStateBundle,
workflowStatus: expectedWorkflowStatus,
overview: null,
controlView: expectedView,
report: expectedStateBundle.report,
runReadiness: null,
run: null,
session: null,
status: {
lastAction: "run-gcode",
error: null,
runStatus: null,
},
});
assert.deepEqual(controller.loadSessionState(), {
phase: "ready",
panelReady: true,

View File

@@ -9,7 +9,9 @@ import {
createControlPageSessionLoadState,
createIniPanelLauncherLinkViewModel,
createIniPanelShellViewModel,
createMachineSessionReadonlyStatus,
loadMachineSessionForControlPageWorkflow,
readMachineSessionReadonlyStatus,
refreshMachineSessionControlPage,
getVisibleIniPanelEntries,
} from "../../../runtime/ui/ini-panel/ui-shell.js";
@@ -36,7 +38,9 @@ const requiredShellExports = [
"getIniPanelEntryByHref",
"getVisibleIniPanelEntries",
"createMachineSessionControlPageController",
"createMachineSessionReadonlyStatus",
"loadMachineSessionForControlPageWorkflow",
"readMachineSessionReadonlyStatus",
"refreshMachineSessionControlPage",
"renderMachineSessionControlView",
];
@@ -96,7 +100,9 @@ assert.deepEqual(createControlPageSessionLoadState({ phase: "waiting-panel" }),
error: null,
});
assert.equal(typeof createIniPanelShellViewModel().controlPage.createController, "function");
assert.equal(typeof createMachineSessionReadonlyStatus, "function");
assert.equal(createIniPanelShellViewModel().controlPage.loadSessionState, loadMachineSessionForControlPageWorkflow);
assert.equal(createIniPanelShellViewModel().controlPage.readStatus, readMachineSessionReadonlyStatus);
assert.equal(createIniPanelShellViewModel().controlPage.refresh, refreshMachineSessionControlPage);
assert.equal(typeof createIniPanelShellViewModel().controlPage.renderView, "function");

View File

@@ -0,0 +1,116 @@
import assert from "node:assert/strict";
import {
createMachineSessionReadonlyStatus,
readMachineSessionReadonlyStatus,
} from "../../../runtime/ui/ini-panel/readonly-status-api.js";
const stateBundle = {
overview: {
phase: "ran",
status: {
lastAction: "run-gcode",
error: null,
},
},
report: {
session: {
snapshotLabel: "ui-machine-session/ui-machine-session.json",
},
runReadiness: {
phase: "ready",
canRun: true,
},
run: {
status: "ok",
canonicalEventCount: 2,
},
},
};
const workflowStatus = {
overview: stateBundle.overview,
runReadiness: stateBundle.report.runReadiness,
session: stateBundle.report.session,
run: stateBundle.report.run,
lastAction: "run-gcode",
error: null,
};
const controlView = {
status: {
lastAction: "run-gcode",
runStatus: "ok",
error: null,
},
};
assert.deepEqual(
createMachineSessionReadonlyStatus({
stateBundle,
workflowStatus,
controlView,
}),
{
stateBundle,
workflowStatus,
overview: stateBundle.overview,
controlView,
report: stateBundle.report,
runReadiness: stateBundle.report.runReadiness,
run: stateBundle.report.run,
session: stateBundle.report.session,
status: {
lastAction: "run-gcode",
error: null,
runStatus: "ok",
},
},
);
assert.deepEqual(createMachineSessionReadonlyStatus(), {
stateBundle: null,
workflowStatus: null,
overview: null,
controlView: null,
report: null,
runReadiness: null,
run: null,
session: null,
status: {
lastAction: null,
error: null,
runStatus: null,
},
});
const panelApi = {
getMachineSessionStateBundle: () => stateBundle,
getMachineSessionWorkflowStatus: () => workflowStatus,
};
assert.deepEqual(
readMachineSessionReadonlyStatus({
getPanelApi: () => panelApi,
getControlView: () => controlView,
}),
createMachineSessionReadonlyStatus({
stateBundle,
workflowStatus,
controlView,
}),
);
assert.deepEqual(
readMachineSessionReadonlyStatus({
getPanelApi: () => null,
getControlView: () => null,
}),
createMachineSessionReadonlyStatus(),
);
assert.throws(
() => readMachineSessionReadonlyStatus({ getControlView: () => null }),
/panel API getter/,
);
assert.throws(
() => readMachineSessionReadonlyStatus({ getPanelApi: () => panelApi }),
/control view getter/,
);
console.log("ini_panel_readonly_status_api_node_smoke=ok");

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
node "$ROOT_DIR/tests/ui/node/verify_ini_panel_readonly_status_api.mjs"

View File

@@ -5,6 +5,7 @@ import {
controlPageStatusText,
createIniPanelLauncherLinkViewModel,
createIniPanelShellViewModel,
createMachineSessionReadonlyStatus,
createControlPageRefreshState,
createControlPageSessionLoadState,
createMachineSessionControlPageController,
@@ -12,6 +13,7 @@ import {
getIniPanelEntryManifest,
getVisibleIniPanelEntries,
loadMachineSessionForControlPageWorkflow,
readMachineSessionReadonlyStatus,
refreshMachineSessionControlPage,
renderMachineSessionControlView,
} from "../../../runtime/ui/ini-panel/ui-shell.js";
@@ -38,7 +40,9 @@ assert.deepEqual(createControlPageSessionLoadState({ phase: "waiting-panel" }),
});
assert.equal(getIniPanelEntryByHref("./index.html")?.id, "edit-run");
assert.equal(typeof createMachineSessionControlPageController, "function");
assert.equal(typeof createMachineSessionReadonlyStatus, "function");
assert.equal(typeof loadMachineSessionForControlPageWorkflow, "function");
assert.equal(typeof readMachineSessionReadonlyStatus, "function");
assert.equal(typeof refreshMachineSessionControlPage, "function");
assert.equal(typeof renderMachineSessionControlView, "function");
@@ -79,6 +83,7 @@ assert.deepEqual(shellViewModel.pages, [
assert.deepEqual(shellViewModel.launcherLinks, createIniPanelLauncherLinkViewModel());
assert.equal(shellViewModel.controlPage.createController, createMachineSessionControlPageController);
assert.equal(shellViewModel.controlPage.loadSessionState, loadMachineSessionForControlPageWorkflow);
assert.equal(shellViewModel.controlPage.readStatus, readMachineSessionReadonlyStatus);
assert.equal(shellViewModel.controlPage.refresh, refreshMachineSessionControlPage);
assert.equal(shellViewModel.controlPage.renderView, renderMachineSessionControlView);
shellViewModel.pages[0].title = "changed";
@@ -96,6 +101,18 @@ const panelFrame = {
},
sections: [],
}),
getMachineSessionStateBundle: () => ({
overview: {
phase: "ran",
},
}),
getMachineSessionWorkflowStatus: () => ({
overview: {
phase: "ran",
},
lastAction: "run-gcode",
error: null,
}),
},
},
addEventListener() {},
@@ -116,6 +133,7 @@ const controller = createMachineSessionControlPageController({
assert.deepEqual(controller.render(), { rendered: true });
assert.equal(statusNode.textContent, "run-gcode | ok | -");
assert.equal(renderedView.status.runStatus, "ok");
assert.equal(controller.readStatus().overview.phase, "ran");
assert.equal(controller.loadSessionState().phase, "ready");
assert.equal(controller.refresh().phase, "rendered");

View File

@@ -12,6 +12,7 @@ ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_control_page_controller.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_control_page_refresh_workflow.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_control_page_session_workflow.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_readonly_status_api.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_entry_manifest.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_ui_shell.sh"
"$ROOT_DIR/tests/ui/node/verify_ini_panel_entry_docs.sh"