From 3dd0131088bc0fc4858b3b6fe6638d2aa9ba78ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Sat, 18 Oct 2025 23:03:16 +0200 Subject: [PATCH] refator_comm1 --- static/js/admin.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/static/js/admin.js b/static/js/admin.js index 3131b5c..ed56432 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -35,7 +35,7 @@ function setBadgeCell(cell, textOrState) { else html = badge(textOrState || '—','dark'); if (cell.innerHTML !== html) { cell.innerHTML = html; - return true; // zmiana + return true; // changed } return false; } @@ -128,10 +128,13 @@ export async function startAdminWatches() { const tbody = document.querySelector('#vm-admin tbody'); if (!tbody) return; - const availableNodes = await api.listNodes(); + const ns = await api.nodesSummary(); + const availableNodes = Array.isArray(ns?.nodes) + ? Array.from(new Set(ns.nodes.map(n => String(n.name || n.node || n).trim()).filter(Boolean))) + : (Array.isArray(ns) ? Array.from(new Set(ns.map(n => String(n.name || n.node || n).trim()).filter(Boolean))) : []); setRows(tbody, []); - // inicjalne wypełnienie tabeli + // initial table fill try { const latest = await api.listAllVmct(); const all = Array.isArray(latest.all) ? latest.all : []; @@ -161,7 +164,7 @@ export async function startAdminWatches() { setRows(tbody, html); - // podłącz selecty z node'ami i akcje + // wire node selects and actions Array.from(tbody.querySelectorAll('tr[data-sid]')).forEach(tr => { const nodeCell = tr.children[3]; const targetSel = tr.querySelector('.target-node'); @@ -178,12 +181,12 @@ export async function startAdminWatches() { setMigrateDisabled(tr, false); const res = await api.vmAction(sid, kind, targetNode); if (res?.ok) { - showToast(`Zadanie ${kind} wystartowało dla ${safe(nameCell.textContent)}`); + showToast(`Task ${kind} started for ${safe(nameCell.textContent)}`); } else { - showToast(`Błąd zadania ${kind} dla ${safe(nameCell.textContent)}`, 'danger'); + showToast(`Task ${kind} failed for ${safe(nameCell.textContent)}`, 'danger'); } } catch (e) { - showToast(`Błąd: ${e?.message || e}`, 'danger'); + showToast(`Error: ${e?.message || e}`, 'danger'); } } @@ -196,7 +199,7 @@ export async function startAdminWatches() { window.__nodesCache = availableNodes.slice(); - // pełna lista – co 30 s + // full refresh – every 30s slowTimer = setInterval(async () => { try { const latest = await api.listAllVmct(); @@ -222,7 +225,7 @@ export async function startAdminWatches() { flashDot(nameCell); } - // status z wolnego reconcile — tylko gdy brak „working”, żeby nie zagłuszać WS + // status from slow reconcile — only when not 'working' to avoid overruling WS const currentTxt = (statusCell?.innerText || '').toLowerCase(); if (!/working/.test(currentTxt)) { const stRaw = String(rowData.status || '').toLowerCase(); // fallback z /cluster/resources @@ -237,7 +240,7 @@ export async function startAdminWatches() { } catch {} }, 30000); - // tylko aktywne – co 10 s (dociąga precyzyjny status + node) + // active only – every 10s (pull precise status + node) fastTimer = setInterval(async () => { try { const sids = Array.from(activeSids); @@ -277,7 +280,7 @@ export async function startAdminWatches() { window.addEventListener('beforeunload', stopAllAdminWatches, { once: true }); } catch (e) { - showToast(`Nie udało się załadować listy: ${e?.message || e}`, 'danger'); + showToast(`Failed to load list: ${e?.message || e}`, 'danger'); } } @@ -286,7 +289,7 @@ export async function renderVMAdmin() { try { await startAdminWatches(); } catch (e) { - showToast(`Błąd inicjalizacji VM Admin: ${e?.message || e}`, 'danger'); + showToast(`VM Admin initialization error: ${e?.message || e}`, 'danger'); console.error(e); } }