推进 INI 面板 control view DOM consumer

This commit is contained in:
2026-06-14 22:45:45 +08:00
parent 4133d202f0
commit 74617cc3fa
3 changed files with 120 additions and 0 deletions

View File

@@ -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,