feat(logs): limite configurabile e selettore righe Last Heard con i18n

Aggiunto il supporto per definire il numero di righe del Last Heard tramite configurazione (config.json) e query string (?limit=). Inserito nel frontend un selettore a tendina con persistenza in localStorage ed etichetta bilingue (IT/EN).
This commit is contained in:
2026-10-25 11:54:20 +01:00
parent 69308c4580
commit efca23c64f
5 changed files with 42 additions and 6 deletions
+2 -1
View File
@@ -39,5 +39,6 @@
"nxdn": "https://radioid.net/static/nxdn.csv" "nxdn": "https://radioid.net/static/nxdn.csv"
}, },
"log_max_mb": 50, "log_max_mb": 50,
"log_backup_count": 10 "log_backup_count": 10,
"last_heard_limit": 60
} }
+11 -1
View File
@@ -47,10 +47,20 @@ def get_clients():
@api_bp.route('/api/logs') @api_bp.route('/api/logs')
def get_logs(): def get_logs():
# 1. Recupera il valore da config.json (default: 60)
cfg_limit = config.get("last_heard_limit", 60)
# 2. Se il client passa ?limit=, usa quello (validato tra 10 e 300 righe)
try:
limit = int(request.args.get('limit', cfg_limit))
limit = max(10, min(limit, 300))
except (ValueError, TypeError):
limit = cfg_limit
conn = sqlite3.connect(DB_PATH, timeout=10) conn = sqlite3.connect(DB_PATH, timeout=10)
c = conn.cursor() c = conn.cursor()
c.execute("""SELECT timestamp, client_id, protocol, source_id, target, slot, duration, ber, source_ext, rssi, source_conn, ysf_mode c.execute("""SELECT timestamp, client_id, protocol, source_id, target, slot, duration, ber, source_ext, rssi, source_conn, ysf_mode
FROM radio_logs ORDER BY id DESC LIMIT 60""") FROM radio_logs ORDER BY id DESC LIMIT ?""", (limit,))
logs = c.fetchall() logs = c.fetchall()
conn.close() conn.close()
return jsonify(logs) return jsonify(logs)
+13 -1
View File
@@ -206,6 +206,11 @@ async function initUI() {
statSelect.innerHTML = opts; statSelect.innerHTML = opts;
} }
const limitSel = document.getElementById('log-limit-select');
if (limitSel) {
limitSel.value = localStorage.getItem('fleetLogLimit') || '60';
}
const grid = document.getElementById('client-grid'); const grid = document.getElementById('client-grid');
const authContainer = document.getElementById('auth-container'); const authContainer = document.getElementById('auth-container');
const role = me.role || ''; const role = me.role || '';
@@ -734,9 +739,16 @@ if (isOnline) {
} catch (e) { console.error(e); } } catch (e) { console.error(e); }
} }
function changeLogLimit(val) {
localStorage.setItem('fleetLogLimit', val);
refreshLogs();
}
async function refreshLogs() { async function refreshLogs() {
try { try {
const res = await fetch('/api/logs'); const logs = await res.json(); const savedLimit = localStorage.getItem('fleetLogLimit') || '';
const url = savedLimit ? `/api/logs?limit=${encodeURIComponent(savedLimit)}` : '/api/logs';
const res = await fetch(url); const logs = await res.json();
const tbody = document.getElementById('log-body'); let tableHTML = ""; let networkLogs = {}; const tbody = document.getElementById('log-body'); let tableHTML = ""; let networkLogs = {};
logs.forEach(row => { logs.forEach(row => {
const time = row[0] ? row[0].split(' ')[1] : "--:--"; const time = row[0] ? row[0].split(' ')[1] : "--:--";
+2
View File
@@ -1,6 +1,7 @@
// --- SISTEMA TRADUZIONI (i18n) & HELPERS --- // --- SISTEMA TRADUZIONI (i18n) & HELPERS ---
const i18n = { const i18n = {
en: { en: {
lblLogLimit: "Rows:",
lastTransits: "Lastheard", loginTitle: "🔒 System Login", lastTransits: "Lastheard", loginTitle: "🔒 System Login",
thTime: "Time", thRep: "Repeater", thMode: "Mode", thCall: "Callsign", thDur: "Duration", thTime: "Time", thRep: "Repeater", thMode: "Mode", thCall: "Callsign", thDur: "Duration",
thUser: "User", thRole: "Role", thNodes: "Nodes", thActs: "Actions", thUser: "User", thRole: "Role", thNodes: "Nodes", thActs: "Actions",
@@ -31,6 +32,7 @@ const i18n = {
filtAll: "All Nodes", filtOnline: "Online", filtOffline: "Offline", filtAlerts: "⚠️ Alerts" filtAll: "All Nodes", filtOnline: "Online", filtOffline: "Offline", filtAlerts: "⚠️ Alerts"
}, },
it: { it: {
lblLogLimit: "Righe:",
lastTransits: "Ultimi ascolti", loginTitle: "🔒 Login di Sistema", lastTransits: "Ultimi ascolti", loginTitle: "🔒 Login di Sistema",
thTime: "Ora", thRep: "Ripetitore", thMode: "Modo", thCall: "Nominativo", thDur: "Durata", thTime: "Ora", thRep: "Ripetitore", thMode: "Modo", thCall: "Nominativo", thDur: "Durata",
thUser: "Utente", thRole: "Ruolo", thNodes: "Nodi", thActs: "Azioni", thUser: "Utente", thRole: "Ruolo", thNodes: "Nodi", thActs: "Azioni",
+11
View File
@@ -84,10 +84,21 @@
<h3 style="margin: 0; font-weight: 800; display: flex; align-items: center; gap: 10px; color: var(--text-main);"> <h3 style="margin: 0; font-weight: 800; display: flex; align-items: center; gap: 10px; color: var(--text-main);">
<span style="font-size: 1.5rem;">📡</span> <span data-i18n="lastTransits">Lastheard</span> <span style="font-size: 1.5rem;">📡</span> <span data-i18n="lastTransits">Lastheard</span>
</h3> </h3>
<div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap;">
<div style="display: flex; align-items: center; gap: 6px;">
<label for="log-limit-select" data-i18n="lblLogLimit" style="font-size: 0.8rem; color: var(--text-muted); font-weight: 600;">Righe:</label>
<select id="log-limit-select" onchange="changeLogLimit(this.value)" style="font-weight: bold; cursor: pointer; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border-color); background: rgba(0,0,0,0.2); color: var(--text-main);">
<option value="30">30</option>
<option value="60">60</option>
<option value="100">100</option>
<option value="200">200</option>
</select>
</div>
<select id="stat-node-filter" onchange="refreshStats(); refreshLogs();" style="font-weight: bold; cursor: pointer;"> <select id="stat-node-filter" onchange="refreshStats(); refreshLogs();" style="font-weight: bold; cursor: pointer;">
<option value="all">🌐 ALL NODES</option> <option value="all">🌐 ALL NODES</option>
</select> </select>
</div> </div>
</div>
<div class="table-container" style="margin-bottom: 0;"> <div class="table-container" style="margin-bottom: 0;">
<table> <table>
<thead> <thead>