推进 INI 面板 control view DOM consumer
This commit is contained in:
@@ -161,6 +161,18 @@ This helper maps a bundle into UI-ready status and sections:
|
||||
It is a presentation mapping over the bundle only. It does not parse G-code,
|
||||
canonical events, or LinuxCNC-owned runtime content.
|
||||
|
||||
A minimal read-only browser consumer can render the sections directly:
|
||||
|
||||
```js
|
||||
const view = window.linuxCncIniPanelApi.getMachineSessionControlView();
|
||||
for (const section of view.sections) {
|
||||
renderSection(section.title, section.rows);
|
||||
}
|
||||
```
|
||||
|
||||
Consumers should treat `rows` as display data and keep actions wired through
|
||||
explicit workflow APIs instead of deriving behavior from labels.
|
||||
|
||||
## Boundary Rules
|
||||
|
||||
- Do not parse G-code text in this helper.
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
</head>
|
||||
<body>
|
||||
<pre id="status">running</pre>
|
||||
<div id="control-view">
|
||||
<div id="control-status"></div>
|
||||
<div id="control-sections"></div>
|
||||
</div>
|
||||
<script type="module">
|
||||
import { createLinuxCncIniSdk } from "../../runtime/sdk/src/index.js";
|
||||
import { loadTextFile, saveTextFile } from "../../runtime/opfs/file-service.js";
|
||||
@@ -76,6 +80,34 @@
|
||||
return frame.contentDocument;
|
||||
}
|
||||
|
||||
function renderControlView(containerDocument, view) {
|
||||
const statusNode = containerDocument.getElementById("control-status");
|
||||
const sectionsNode = containerDocument.getElementById("control-sections");
|
||||
statusNode.textContent = [
|
||||
view.status.lastAction ?? "-",
|
||||
view.status.runStatus ?? "-",
|
||||
view.status.error ?? "-",
|
||||
].join(" | ");
|
||||
sectionsNode.textContent = "";
|
||||
for (const section of view.sections) {
|
||||
const sectionNode = containerDocument.createElement("section");
|
||||
sectionNode.dataset.sectionId = section.id;
|
||||
const heading = containerDocument.createElement("h2");
|
||||
heading.textContent = section.title;
|
||||
sectionNode.appendChild(heading);
|
||||
const list = containerDocument.createElement("dl");
|
||||
for (const row of section.rows) {
|
||||
const term = containerDocument.createElement("dt");
|
||||
term.textContent = row.label;
|
||||
const def = containerDocument.createElement("dd");
|
||||
def.textContent = String(row.value ?? "-");
|
||||
list.append(term, def);
|
||||
}
|
||||
sectionNode.appendChild(list);
|
||||
sectionsNode.appendChild(sectionNode);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const ini = await createLinuxCncIniSdk();
|
||||
const wasmPath = "/work/browser-smoke.ini";
|
||||
@@ -832,6 +864,7 @@ TOOL_TABLE = browser-tool.tbl
|
||||
"UI legacy machine session state bundle getter matches API namespace",
|
||||
);
|
||||
const machineSessionControlView = uiApi.getMachineSessionControlView();
|
||||
renderControlView(document, machineSessionControlView);
|
||||
assertEqual(
|
||||
machineSessionControlView.status.runStatus,
|
||||
"ok",
|
||||
@@ -852,6 +885,21 @@ TOOL_TABLE = browser-tool.tbl
|
||||
2,
|
||||
"UI machine session control view canonical event row",
|
||||
);
|
||||
assertEqual(
|
||||
document.getElementById("control-status").textContent,
|
||||
"run-gcode | ok | -",
|
||||
"UI machine session control view DOM status",
|
||||
);
|
||||
assertEqual(
|
||||
document.getElementById("control-sections").querySelectorAll("section").length,
|
||||
3,
|
||||
"UI machine session control view DOM section count",
|
||||
);
|
||||
assertEqual(
|
||||
document.getElementById("control-sections").querySelector('section[data-section-id=\"run\"] dd:nth-of-type(2)').textContent,
|
||||
"2",
|
||||
"UI machine session control view DOM canonical event row",
|
||||
);
|
||||
assertEqual(
|
||||
uiDocument.defaultView.getMachineSessionControlView().status.lastAction,
|
||||
machineSessionControlView.status.lastAction,
|
||||
|
||||
Reference in New Issue
Block a user