927 lines
32 KiB
HTML
927 lines
32 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="it" style="height: 100%;">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>S3 Sync Dashboard</title>
|
|
<style>
|
|
/* ============================================================
|
|
CSS - Dashboard ispirata a Syncthing
|
|
============================================================ */
|
|
|
|
:root {
|
|
--bg-primary: #1a1a2e;
|
|
--bg-secondary: #16213e;
|
|
--bg-card: #1e2a47;
|
|
--bg-card-hover: #243256;
|
|
--accent: #0f9b8e;
|
|
--accent-light: #14b8a6;
|
|
--accent-glow: rgba(15, 155, 142, 0.15);
|
|
--text-primary: #e2e8f0;
|
|
--text-secondary: #94a3b8;
|
|
--text-muted: #64748b;
|
|
--border: #2d3a5c;
|
|
--success: #22c55e;
|
|
--warning: #f59e0b;
|
|
--error: #ef4444;
|
|
--info: #3b82f6;
|
|
--log-bg: #0f1729;
|
|
--scrollbar-thumb: #334155;
|
|
--scrollbar-track: #1e293b;
|
|
}
|
|
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
background: var(--bg-primary);
|
|
color: var(--text-primary);
|
|
line-height: 1.6;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
/* --- Scrollbar personalizzata --- */
|
|
::-webkit-scrollbar { width: 8px; height: 8px; }
|
|
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
|
|
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
|
|
::-webkit-scrollbar-thumb:hover { background: #475569; }
|
|
|
|
/* --- Header --- */
|
|
.header {
|
|
background: var(--bg-secondary);
|
|
border-bottom: 1px solid var(--border);
|
|
padding: 1rem 2rem;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 100;
|
|
backdrop-filter: blur(10px);
|
|
}
|
|
|
|
.header-left {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.logo {
|
|
font-size: 1.5rem;
|
|
font-weight: 700;
|
|
color: var(--accent-light);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.logo svg {
|
|
width: 28px;
|
|
height: 28px;
|
|
}
|
|
|
|
.status-badge {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
padding: 0.3rem 0.8rem;
|
|
border-radius: 20px;
|
|
font-size: 0.8rem;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
.status-badge .dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
animation: pulse 2s infinite;
|
|
}
|
|
|
|
.status-idle { background: rgba(34,197,94,0.15); color: var(--success); }
|
|
.status-idle .dot { background: var(--success); }
|
|
|
|
.status-syncing { background: rgba(59,130,246,0.15); color: var(--info); }
|
|
.status-syncing .dot { background: var(--info); animation: pulse 1s infinite; }
|
|
|
|
.status-error { background: rgba(239,68,68,0.15); color: var(--error); }
|
|
.status-error .dot { background: var(--error); }
|
|
|
|
.status-starting { background: rgba(245,158,11,0.15); color: var(--warning); }
|
|
.status-starting .dot { background: var(--warning); }
|
|
|
|
@keyframes pulse {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.4; }
|
|
}
|
|
|
|
/* --- Layout principale --- */
|
|
.container {
|
|
max-width: 1400px;
|
|
margin: 0 auto;
|
|
padding: 1.5rem;
|
|
display: grid;
|
|
gap: 1.5rem;
|
|
}
|
|
|
|
/* --- Griglia cards superiore --- */
|
|
.stats-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
|
gap: 1rem;
|
|
}
|
|
|
|
.card {
|
|
background: var(--bg-card);
|
|
border: 1px solid var(--border);
|
|
border-radius: 12px;
|
|
padding: 1.25rem;
|
|
transition: all 0.2s ease;
|
|
}
|
|
|
|
.card:hover {
|
|
background: var(--bg-card-hover);
|
|
border-color: var(--accent);
|
|
box-shadow: 0 0 20px var(--accent-glow);
|
|
}
|
|
|
|
.card-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
|
|
.card-title {
|
|
font-size: 0.8rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
color: var(--text-muted);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.card-icon {
|
|
width: 36px;
|
|
height: 36px;
|
|
border-radius: 8px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.card-value {
|
|
font-size: 1.8rem;
|
|
font-weight: 700;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.card-sub {
|
|
font-size: 0.8rem;
|
|
color: var(--text-secondary);
|
|
margin-top: 0.25rem;
|
|
}
|
|
|
|
/* --- Sezione configurazione --- */
|
|
.config-section {
|
|
background: var(--bg-card);
|
|
border: 1px solid var(--border);
|
|
border-radius: 12px;
|
|
padding: 1.25rem;
|
|
}
|
|
|
|
.config-section h2 {
|
|
font-size: 1rem;
|
|
margin-bottom: 1rem;
|
|
color: var(--accent-light);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.config-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 0.75rem;
|
|
}
|
|
|
|
.config-item {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.2rem;
|
|
}
|
|
|
|
.config-label {
|
|
font-size: 0.75rem;
|
|
color: var(--text-muted);
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
.config-value {
|
|
font-size: 0.9rem;
|
|
color: var(--text-secondary);
|
|
font-family: 'SF Mono', 'Fira Code', monospace;
|
|
background: var(--bg-primary);
|
|
padding: 0.3rem 0.6rem;
|
|
border-radius: 6px;
|
|
word-break: break-all;
|
|
}
|
|
|
|
/* --- Layout inferiore: Log + Modifiche side by side --- */
|
|
.bottom-grid {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 1.5rem;
|
|
}
|
|
|
|
@media (max-width: 900px) {
|
|
.bottom-grid { grid-template-columns: 1fr; }
|
|
}
|
|
|
|
/* --- Pannello log --- */
|
|
.log-panel {
|
|
background: var(--bg-card);
|
|
border: 1px solid var(--border);
|
|
border-radius: 12px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
max-height: 500px;
|
|
}
|
|
|
|
.panel-header {
|
|
padding: 1rem 1.25rem;
|
|
border-bottom: 1px solid var(--border);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.panel-header h2 {
|
|
font-size: 1rem;
|
|
color: var(--accent-light);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.log-container {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 0.75rem;
|
|
background: var(--log-bg);
|
|
border-radius: 0 0 12px 12px;
|
|
font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
|
|
font-size: 0.78rem;
|
|
line-height: 1.7;
|
|
}
|
|
|
|
.log-line {
|
|
padding: 0.1rem 0.4rem;
|
|
border-radius: 3px;
|
|
white-space: pre-wrap;
|
|
word-break: break-all;
|
|
}
|
|
|
|
.log-line:hover {
|
|
background: rgba(255,255,255,0.03);
|
|
}
|
|
|
|
.log-line.log-error { color: var(--error); }
|
|
.log-line.log-warn { color: var(--warning); }
|
|
.log-line.log-info { color: var(--text-secondary); }
|
|
.log-line.log-success { color: var(--success); }
|
|
|
|
/* --- Pannello modifiche recenti --- */
|
|
.changes-panel {
|
|
background: var(--bg-card);
|
|
border: 1px solid var(--border);
|
|
border-radius: 12px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
max-height: 500px;
|
|
}
|
|
|
|
.changes-list {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 0.5rem;
|
|
}
|
|
|
|
.change-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
padding: 0.6rem 0.75rem;
|
|
border-radius: 8px;
|
|
transition: background 0.15s ease;
|
|
}
|
|
|
|
.change-item:hover {
|
|
background: rgba(255,255,255,0.03);
|
|
}
|
|
|
|
.change-icon {
|
|
width: 32px;
|
|
height: 32px;
|
|
border-radius: 8px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 0.85rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.change-icon.added { background: rgba(34,197,94,0.15); color: var(--success); }
|
|
.change-icon.modified { background: rgba(59,130,246,0.15); color: var(--info); }
|
|
.change-icon.deleted { background: rgba(239,68,68,0.15); color: var(--error); }
|
|
|
|
.change-info {
|
|
flex: 1;
|
|
min-width: 0;
|
|
}
|
|
|
|
.change-name {
|
|
font-size: 0.85rem;
|
|
color: var(--text-primary);
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
}
|
|
|
|
.change-meta {
|
|
font-size: 0.75rem;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.change-size {
|
|
font-size: 0.75rem;
|
|
color: var(--text-secondary);
|
|
font-family: 'SF Mono', 'Fira Code', monospace;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
/* --- Countdown / progress bar --- */
|
|
.next-sync-bar {
|
|
height: 3px;
|
|
background: var(--border);
|
|
border-radius: 2px;
|
|
margin-top: 0.5rem;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.next-sync-bar .fill {
|
|
height: 100%;
|
|
background: var(--accent);
|
|
border-radius: 2px;
|
|
transition: width 1s linear;
|
|
}
|
|
|
|
/* --- Empty state --- */
|
|
.empty-state {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 2rem;
|
|
color: var(--text-muted);
|
|
font-size: 0.85rem;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.empty-state .empty-icon {
|
|
font-size: 2rem;
|
|
opacity: 0.4;
|
|
}
|
|
|
|
/* --- Bottoni --- */
|
|
.btn {
|
|
padding: 0.4rem 0.8rem;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
background: var(--bg-primary);
|
|
color: var(--text-secondary);
|
|
font-size: 0.78rem;
|
|
cursor: pointer;
|
|
transition: all 0.15s ease;
|
|
}
|
|
|
|
.btn:hover {
|
|
border-color: var(--accent);
|
|
color: var(--accent-light);
|
|
}
|
|
|
|
/* --- Connessione SSE indicatore --- */
|
|
.connection-indicator {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
font-size: 0.75rem;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.connection-indicator .dot {
|
|
width: 6px;
|
|
height: 6px;
|
|
border-radius: 50%;
|
|
background: var(--success);
|
|
}
|
|
|
|
.connection-indicator.disconnected .dot {
|
|
background: var(--error);
|
|
}
|
|
|
|
/* --- Storico sync --- */
|
|
.history-row {
|
|
display: grid;
|
|
grid-template-columns: 140px 80px 80px 1fr;
|
|
gap: 0.5rem;
|
|
padding: 0.4rem 0.75rem;
|
|
font-size: 0.8rem;
|
|
border-radius: 4px;
|
|
align-items: center;
|
|
}
|
|
|
|
.history-row:hover {
|
|
background: rgba(255,255,255,0.03);
|
|
}
|
|
|
|
.history-row .time { color: var(--text-muted); font-family: monospace; }
|
|
.history-row .result-ok { color: var(--success); }
|
|
.history-row .result-fail { color: var(--error); }
|
|
.history-row .duration { color: var(--text-secondary); }
|
|
.history-row .details { color: var(--text-muted); }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- ============================================================
|
|
Header con logo e stato globale
|
|
============================================================ -->
|
|
<header class="header">
|
|
<div class="header-left">
|
|
<div class="logo">
|
|
<!-- Icona sync SVG -->
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/>
|
|
<path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/>
|
|
</svg>
|
|
S3 Sync
|
|
</div>
|
|
<span id="statusBadge" class="status-badge status-starting">
|
|
<span class="dot"></span>
|
|
<span id="statusText">Avvio...</span>
|
|
</span>
|
|
</div>
|
|
<div class="connection-indicator" id="connectionIndicator">
|
|
<span class="dot"></span>
|
|
<span id="connectionText">Connesso</span>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="container">
|
|
|
|
<!-- ============================================================
|
|
Cards statistiche
|
|
============================================================ -->
|
|
<div class="stats-grid">
|
|
<!-- Card: Ultima sync -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<span class="card-title">Ultima Sincronizzazione</span>
|
|
<div class="card-icon" style="background: rgba(34,197,94,0.15); color: var(--success);">✓</div>
|
|
</div>
|
|
<div class="card-value" id="lastSyncTime">--:--</div>
|
|
<div class="card-sub" id="lastSyncAgo">In attesa...</div>
|
|
</div>
|
|
|
|
<!-- Card: Prossima sync -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<span class="card-title">Prossima Sincronizzazione</span>
|
|
<div class="card-icon" style="background: rgba(59,130,246,0.15); color: var(--info);">↻</div>
|
|
</div>
|
|
<div class="card-value" id="nextSyncCountdown">--:--</div>
|
|
<div class="next-sync-bar"><div class="fill" id="nextSyncBar" style="width: 0%"></div></div>
|
|
</div>
|
|
|
|
<!-- Card: File sincronizzati -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<span class="card-title">File Locali</span>
|
|
<div class="card-icon" style="background: rgba(14,165,233,0.15); color: #0ea5e9;">📁</div>
|
|
</div>
|
|
<div class="card-value" id="fileCount">--</div>
|
|
<div class="card-sub" id="folderSize">Calcolo...</div>
|
|
</div>
|
|
|
|
<!-- Card: Sync completate -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<span class="card-title">Sync Completate</span>
|
|
<div class="card-icon" style="background: rgba(168,85,247,0.15); color: #a855f7;">☆</div>
|
|
</div>
|
|
<div class="card-value" id="syncCount">0</div>
|
|
<div class="card-sub" id="syncErrors">0 errori</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ============================================================
|
|
Configurazione attiva
|
|
============================================================ -->
|
|
<div class="config-section">
|
|
<h2>⚙ Configurazione Attiva</h2>
|
|
<div class="config-grid">
|
|
<div class="config-item">
|
|
<span class="config-label">Endpoint</span>
|
|
<span class="config-value">{{ config.endpoint }}</span>
|
|
</div>
|
|
<div class="config-item">
|
|
<span class="config-label">Bucket</span>
|
|
<span class="config-value">{{ config.bucket }}</span>
|
|
</div>
|
|
<div class="config-item">
|
|
<span class="config-label">Prefisso</span>
|
|
<span class="config-value">{{ config.prefix }}</span>
|
|
</div>
|
|
<div class="config-item">
|
|
<span class="config-label">Modalità</span>
|
|
<span class="config-value">{{ config.sync_mode }}</span>
|
|
</div>
|
|
<div class="config-item">
|
|
<span class="config-label">Pianificazione</span>
|
|
<span class="config-value">{{ config.schedule_display }}{% if config.schedule_mode == 'cron' %} ({{ config.sync_schedule }}){% endif %}</span>
|
|
</div>
|
|
<div class="config-item">
|
|
<span class="config-label">Sync all'avvio</span>
|
|
<span class="config-value">{{ config.sync_on_start }}</span>
|
|
</div>
|
|
<div class="config-item">
|
|
<span class="config-label">Trasferimenti</span>
|
|
<span class="config-value">{{ config.transfers }} paralleli</span>
|
|
</div>
|
|
<div class="config-item">
|
|
<span class="config-label">Banda</span>
|
|
<span class="config-value">{{ config.bandwidth }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ============================================================
|
|
Log in tempo reale + Modifiche recenti
|
|
============================================================ -->
|
|
<div class="bottom-grid">
|
|
<!-- Pannello log -->
|
|
<div class="log-panel">
|
|
<div class="panel-header">
|
|
<h2>📜 Log in Tempo Reale</h2>
|
|
<div style="display:flex; gap:0.5rem;">
|
|
<button class="btn" onclick="toggleAutoScroll()" id="autoScrollBtn">Auto-scroll: ON</button>
|
|
<button class="btn" onclick="clearLogDisplay()">Pulisci</button>
|
|
</div>
|
|
</div>
|
|
<div class="log-container" id="logContainer">
|
|
<div class="empty-state">
|
|
<div class="empty-icon">📄</div>
|
|
In attesa dei log...
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Pannello modifiche recenti -->
|
|
<div class="changes-panel">
|
|
<div class="panel-header">
|
|
<h2>🕒 Modifiche Recenti</h2>
|
|
<span class="card-sub" id="changesCount">0 modifiche</span>
|
|
</div>
|
|
<div class="changes-list" id="changesList">
|
|
<div class="empty-state">
|
|
<div class="empty-icon">📁</div>
|
|
Nessuna modifica registrata
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ============================================================
|
|
Storico sincronizzazioni
|
|
============================================================ -->
|
|
<div class="config-section">
|
|
<h2>📊 Storico Sincronizzazioni</h2>
|
|
<div id="historyList">
|
|
<div class="empty-state">
|
|
<div class="empty-icon">📋</div>
|
|
Nessuna sincronizzazione completata
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
// ============================================================
|
|
// JavaScript - Logica dashboard in tempo reale
|
|
// ============================================================
|
|
|
|
// --- Stato globale ---
|
|
let autoScroll = true;
|
|
let logLines = 0;
|
|
const MAX_LOG_LINES = 500; // Limite righe log per performance
|
|
const SYNC_INTERVAL = {{ config.sync_interval }};
|
|
const SCHEDULE_MODE = '{{ config.schedule_mode }}'; // "interval" o "cron"
|
|
let lastSyncTimestamp = null;
|
|
let statusMessage = ''; // Messaggio dal server (contiene info prossima sync cron)
|
|
let evtSource = null;
|
|
|
|
// --- Inizializzazione SSE (Server-Sent Events) ---
|
|
function connectSSE() {
|
|
if (evtSource) evtSource.close();
|
|
|
|
evtSource = new EventSource('/api/stream');
|
|
|
|
evtSource.onmessage = function(event) {
|
|
const data = JSON.parse(event.data);
|
|
|
|
if (data.type === 'log') {
|
|
appendLog(data.message);
|
|
}
|
|
// Heartbeat: nessuna azione necessaria (mantiene la connessione)
|
|
};
|
|
|
|
evtSource.onopen = function() {
|
|
setConnectionStatus(true);
|
|
};
|
|
|
|
evtSource.onerror = function() {
|
|
setConnectionStatus(false);
|
|
// Riconnessione automatica gestita dal browser
|
|
};
|
|
}
|
|
|
|
// --- Aggiunge una riga al pannello log ---
|
|
function appendLog(message) {
|
|
const container = document.getElementById('logContainer');
|
|
|
|
// Rimuovi empty state se presente
|
|
const emptyState = container.querySelector('.empty-state');
|
|
if (emptyState) emptyState.remove();
|
|
|
|
// Crea elemento riga
|
|
const line = document.createElement('div');
|
|
line.className = 'log-line ' + getLogClass(message);
|
|
line.textContent = message;
|
|
container.appendChild(line);
|
|
|
|
logLines++;
|
|
|
|
// Limita numero di righe (performance)
|
|
if (logLines > MAX_LOG_LINES) {
|
|
container.removeChild(container.firstChild);
|
|
logLines--;
|
|
}
|
|
|
|
// Auto-scroll verso il basso
|
|
if (autoScroll) {
|
|
container.scrollTop = container.scrollHeight;
|
|
}
|
|
}
|
|
|
|
// --- Determina la classe CSS in base al contenuto del log ---
|
|
function getLogClass(message) {
|
|
if (message.includes('[ERROR]')) return 'log-error';
|
|
if (message.includes('[WARN]')) return 'log-warn';
|
|
if (message.includes('completata con successo')) return 'log-success';
|
|
return 'log-info';
|
|
}
|
|
|
|
// --- Toggle auto-scroll ---
|
|
function toggleAutoScroll() {
|
|
autoScroll = !autoScroll;
|
|
document.getElementById('autoScrollBtn').textContent =
|
|
'Auto-scroll: ' + (autoScroll ? 'ON' : 'OFF');
|
|
}
|
|
|
|
// --- Pulisci display log ---
|
|
function clearLogDisplay() {
|
|
const container = document.getElementById('logContainer');
|
|
container.innerHTML = '';
|
|
logLines = 0;
|
|
}
|
|
|
|
// --- Stato connessione SSE ---
|
|
function setConnectionStatus(connected) {
|
|
const el = document.getElementById('connectionIndicator');
|
|
const text = document.getElementById('connectionText');
|
|
if (connected) {
|
|
el.classList.remove('disconnected');
|
|
text.textContent = 'Connesso';
|
|
} else {
|
|
el.classList.add('disconnected');
|
|
text.textContent = 'Riconnessione...';
|
|
}
|
|
}
|
|
|
|
// --- Aggiorna stato dalla API ---
|
|
async function updateStatus() {
|
|
try {
|
|
const res = await fetch('/api/status');
|
|
const data = await res.json();
|
|
|
|
// Badge stato
|
|
const badge = document.getElementById('statusBadge');
|
|
const statusText = document.getElementById('statusText');
|
|
badge.className = 'status-badge status-' + data.state;
|
|
|
|
const stateLabels = {
|
|
'idle': 'Sincronizzato',
|
|
'syncing': 'Sincronizzazione...',
|
|
'error': 'Errore',
|
|
'starting': 'Avvio...',
|
|
'waiting': 'In attesa'
|
|
};
|
|
statusText.textContent = stateLabels[data.state] || data.state;
|
|
|
|
// Ultima sync
|
|
if (data.last_sync) {
|
|
lastSyncTimestamp = new Date(data.last_sync);
|
|
document.getElementById('lastSyncTime').textContent =
|
|
lastSyncTimestamp.toLocaleTimeString('it-IT');
|
|
updateLastSyncAgo();
|
|
}
|
|
|
|
// Messaggio di stato (contiene info prossima sync per cron)
|
|
if (data.message) {
|
|
statusMessage = data.message;
|
|
}
|
|
|
|
// Contatori
|
|
if (data.sync_count !== undefined) {
|
|
document.getElementById('syncCount').textContent = data.sync_count;
|
|
}
|
|
if (data.error_count !== undefined) {
|
|
const errEl = document.getElementById('syncErrors');
|
|
errEl.textContent = data.error_count + ' errori';
|
|
errEl.style.color = data.error_count > 0 ? 'var(--error)' : '';
|
|
}
|
|
|
|
// Statistiche cartella
|
|
if (data.folder_stats) {
|
|
document.getElementById('fileCount').textContent =
|
|
data.folder_stats.file_count.toLocaleString('it-IT');
|
|
document.getElementById('folderSize').textContent =
|
|
data.folder_stats.total_size_human + ' in ' +
|
|
data.folder_stats.dir_count + ' cartelle';
|
|
}
|
|
} catch (e) {
|
|
// Silenzioso: la prossima chiamata riproverà
|
|
}
|
|
}
|
|
|
|
// --- Aggiorna "tempo fa" dell'ultima sync ---
|
|
function updateLastSyncAgo() {
|
|
if (!lastSyncTimestamp) return;
|
|
|
|
const now = new Date();
|
|
const diff = Math.floor((now - lastSyncTimestamp) / 1000);
|
|
let text;
|
|
|
|
if (diff < 5) text = 'Adesso';
|
|
else if (diff < 60) text = diff + ' secondi fa';
|
|
else if (diff < 3600) text = Math.floor(diff / 60) + ' minuti fa';
|
|
else text = Math.floor(diff / 3600) + ' ore fa';
|
|
|
|
document.getElementById('lastSyncAgo').textContent = text;
|
|
|
|
if (SCHEDULE_MODE === 'cron') {
|
|
// Modalità cron: mostra il messaggio dal server (es. "Prossima sync: 2026-03-18 03:00:00")
|
|
// Prova a estrarre la data dal messaggio di stato
|
|
const match = statusMessage.match(/Prossima sync: (.+)/);
|
|
if (match) {
|
|
const nextTime = new Date(match[1].replace(' ', 'T'));
|
|
const remaining = Math.max(0, Math.floor((nextTime - now) / 1000));
|
|
|
|
if (remaining > 86400) {
|
|
// Più di un giorno: mostra giorni e ore
|
|
const days = Math.floor(remaining / 86400);
|
|
const hrs = Math.floor((remaining % 86400) / 3600);
|
|
document.getElementById('nextSyncCountdown').textContent =
|
|
days + 'g ' + hrs + 'h';
|
|
} else if (remaining > 3600) {
|
|
// Più di un'ora: mostra ore e minuti
|
|
const hrs = Math.floor(remaining / 3600);
|
|
const mins = Math.floor((remaining % 3600) / 60);
|
|
document.getElementById('nextSyncCountdown').textContent =
|
|
String(hrs).padStart(2, '0') + ':' + String(mins).padStart(2, '0') + 'h';
|
|
} else {
|
|
// Meno di un'ora: mostra minuti e secondi
|
|
const mins = Math.floor(remaining / 60);
|
|
const secs = remaining % 60;
|
|
document.getElementById('nextSyncCountdown').textContent =
|
|
String(mins).padStart(2, '0') + ':' + String(secs).padStart(2, '0');
|
|
}
|
|
|
|
// Progress bar (stima basata sull'intervallo tra ultima sync e prossima)
|
|
const totalWait = Math.floor((nextTime - lastSyncTimestamp) / 1000);
|
|
const pct = totalWait > 0 ? Math.min(100, ((totalWait - remaining) / totalWait) * 100) : 0;
|
|
document.getElementById('nextSyncBar').style.width = pct + '%';
|
|
} else {
|
|
document.getElementById('nextSyncCountdown').textContent = statusMessage || '--:--';
|
|
document.getElementById('nextSyncBar').style.width = '0%';
|
|
}
|
|
} else {
|
|
// Modalità intervallo: countdown classico
|
|
const remaining = Math.max(0, SYNC_INTERVAL - diff);
|
|
const mins = Math.floor(remaining / 60);
|
|
const secs = remaining % 60;
|
|
document.getElementById('nextSyncCountdown').textContent =
|
|
String(mins).padStart(2, '0') + ':' + String(secs).padStart(2, '0');
|
|
|
|
// Progress bar
|
|
const pct = Math.min(100, ((SYNC_INTERVAL - remaining) / SYNC_INTERVAL) * 100);
|
|
document.getElementById('nextSyncBar').style.width = pct + '%';
|
|
}
|
|
}
|
|
|
|
// --- Aggiorna modifiche recenti ---
|
|
async function updateChanges() {
|
|
try {
|
|
const res = await fetch('/api/changes');
|
|
const changes = await res.json();
|
|
const container = document.getElementById('changesList');
|
|
const countEl = document.getElementById('changesCount');
|
|
|
|
if (!changes || changes.length === 0) {
|
|
container.innerHTML = '<div class="empty-state"><div class="empty-icon">📁</div>Nessuna modifica registrata</div>';
|
|
countEl.textContent = '0 modifiche';
|
|
return;
|
|
}
|
|
|
|
countEl.textContent = changes.length + ' modifiche';
|
|
container.innerHTML = changes.map(c => {
|
|
const iconClass = c.action === 'new' ? 'added' :
|
|
c.action === 'deleted' ? 'deleted' : 'modified';
|
|
const iconChar = c.action === 'new' ? '+' :
|
|
c.action === 'deleted' ? '×' : '~';
|
|
const actionText = c.action === 'new' ? 'Aggiunto' :
|
|
c.action === 'deleted' ? 'Rimosso' : 'Modificato';
|
|
return `
|
|
<div class="change-item">
|
|
<div class="change-icon ${iconClass}">${iconChar}</div>
|
|
<div class="change-info">
|
|
<div class="change-name" title="${c.path}">${c.path}</div>
|
|
<div class="change-meta">${actionText} · ${c.time || ''}</div>
|
|
</div>
|
|
<div class="change-size">${c.size || ''}</div>
|
|
</div>`;
|
|
}).join('');
|
|
} catch (e) { /* retry next cycle */ }
|
|
}
|
|
|
|
// --- Aggiorna storico sincronizzazioni ---
|
|
async function updateHistory() {
|
|
try {
|
|
const res = await fetch('/api/history');
|
|
const history = await res.json();
|
|
const container = document.getElementById('historyList');
|
|
|
|
if (!history || history.length === 0) {
|
|
container.innerHTML = '<div class="empty-state"><div class="empty-icon">📋</div>Nessuna sincronizzazione completata</div>';
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = history.slice(0, 20).map(h => {
|
|
const resultClass = h.success ? 'result-ok' : 'result-fail';
|
|
const resultText = h.success ? '✓ OK' : '✗ Errore';
|
|
return `
|
|
<div class="history-row">
|
|
<span class="time">${h.time || ''}</span>
|
|
<span class="${resultClass}">${resultText}</span>
|
|
<span class="duration">${h.duration || '--'}s</span>
|
|
<span class="details">${h.transferred || 0} file, ${h.size || '0 B'}</span>
|
|
</div>`;
|
|
}).join('');
|
|
} catch (e) { /* retry next cycle */ }
|
|
}
|
|
|
|
// --- Avvio ---
|
|
connectSSE();
|
|
updateStatus();
|
|
updateChanges();
|
|
updateHistory();
|
|
|
|
// Aggiornamenti periodici
|
|
setInterval(updateStatus, 5000); // Stato ogni 5s
|
|
setInterval(updateLastSyncAgo, 1000); // Countdown ogni 1s
|
|
setInterval(updateChanges, 10000); // Modifiche ogni 10s
|
|
setInterval(updateHistory, 15000); // Storico ogni 15s
|
|
</script>
|
|
</body>
|
|
</html>
|