This commit is contained in:
2026-03-18 17:28:29 +01:00
parent 2a249e16d4
commit 18c26e3cc2
3 changed files with 138 additions and 6 deletions

View File

@@ -107,6 +107,29 @@
col.className = 'col-12 col-lg-6';
const statusText = job.running ? 'in esecuzione' : job.last_status;
// Barra di avanzamento (visibile solo durante il download)
const total = job.files_total || 0;
const done = job.files_done || 0;
const pct = total > 0 ? Math.round((done / total) * 100) : 0;
const showProgress = job.running && total > 0;
const progressHtml = showProgress ? `
<div class="mt-3">
<div class="d-flex justify-content-between align-items-center mb-1">
<span class="mono small progress-phase">${job.phase || 'in corso\u2026'}</span>
<span class="mono small">${done} / ${total}  <span class="text-secondary">(${pct}%)</span></span>
</div>
<div class="progress-track"><div class="progress-fill" style="width:${pct}%"></div></div>
</div>
` : (job.running ? `<div class="mt-3 mono small progress-phase">${job.phase || 'in corso\u2026'}</div>` : '');
// File corrente
const fileHtml = job.running && job.current_file ? `
<div class="mt-2 current-file-box mono">
<span class="current-file-label">copia</span>
<span class="current-file-name" title="${escHtml(job.current_file)}">${escHtml(job.current_file)}</span>
</div>
` : '';
col.innerHTML = `
<article class="job-card p-4">
<div class="d-flex justify-content-between align-items-start gap-3">
@@ -123,6 +146,9 @@
<div>Ultima fine: ${fmtDate(job.last_end)}</div>
</div>
${progressHtml}
${fileHtml}
<div class="mt-3 summary-box mono small">${fmtSummary(job.last_summary, job.running)}</div>
<div class="mt-3 d-flex gap-2">
@@ -146,6 +172,10 @@
});
}
function escHtml(s) {
return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
}
let prevLogTime = null;
function renderLogs(logs) {
@@ -179,6 +209,8 @@
}
}
let pollTimer = null;
async function reload() {
try {
const data = await fetchStatus();
@@ -192,8 +224,13 @@
} else {
dot.classList.add('d-none');
}
// Polling veloce (1 s) durante sync attiva, lento (5 s) a riposo
const interval = anyRunning ? 1000 : 5000;
clearTimeout(pollTimer);
pollTimer = setTimeout(reload, interval);
} catch (err) {
document.getElementById('serverTime').textContent = `Errore: ${err.message}`;
pollTimer = setTimeout(reload, 5000);
}
}
@@ -209,7 +246,7 @@
});
reload();
setInterval(reload, 5000);
// il timer ricorsivo in reload() gestisce il polling adattivo
</script>
</body>
</html>