fix: always populate glance-strip for all hosts on page load

fetchHostGlance was only called for the initially expanded host, leaving
all other hosts showing "—" until manually expanded. Now fetches glance
for every host-card on DOMContentLoaded and refreshes all (not just
expanded) on the 30s auto-refresh interval.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Andreas Wrede
2026-05-10 14:13:10 -04:00
parent 7444262985
commit 3e9b052f71
+24 -21
View File
@@ -1305,9 +1305,12 @@
// ── Auto-refresh (30 s) ───────────────────────────────────────────────── // ── Auto-refresh (30 s) ─────────────────────────────────────────────────
setInterval(() => { setInterval(() => {
document.querySelectorAll('.host-card').forEach(card => {
fetchHostGlance(card.dataset.hostname);
});
document.querySelectorAll('.host-card:not(.collapsed)').forEach(card => { document.querySelectorAll('.host-card:not(.collapsed)').forEach(card => {
const hostname = card.dataset.hostname; const hostname = card.dataset.hostname;
fetchHostGlance(hostname);
card.querySelectorAll('.plugin-accordion:not(.collapsed)').forEach(acc => { card.querySelectorAll('.plugin-accordion:not(.collapsed)').forEach(acc => {
const pname = acc.dataset.plugin; const pname = acc.dataset.plugin;
@@ -1327,15 +1330,16 @@
// ── Init ──────────────────────────────────────────────────────────────── // ── Init ────────────────────────────────────────────────────────────────
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
// If a host fragment is in the URL, expand and scroll to that host; // Fetch glance data for every host immediately so the strip is always populated.
// otherwise expand the first host as before. document.querySelectorAll('.host-card').forEach(card => {
const hash = window.location.hash; fetchHostGlance(card.dataset.hostname);
if (hash) { });
const hostname = decodeURIComponent(hash.slice(1));
// Expand and load info for the target host (URL hash or first host).
function expandHost(hostname) {
const card = document.querySelector(`.host-card[data-hostname="${hostname}"]`); const card = document.querySelector(`.host-card[data-hostname="${hostname}"]`);
if (card) { if (!card) return false;
card.classList.remove('collapsed'); card.classList.remove('collapsed');
fetchHostGlance(hostname);
fetchHostInfo(hostname).then(data => { fetchHostInfo(hostname).then(data => {
infoCache[hostname] = data; infoCache[hostname] = data;
renderInfoSection(hostname, data); renderInfoSection(hostname, data);
@@ -1343,23 +1347,22 @@
const el = document.getElementById(`info-${hostname}`); const el = document.getElementById(`info-${hostname}`);
if (el) el.innerHTML = '<div class="info-loading">Could not load host info.</div>'; if (el) el.innerHTML = '<div class="info-loading">Could not load host info.</div>';
}); });
setTimeout(() => card.scrollIntoView({ behavior: 'smooth', block: 'start' }), 150); return true;
}
const hash = window.location.hash;
if (hash) {
const hostname = decodeURIComponent(hash.slice(1));
if (expandHost(hostname)) {
setTimeout(() => {
const card = document.querySelector(`.host-card[data-hostname="${hostname}"]`);
if (card) card.scrollIntoView({ behavior: 'smooth', block: 'start' });
}, 150);
return; return;
} }
} }
const first = document.querySelector('.host-card'); const first = document.querySelector('.host-card');
if (first) { if (first) expandHost(first.dataset.hostname);
const hostname = first.dataset.hostname;
first.classList.remove('collapsed');
fetchHostGlance(hostname);
fetchHostInfo(hostname).then(data => {
infoCache[hostname] = data;
renderInfoSection(hostname, data);
}).catch(() => {
const el = document.getElementById(`info-${hostname}`);
if (el) el.innerHTML = '<div class="info-loading">Could not load host info.</div>';
});
}
}); });
// ── Host action helpers ────────────────────────────────────── // ── Host action helpers ──────────────────────────────────────