refator_comm1
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user