refator_comm1

This commit is contained in:
Mateusz Gruszczyński
2025-10-18 23:03:16 +02:00
parent e1031d8ae0
commit 3dd0131088

View File

@@ -35,7 +35,7 @@ function setBadgeCell(cell, textOrState) {
else html = badge(textOrState || '—','dark'); else html = badge(textOrState || '—','dark');
if (cell.innerHTML !== html) { if (cell.innerHTML !== html) {
cell.innerHTML = html; cell.innerHTML = html;
return true; // zmiana return true; // changed
} }
return false; return false;
} }
@@ -128,10 +128,13 @@ export async function startAdminWatches() {
const tbody = document.querySelector('#vm-admin tbody'); const tbody = document.querySelector('#vm-admin tbody');
if (!tbody) return; 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, []); setRows(tbody, []);
// inicjalne wypełnienie tabeli // initial table fill
try { try {
const latest = await api.listAllVmct(); const latest = await api.listAllVmct();
const all = Array.isArray(latest.all) ? latest.all : []; const all = Array.isArray(latest.all) ? latest.all : [];
@@ -161,7 +164,7 @@ export async function startAdminWatches() {
setRows(tbody, html); 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 => { Array.from(tbody.querySelectorAll('tr[data-sid]')).forEach(tr => {
const nodeCell = tr.children[3]; const nodeCell = tr.children[3];
const targetSel = tr.querySelector('.target-node'); const targetSel = tr.querySelector('.target-node');
@@ -178,12 +181,12 @@ export async function startAdminWatches() {
setMigrateDisabled(tr, false); setMigrateDisabled(tr, false);
const res = await api.vmAction(sid, kind, targetNode); const res = await api.vmAction(sid, kind, targetNode);
if (res?.ok) { if (res?.ok) {
showToast(`Zadanie ${kind} wystartowało dla ${safe(nameCell.textContent)}`); showToast(`Task ${kind} started for ${safe(nameCell.textContent)}`);
} else { } else {
showToast(`Błąd zadania ${kind} dla ${safe(nameCell.textContent)}`, 'danger'); showToast(`Task ${kind} failed for ${safe(nameCell.textContent)}`, 'danger');
} }
} catch (e) { } 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(); window.__nodesCache = availableNodes.slice();
// pełna lista co 30 s // full refresh every 30s
slowTimer = setInterval(async () => { slowTimer = setInterval(async () => {
try { try {
const latest = await api.listAllVmct(); const latest = await api.listAllVmct();
@@ -222,7 +225,7 @@ export async function startAdminWatches() {
flashDot(nameCell); 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(); const currentTxt = (statusCell?.innerText || '').toLowerCase();
if (!/working/.test(currentTxt)) { if (!/working/.test(currentTxt)) {
const stRaw = String(rowData.status || '').toLowerCase(); // fallback z /cluster/resources const stRaw = String(rowData.status || '').toLowerCase(); // fallback z /cluster/resources
@@ -237,7 +240,7 @@ export async function startAdminWatches() {
} catch {} } catch {}
}, 30000); }, 30000);
// tylko aktywne co 10 s (dociąga precyzyjny status + node) // active only every 10s (pull precise status + node)
fastTimer = setInterval(async () => { fastTimer = setInterval(async () => {
try { try {
const sids = Array.from(activeSids); const sids = Array.from(activeSids);
@@ -277,7 +280,7 @@ export async function startAdminWatches() {
window.addEventListener('beforeunload', stopAllAdminWatches, { once: true }); window.addEventListener('beforeunload', stopAllAdminWatches, { once: true });
} catch (e) { } 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 { try {
await startAdminWatches(); await startAdminWatches();
} catch (e) { } catch (e) {
showToast(`Błąd inicjalizacji VM Admin: ${e?.message || e}`, 'danger'); showToast(`VM Admin initialization error: ${e?.message || e}`, 'danger');
console.error(e); console.error(e);
} }
} }