some webUI fixes
This commit is contained in:
@@ -15,6 +15,12 @@ const btnStop = document.getElementById("btn-stop");
|
||||
const btnTmpRef = document.getElementById("btn-tmp-ref");
|
||||
const btnApply = document.getElementById("btn-apply");
|
||||
const btnResetHistory = document.getElementById("btn-reset-history");
|
||||
const btnLoadConfig = document.getElementById("btn-load-config");
|
||||
const configSelect = document.getElementById("config-select");
|
||||
const configActiveEl = document.getElementById("config-active");
|
||||
const savePathInput = document.getElementById("save-path");
|
||||
const saveNameInput = document.getElementById("save-name");
|
||||
const btnSaveDataset = document.getElementById("btn-save-dataset");
|
||||
|
||||
const settingsToggle = document.getElementById("settings-toggle");
|
||||
const sidePanel = document.querySelector(".side-panel");
|
||||
@@ -24,12 +30,15 @@ const settingsNote = document.getElementById("settings-note");
|
||||
const runningEl = document.getElementById("stat-running");
|
||||
const processorEl = document.getElementById("stat-processor");
|
||||
const ringEl = document.getElementById("stat-ring");
|
||||
const scansEl = document.getElementById("stat-scans");
|
||||
const staleEl = document.getElementById("stat-stale");
|
||||
const toastEl = document.getElementById("toast");
|
||||
|
||||
/* ---- state ------------------------------------------------------- */
|
||||
let pendingPng = null; // newest PNG (base64), shown on the next animation frame
|
||||
let lastFrameTs = 0; // performance.now() of the last received frame
|
||||
let pendingPng = null; // newest PNG (base64), shown on the next animation frame
|
||||
let lastFrameTs = 0; // performance.now() of the last received frame
|
||||
let pipelineRunning = false; // gates the config loader (loading requires a stopped pipeline)
|
||||
let saveFieldsPrefilled = false; // seed the save path/name fields once, then leave the operator's edits
|
||||
|
||||
/* ---- helpers ----------------------------------------------------- */
|
||||
function toast(message, isError) {
|
||||
@@ -245,6 +254,63 @@ async function loadSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- config profile --------------------------------------------- */
|
||||
// Loading a config does exactly what the desktop "Load Config" button does. The file
|
||||
// list comes from the server's run_configs/ directory (the browser has no file access),
|
||||
// and loading is gated to a stopped pipeline — mirroring the desktop precondition.
|
||||
function updateLoadButtonState() {
|
||||
btnLoadConfig.disabled = pipelineRunning || configSelect.options.length === 0;
|
||||
}
|
||||
|
||||
async function loadConfigList() {
|
||||
try {
|
||||
const { names = [] } = await api("/api/configs");
|
||||
const previous = configSelect.value;
|
||||
configSelect.innerHTML = "";
|
||||
for (const name of names) {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = name;
|
||||
opt.textContent = name;
|
||||
configSelect.appendChild(opt);
|
||||
}
|
||||
if (names.includes(previous)) configSelect.value = previous; // keep the operator's choice
|
||||
updateLoadButtonState();
|
||||
} catch (err) {
|
||||
toast("Could not load config list: " + err.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
btnLoadConfig.addEventListener("click", async () => {
|
||||
const name = configSelect.value;
|
||||
if (!name) return;
|
||||
btnLoadConfig.disabled = true;
|
||||
try {
|
||||
await api("/api/load_config", { name });
|
||||
toast(`Config loaded: ${name}`); // the new settings schema arrives via the live status push
|
||||
} catch (err) {
|
||||
toast(err.message, true);
|
||||
} finally {
|
||||
updateLoadButtonState();
|
||||
}
|
||||
});
|
||||
|
||||
/* ---- save dataset ----------------------------------------------- */
|
||||
// Saves to the path in the field, mirroring the desktop "Save Dataset" button exactly.
|
||||
btnSaveDataset.addEventListener("click", async () => {
|
||||
btnSaveDataset.disabled = true;
|
||||
try {
|
||||
await api("/api/save_dataset", {
|
||||
path: savePathInput.value.trim(),
|
||||
name: saveNameInput.value.trim(),
|
||||
});
|
||||
toast("Save requested"); // a radar-config prefix is prepended to the name server-side
|
||||
} catch (err) {
|
||||
toast(err.message, true);
|
||||
} finally {
|
||||
btnSaveDataset.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
/* ---- status ------------------------------------------------------ */
|
||||
function setStat(el, label, value, cls) {
|
||||
el.className = "stat" + (cls ? " " + cls : "");
|
||||
@@ -253,13 +319,26 @@ function setStat(el, label, value, cls) {
|
||||
}
|
||||
|
||||
function applyStatus(s) {
|
||||
if ("running" in s)
|
||||
if ("running" in s) {
|
||||
setStat(runningEl, "running", s.running ? "yes" : "no", s.running ? "ok" : "off");
|
||||
pipelineRunning = !!s.running;
|
||||
updateLoadButtonState();
|
||||
}
|
||||
if ("active_config" in s)
|
||||
configActiveEl.textContent = s.active_config ? `current: ${s.active_config}` : "";
|
||||
if ("save_path" in s && !saveFieldsPrefilled) {
|
||||
savePathInput.value = s.save_path || ""; // seed once; don't clobber later edits
|
||||
saveNameInput.value = s.save_name || "";
|
||||
saveFieldsPrefilled = true;
|
||||
}
|
||||
if ("processor_running" in s)
|
||||
setStat(processorEl, "processor", s.processor_running ? "yes" : "no",
|
||||
s.processor_running ? "ok" : "off");
|
||||
if ("ring_name" in s) setStat(ringEl, "ring", s.ring_name || "—",
|
||||
s.ring_name ? "" : "off");
|
||||
if ("raw_count" in s)
|
||||
setStat(scansEl, "scans",
|
||||
`raw ${s.raw_count} / preprocessed ${s.preprocessed_count} / results ${s.result_count}`);
|
||||
}
|
||||
|
||||
/* ---- frame rendering (latest-wins; the frame IS the Qt plot image) - */
|
||||
@@ -305,6 +384,7 @@ async function init() {
|
||||
settingsNote.textContent = "Status unavailable: " + err.message;
|
||||
}
|
||||
await loadSettings();
|
||||
await loadConfigList();
|
||||
connectWs();
|
||||
}
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user