diff --git a/src/index.html b/src/index.html index 23e89d2..fd0c63c 100644 --- a/src/index.html +++ b/src/index.html @@ -454,6 +454,10 @@ const API_BASE = (window.FLEETOPS_API_BASE && /^https?:\/\//.test(window.FLEETOP const $ = (id) => document.getElementById(id); const num = (v, d = 0) => (v == null || isNaN(v)) ? '—' : Number(v).toLocaleString('en', { minimumFractionDigits: d, maximumFractionDigits: d }); const intg = (v) => (v == null || isNaN(v)) ? '—' : Number(v).toLocaleString('en'); +// Which tab owns the shared header KPI strip right now — guards late async +// loaders (e.g. boot loadAll finishing after the user switched tabs) from +// clobbering another tab's header. +const activeTab = () => (document.querySelector('.tab.active')?.dataset.tab) || 'logistics'; async function api(path) { const r = await fetch(`${API_BASE}${path}`, { headers: { 'Accept': 'application/json' } }); @@ -525,6 +529,7 @@ $('refresh').addEventListener('click', loadAll); // RENDER — KPIs // ============================================================================ function renderKpis(totals, fuelL) { + if (activeTab() !== 'logistics') return; // don't clobber another tab's header totals = totals || {}; const kpis = [ ['accent', intg(totals.vehicles), 'Vehicles'], @@ -700,6 +705,7 @@ function fuelQs() { } function renderFuelKpis(t) { + if (activeTab() !== 'fuel') return; t = t || {}; const kpis = [ ['accent', intg(t.vehicles_fuelled), 'Vehicles'], @@ -1007,6 +1013,7 @@ function updateVehScale() { // ── render: header KPIs + metric strip + tables + closure chart ───────────── function renderIncKpis(m) { + if (activeTab() !== 'tickets') return; m = m || {}; const so = (m.sla && m.sla.open) || {}; const k = [ ['accent', intg(m.open_now), 'INC open'],