218 lines
9.4 KiB
HTML
218 lines
9.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="it" data-bs-theme="dark">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>SIP-DMR Live Dashboard</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
body { background-color: #121212; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
|
|
.badge-rx { background-color: #198754; color: white; }
|
|
.badge-tx { background-color: #dc3545; color: white; }
|
|
.pulsing { animation: pulse 1.5s infinite; }
|
|
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }
|
|
.table-dark { --bs-table-bg: #1e1e1e; }
|
|
|
|
/* Contenitore con scorrimento solo per lo storico */
|
|
.table-scrollable {
|
|
max-height: 75vh;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
/* Intestazioni fisse in alto durante lo scorrimento */
|
|
thead th {
|
|
position: sticky;
|
|
top: 0;
|
|
background-color: #2c3034 !important;
|
|
z-index: 10;
|
|
box-shadow: 0 1px 2px rgba(0,0,0,0.5);
|
|
}
|
|
|
|
::-webkit-scrollbar { width: 8px; }
|
|
::-webkit-scrollbar-track { background: #1e1e1e; }
|
|
::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
|
|
::-webkit-scrollbar-thumb:hover { background: #888; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container-fluid py-4 px-4">
|
|
<!-- HEADER -->
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="m-0 text-light">📡 SIP-DMR Gateway</h2>
|
|
<span id="conn-status" class="badge bg-warning text-dark fs-6">Connessione in corso...</span>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<!-- TABELLA ESTENSIONI (SINISTRA - Altezza naturale fissa) -->
|
|
<div class="col-xl-3 col-lg-4 mb-4">
|
|
<div class="card bg-dark border-secondary shadow-lg">
|
|
<div class="card-header bg-secondary text-white fw-bold">
|
|
🔌 Estensioni Connesse
|
|
</div>
|
|
<!-- Rimossa la classe table-scrollable da qui -->
|
|
<div class="card-body p-0">
|
|
<table class="table table-dark table-hover m-0">
|
|
<thead>
|
|
<tr>
|
|
<th>Est.</th>
|
|
<th>Nome</th>
|
|
<th>In Ascolto</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="tabella-estensioni">
|
|
<!-- Estensioni caricate da JS -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- TABELLA STORICO (DESTRA - Scorrimento dinamico) -->
|
|
<div class="col-xl-9 col-lg-8 mb-4">
|
|
<div class="card bg-dark border-secondary shadow-lg h-100">
|
|
<div class="card-header bg-secondary text-white fw-bold">
|
|
📻 Traffico Radio Live
|
|
</div>
|
|
<!-- Mantenuta la classe table-scrollable -->
|
|
<div class="card-body p-0 table-scrollable">
|
|
<table class="table table-dark table-hover m-0">
|
|
<thead>
|
|
<tr>
|
|
<th>Orario</th>
|
|
<th>Dir</th>
|
|
<th>Mittente</th>
|
|
<th>Destinatario (TG)</th>
|
|
<th>Durata</th>
|
|
<th>Stato</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="tabella-storico">
|
|
<!-- Storico caricato da JS -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const SERVER_IP = window.location.hostname === "" || window.location.hostname === "localhost"
|
|
? "127.0.0.1" : window.location.hostname;
|
|
const WS_PORT = "8081";
|
|
|
|
const tbodyStorico = document.getElementById('tabella-storico');
|
|
const tbodyEstensioni = document.getElementById('tabella-estensioni');
|
|
const statusBadge = document.getElementById('conn-status');
|
|
|
|
function formattaOrario(timestamp) {
|
|
const d = new Date(timestamp * 1000);
|
|
return d.toLocaleTimeString('it-IT', { hour12: false }) + '.' + String(d.getMilliseconds()).padStart(3, '0').substring(0,2);
|
|
}
|
|
|
|
function disegnaEstensioni(estensioni) {
|
|
tbodyEstensioni.innerHTML = "";
|
|
if (estensioni.length === 0) {
|
|
tbodyEstensioni.innerHTML = `<tr><td colspan="3" class="text-center text-muted py-3"><small>Nessun dispositivo collegato</small></td></tr>`;
|
|
return;
|
|
}
|
|
estensioni.forEach(est => {
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = `
|
|
<td class="fw-bold text-light">${est.estensione}</td>
|
|
<td class="text-secondary" style="font-size: 0.9em;">${est.nome}</td>
|
|
<td><span class="badge bg-info text-dark">TG ${est.tg}</span></td>
|
|
`;
|
|
tbodyEstensioni.appendChild(tr);
|
|
});
|
|
}
|
|
|
|
async function caricaEstensioni() {
|
|
try {
|
|
const res = await fetch(`http://${SERVER_IP}:${WS_PORT}/api/storico`);
|
|
const data = await res.json();
|
|
disegnaEstensioni(data.estensioni);
|
|
} catch (err) { console.error("Errore aggiornamento estensioni:", err); }
|
|
}
|
|
|
|
function creaRiga(dati) {
|
|
const tr = document.createElement('tr');
|
|
tr.id = `row-${dati.id}`;
|
|
|
|
const badgeDir = dati.direzione === "RX" ? "badge-rx" : "badge-tx";
|
|
const statoHtml = dati.stato === "ON"
|
|
? `<span class="badge bg-primary pulsing">In Trasmissione</span>`
|
|
: `<span class="badge bg-secondary">Terminata</span>`;
|
|
|
|
const durata = dati.durata ? `${dati.durata}s` : `<span class="spinner-grow spinner-grow-sm text-light" role="status"></span>`;
|
|
|
|
tr.innerHTML = `
|
|
<td class="text-secondary">${formattaOrario(dati.inizio)}</td>
|
|
<td><span class="badge ${badgeDir} px-2 py-1">${dati.direzione}</span></td>
|
|
<td class="fw-bold text-light">${dati.mittente}</td>
|
|
<td class="text-info">${dati.destinatario}</td>
|
|
<td id="durata-${dati.id}">${durata}</td>
|
|
<td id="stato-${dati.id}">${statoHtml}</td>
|
|
`;
|
|
return tr;
|
|
}
|
|
|
|
async function caricaStorico() {
|
|
try {
|
|
const res = await fetch(`http://${SERVER_IP}:${WS_PORT}/api/storico`);
|
|
const data = await res.json();
|
|
|
|
tbodyStorico.innerHTML = "";
|
|
data.attive.forEach(call => tbodyStorico.appendChild(creaRiga(call)));
|
|
data.storico.forEach(call => tbodyStorico.appendChild(creaRiga(call)));
|
|
|
|
disegnaEstensioni(data.estensioni);
|
|
} catch (err) { console.error("Errore caricamento storico:", err); }
|
|
}
|
|
|
|
function avviaWebSocket() {
|
|
const ws = new WebSocket(`ws://${SERVER_IP}:${WS_PORT}/ws`);
|
|
|
|
ws.onopen = () => {
|
|
statusBadge.textContent = "Connesso (Live)";
|
|
statusBadge.className = "badge bg-success text-white fs-6";
|
|
caricaStorico();
|
|
};
|
|
|
|
ws.onclose = () => {
|
|
statusBadge.textContent = "Disconnesso - Riconnessione...";
|
|
statusBadge.className = "badge bg-danger text-white fs-6";
|
|
setTimeout(avviaWebSocket, 3000);
|
|
};
|
|
|
|
ws.onmessage = (event) => {
|
|
const msg = JSON.parse(event.data);
|
|
|
|
if (msg.evento === "estensioni_update") {
|
|
caricaEstensioni();
|
|
return;
|
|
}
|
|
|
|
const dati = msg.dati;
|
|
if (msg.evento === "chiamata_iniziata") {
|
|
tbodyStorico.insertBefore(creaRiga(dati), tbodyStorico.firstChild);
|
|
if (tbodyStorico.children.length > 100) tbodyStorico.lastChild.remove();
|
|
}
|
|
else if (msg.evento === "chiamata_terminata") {
|
|
const rigaEx = document.getElementById(`row-${dati.id}`);
|
|
if (rigaEx) {
|
|
document.getElementById(`durata-${dati.id}`).textContent = `${dati.durata}s`;
|
|
document.getElementById(`stato-${dati.id}`).innerHTML = `<span class="badge bg-secondary">Terminata</span>`;
|
|
} else {
|
|
tbodyStorico.insertBefore(creaRiga(dati), tbodyStorico.firstChild);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
avviaWebSocket();
|
|
</script>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|