diff --git a/ctrl/static/app.js b/ctrl/static/app.js index dc53493..3d7c18c 100644 --- a/ctrl/static/app.js +++ b/ctrl/static/app.js @@ -63,7 +63,8 @@ async function refreshWorkers() { box.innerHTML = `` + workers.map((w) => { - const addr = `${w.host || ""}:${w.port || ""}`; + const displayHost = w.online ? (w.hostname || w.ip || w.host) : w.host; + const addr = `${esc(displayHost)}:${esc(w.port || "")}`; const status = w.online ? `ready · ${esc(w.status || "ok")}` : `down`; @@ -72,7 +73,7 @@ async function refreshWorkers() { - + `; }).join("") + `
AddressStatusOS / CPU
${esc(addr)} ${status} ${osCpu}
`; } catch (_) { @@ -85,6 +86,7 @@ $("#worker-form").addEventListener("submit", async (e) => { const input = $("#worker-spec"); const spec = input.value.trim(); if (!spec) return; + const msg = $("#worker-msg"); try { const resp = await fetch("/api/workers", { method: "POST", @@ -94,25 +96,35 @@ $("#worker-form").addEventListener("submit", async (e) => { const data = await resp.json().catch(() => ({})); if (!resp.ok) throw new Error(data.error || resp.statusText); input.value = ""; + msg.textContent = `Added worker ${spec}`; + msg.className = "msg"; refreshWorkers(); refreshCapabilities(); } catch (err) { - $("#worker-spec").value = ""; - $("#worker-spec").placeholder = `Error: ${err.message}`; + input.value = ""; + msg.textContent = `Error: ${err.message}`; + msg.className = "msg error"; } }); $("#workers").addEventListener("click", async (e) => { const btn = e.target.closest("button.remove-worker"); if (!btn) return; - const url = btn.dataset.url; - const host = url.replace(/^https?:\/\//, "").split(":")[0]; - const port = url.replace(/^https?:\/\//, "").split(":")[1]; + const msg = $("#worker-msg"); + const host = btn.dataset.host; + const port = btn.dataset.port; try { - await fetch(`/api/workers/${encodeURIComponent(port)}/${encodeURIComponent(host)}`, { method: "DELETE" }); + const resp = await fetch(`/api/workers/${encodeURIComponent(port)}/${encodeURIComponent(host)}`, { method: "DELETE" }); + const data = await resp.json().catch(() => ({})); + if (!resp.ok) throw new Error(data.error || resp.statusText); + msg.textContent = `Removed ${host}:${port}`; + msg.className = "msg"; refreshWorkers(); refreshCapabilities(); - } catch (_) {} + } catch (err) { + msg.textContent = `Remove failed: ${err.message}`; + msg.className = "msg error"; + } }); async function refreshJobs() { diff --git a/ctrl/static/index.html b/ctrl/static/index.html index 0b556fc..9b070de 100644 --- a/ctrl/static/index.html +++ b/ctrl/static/index.html @@ -19,6 +19,7 @@ +

@@ -28,18 +29,18 @@
-
- - -
-