diff --git a/config.json.example b/config.json.example index feefa15..2a39ba6 100644 --- a/config.json.example +++ b/config.json.example @@ -39,5 +39,6 @@ "nxdn": "https://radioid.net/static/nxdn.csv" }, "log_max_mb": 50, - "log_backup_count": 10 + "log_backup_count": 10, + "last_heard_limit": 60 } diff --git a/routes/api_routes.py b/routes/api_routes.py index 4807152..eec417e 100644 --- a/routes/api_routes.py +++ b/routes/api_routes.py @@ -47,10 +47,20 @@ def get_clients(): @api_bp.route('/api/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) c = conn.cursor() 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() conn.close() return jsonify(logs) diff --git a/static/js/app.js b/static/js/app.js index 4b4e2c2..daf16be 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -206,6 +206,11 @@ async function initUI() { 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 authContainer = document.getElementById('auth-container'); const role = me.role || ''; @@ -734,9 +739,16 @@ if (isOnline) { } catch (e) { console.error(e); } } +function changeLogLimit(val) { + localStorage.setItem('fleetLogLimit', val); + refreshLogs(); +} + async function refreshLogs() { 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 = {}; logs.forEach(row => { const time = row[0] ? row[0].split(' ')[1] : "--:--"; diff --git a/static/js/modals.js b/static/js/modals.js index 64d7d84..ff368aa 100644 --- a/static/js/modals.js +++ b/static/js/modals.js @@ -1,6 +1,7 @@ // --- SISTEMA TRADUZIONI (i18n) & HELPERS --- const i18n = { en: { + lblLogLimit: "Rows:", lastTransits: "Lastheard", loginTitle: "🔒 System Login", thTime: "Time", thRep: "Repeater", thMode: "Mode", thCall: "Callsign", thDur: "Duration", thUser: "User", thRole: "Role", thNodes: "Nodes", thActs: "Actions", @@ -31,6 +32,7 @@ const i18n = { filtAll: "All Nodes", filtOnline: "Online", filtOffline: "Offline", filtAlerts: "⚠️ Alerts" }, it: { + lblLogLimit: "Righe:", lastTransits: "Ultimi ascolti", loginTitle: "🔒 Login di Sistema", thTime: "Ora", thRep: "Ripetitore", thMode: "Modo", thCall: "Nominativo", thDur: "Durata", thUser: "Utente", thRole: "Ruolo", thNodes: "Nodi", thActs: "Azioni", diff --git a/templates/index.html b/templates/index.html index 792ae90..3377fb8 100644 --- a/templates/index.html +++ b/templates/index.html @@ -84,9 +84,20 @@