推进 INI 面板状态 report JSON 导出 helper
This commit is contained in:
@@ -85,6 +85,21 @@ with four sections:
|
||||
The report is intended for upper-level UI consumers or export paths that want a
|
||||
stable summary shape without touching DOM nodes.
|
||||
|
||||
## `createMachineSessionStateReportExport(state, options)`
|
||||
|
||||
This helper wraps the report in a stable export payload:
|
||||
|
||||
```js
|
||||
{
|
||||
filename: "machine-session-state-report.json",
|
||||
mediaType: "application/json",
|
||||
report: { ... },
|
||||
text: "{\n ...\n}\n"
|
||||
}
|
||||
```
|
||||
|
||||
It is a small export-layer helper for future copy/download/UI SDK wrappers.
|
||||
|
||||
## Boundary Rules
|
||||
|
||||
- Do not parse G-code text in this helper.
|
||||
|
||||
@@ -48,6 +48,7 @@ import {
|
||||
import {
|
||||
createMachineSessionStateSnapshot,
|
||||
createMachineSessionStateReport,
|
||||
createMachineSessionStateReportExport,
|
||||
} from "./panel-state-summary.js";
|
||||
|
||||
const SAMPLE_PATH =
|
||||
@@ -156,6 +157,10 @@ function getMachineSessionStateReport() {
|
||||
return createMachineSessionStateReport(window.linuxCncIniPanelMachineSessionState);
|
||||
}
|
||||
|
||||
function getMachineSessionStateReportExport() {
|
||||
return createMachineSessionStateReportExport(window.linuxCncIniPanelMachineSessionState);
|
||||
}
|
||||
|
||||
function updatePanelMachineSessionState(patch = {}) {
|
||||
panelMachineSessionState = createMachineSessionStateSnapshot({
|
||||
...panelMachineSessionState,
|
||||
@@ -170,6 +175,7 @@ function updatePanelMachineSessionState(patch = {}) {
|
||||
}
|
||||
|
||||
window.getMachineSessionStateReport = getMachineSessionStateReport;
|
||||
window.getMachineSessionStateReportExport = getMachineSessionStateReportExport;
|
||||
window.linuxCncIniPanelMachineSessionState = panelMachineSessionState;
|
||||
|
||||
function setBadge(node, text, className = "badge") {
|
||||
|
||||
@@ -108,3 +108,13 @@ export function createMachineSessionStateReport(state = {}) {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function createMachineSessionStateReportExport(state = {}, options = {}) {
|
||||
const report = createMachineSessionStateReport(state);
|
||||
return {
|
||||
filename: options.filename ?? "machine-session-state-report.json",
|
||||
mediaType: "application/json",
|
||||
report,
|
||||
text: `${JSON.stringify(report, null, 2)}\n`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -743,6 +743,32 @@ TOOL_TABLE = browser-tool.tbl
|
||||
2,
|
||||
"UI machine session state report motion snapshot count",
|
||||
);
|
||||
const machineSessionStateReportExport = uiDocument.defaultView.getMachineSessionStateReportExport();
|
||||
assertEqual(
|
||||
machineSessionStateReportExport.filename,
|
||||
"machine-session-state-report.json",
|
||||
"UI machine session state report export filename",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionStateReportExport.mediaType,
|
||||
"application/json",
|
||||
"UI machine session state report export media type",
|
||||
);
|
||||
assertEqual(
|
||||
machineSessionStateReportExport.text.endsWith("\n"),
|
||||
true,
|
||||
"UI machine session state report export newline",
|
||||
);
|
||||
assertEqual(
|
||||
JSON.parse(machineSessionStateReportExport.text).run.canonicalEventCount,
|
||||
2,
|
||||
"UI machine session state report export canonical event count",
|
||||
);
|
||||
assertEqual(
|
||||
JSON.parse(machineSessionStateReportExport.text).program.source,
|
||||
"snapshot",
|
||||
"UI machine session state report export program source",
|
||||
);
|
||||
if (
|
||||
!runLog.includes("canon_event=STRAIGHT_TRAVERSE") ||
|
||||
!runLog.includes("canon_event=STRAIGHT_FEED")
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
createIniPanelStateSummary,
|
||||
createMachineSessionStateSnapshot,
|
||||
createMachineSessionStateReport,
|
||||
createMachineSessionStateReportExport,
|
||||
} from "../../../runtime/ui/ini-panel/panel-state-summary.js";
|
||||
|
||||
const summary = createIniPanelStateSummary({
|
||||
@@ -268,4 +269,65 @@ assert.deepEqual(
|
||||
},
|
||||
);
|
||||
|
||||
const expectedExportReport = {
|
||||
readiness: {
|
||||
ini: "INI WASM: ready",
|
||||
interp: "Interpreter WASM: ready",
|
||||
opfs: "OPFS: ready",
|
||||
},
|
||||
session: {
|
||||
snapshotLabel: "ui-machine-session/ui-machine-session.json",
|
||||
workflow: null,
|
||||
ini: "/work/session-machine.ini",
|
||||
parameters: null,
|
||||
toolTable: null,
|
||||
gcode: null,
|
||||
},
|
||||
loaded: {
|
||||
iniWasmPath: "/work/session-machine.ini",
|
||||
parameterWasmPath: null,
|
||||
toolTableWasmPath: null,
|
||||
},
|
||||
program: {
|
||||
source: null,
|
||||
opfsPath: null,
|
||||
wasmPath: null,
|
||||
},
|
||||
run: {
|
||||
status: null,
|
||||
canonicalEventCount: 0,
|
||||
motionSnapshotCount: 0,
|
||||
iniWasmPath: null,
|
||||
},
|
||||
status: {
|
||||
lastAction: "save-session-snapshot",
|
||||
error: null,
|
||||
fiveaxisRemap: null,
|
||||
},
|
||||
};
|
||||
|
||||
assert.deepEqual(
|
||||
createMachineSessionStateReportExport({
|
||||
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",
|
||||
},
|
||||
sessionLoad: {
|
||||
iniWasmPath: "/work/session-machine.ini",
|
||||
},
|
||||
lastAction: "save-session-snapshot",
|
||||
}),
|
||||
{
|
||||
filename: "machine-session-state-report.json",
|
||||
mediaType: "application/json",
|
||||
report: expectedExportReport,
|
||||
text: `${JSON.stringify(expectedExportReport, null, 2)}\n`,
|
||||
},
|
||||
);
|
||||
|
||||
console.log("ini_panel_state_summary_node_smoke=ok");
|
||||
|
||||
Reference in New Issue
Block a user