Allow native SYSOP accounts to sign in independently, with an optional sysopUsers allow-list and isolated browser sessions. Keep station services on the configured service account. Add public bulletin comments that preserve category and distribution, alongside private replies to the author. Complete APRS and dynamic status translations and handle decorated button labels correctly. Document configuration and reply behavior. Add authentication, installer, bulletin reply and translation regression coverage.
63 lines
12 KiB
JavaScript
63 lines
12 KiB
JavaScript
(()=>{
|
|
const section=$('#aprs'),form=$('#aprs-form'),heading=form.querySelector('.page-heading');section.prepend(heading);$('#aprs-save').setAttribute('form','aprs-form');
|
|
const tabs=document.createElement('div');tabs.className='aprs-view-tabs';tabs.setAttribute('role','tablist');tabs.setAttribute('aria-label','Viste APRS');tabs.innerHTML='<button role="tab" aria-selected="true" data-aprs-view="activity">Attività</button><button role="tab" aria-selected="false" data-aprs-view="config">Configurazione</button>';heading.after(tabs);
|
|
const pane=document.createElement('section');pane.className='aprs-activity-pane';pane.innerHTML='<div class="aprs-activity-toolbar"><span id="aprs-live-state" class="tag">Collegamento…</span><select id="aprs-source" aria-label="Origine APRS"><option value="Radio">Radio</option><option value="">Radio + Internet</option><option value="Internet">Internet</option></select><select id="aprs-direction" aria-label="Direzione APRS"><option value="">RX + TX</option><option value="RX">RX</option><option value="TX">TX</option></select><input id="aprs-search" type="search" placeholder="Cerca nominativo o testo…" aria-label="Cerca APRS"><button class="secondary" id="aprs-activity-pause">Pausa vista</button><button class="secondary" id="aprs-activity-refresh">↻ Aggiorna</button></div><div class="aprs-activity-kpis" id="aprs-activity-kpis"></div><div class="aprs-map-layout"><article class="card aprs-map-card"><header><div><h2>Stazioni ricevute</h2><span id="aprs-map-count"></span></div><button class="secondary" id="aprs-map-fit">Centra stazioni</button></header><div id="aprs-station-map" aria-label="Mappa stazioni APRS"></div><footer><span class="aprs-legend radio">Radio</span><span class="aprs-legend internet">Internet</span><span class="aprs-legend own">La tua stazione</span></footer></article><aside class="card aprs-stations-card"><header><h2>Ultime ricezioni</h2></header><div id="aprs-received-stations"></div></aside></div><article class="card aprs-traffic-card"><header><h2>Traffico APRS</h2><span id="aprs-traffic-count"></span></header><div class="aprs-traffic-scroll"><table class="aprs-traffic-table"><thead><tr><th>Data e ora</th><th>Direzione</th><th>Trasporto</th><th>Da → A</th><th>Tipo / pacchetto</th></tr></thead><tbody id="aprs-traffic-rows"></tbody></table></div><footer><details><summary>Dettagli del registro</summary><p id="aprs-traffic-scope"></p></details></footer></article><div class="aprs-activity-status" id="aprs-activity-status" role="status"></div>';
|
|
tabs.after(pane);let view='activity',data=null,loading=false,starting=false,paused=false,map=null,layers=null,markers=new Map(),ownMarker=null,fitted=false,selected=null,selectedEvent=null;
|
|
const snapshots=new WeakMap();
|
|
function markup(selector,html){const el=$(selector);if(snapshots.get(el)===html)return;snapshots.set(el,html);el.innerHTML=html;}
|
|
const time=t=>t?new Date(t).toLocaleString(BPQI18n.locale(),{day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit'}):'—';
|
|
const type=t=>({position:'Posizione',message:'Messaggio',status:'Stato',object:'Oggetto APRS',weather:'Meteo',telemetry:'Telemetria','third-party':'Messaggio inoltrato',query:'Richiesta'}[t]||t);
|
|
const source=()=>$('#aprs-source').value,query=()=>$('#aprs-search').value.trim().toUpperCase();
|
|
const stations=()=>data?.stations.filter(s=>(!source()||s.transport===source()||source()==='Radio'&&s.heardRadio)&&(!query()||(s.call+' '+s.status+' '+s.lastBody).toUpperCase().includes(query())))||[];
|
|
function setView(next){view=next;form.hidden=next!=='config';pane.hidden=next!=='activity';$('#aprs-save').hidden=next!=='config';tabs.querySelectorAll('button').forEach(b=>b.setAttribute('aria-selected',String(b.dataset.aprsView===next)));if(next==='activity'&&page==='aprs'){start();requestAnimationFrame(()=>map?.invalidateSize({pan:false}));}}
|
|
tabs.onclick=e=>{const next=e.target.closest('[data-aprs-view]')?.dataset.aprsView;if(next)setView(next);};
|
|
function popup(s){return '<div class="aprs-map-popup"><b>'+esc(s.call)+'</b><span>'+esc(s.transport)+(s.port?' · Port '+s.port:'')+'</span><span>'+esc(time(s.lastAt))+'</span><span>'+s.position.lat.toFixed(5)+', '+s.position.lon.toFixed(5)+'</span><p>'+esc(s.status||s.lastBody||'')+'</p><small>'+esc(s.path||'')+'</small></div>';}
|
|
function initMap(){if(map||!window.L)return;map=L.map('aprs-station-map',{zoomControl:true,scrollWheelZoom:true}).setView([25,0],2);L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png',{maxZoom:19,referrerPolicy:'origin',attribution:'© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors'}).addTo(map);layers=L.layerGroup().addTo(map);if(typeof ResizeObserver!=='undefined')new ResizeObserver(()=>{if(page==='aprs'&&view==='activity')map.invalidateSize({pan:false});}).observe($('#aprs-station-map'));}
|
|
function fit(){if(!map)return;const positions=stations().filter(s=>s.position).map(s=>[s.position.lat,s.position.lon]);if(data?.own.position)positions.push([data.own.position.lat,data.own.position.lon]);if(positions.length)map.fitBounds(L.latLngBounds(positions),{padding:[38,38],maxZoom:13});}
|
|
function renderMap(){
|
|
if(page!=='aprs'||view!=='activity')return;
|
|
initMap();if(!map)return;
|
|
const list=stations(),visible=new Set();
|
|
for(const s of list){
|
|
if(!s.position)continue;
|
|
visible.add(s.call);
|
|
const color=s.transport==='Radio'?'#6fd4b1':'#81b9f4',point=[s.position.lat,s.position.lon],html=popup(s);
|
|
let marker=markers.get(s.call);
|
|
if(!marker){
|
|
marker=L.circleMarker(point,{radius:7,color:'#0b1723',weight:2,fillColor:color,fillOpacity:.96})
|
|
.bindTooltip(esc(s.call),{direction:'top',offset:[0,-6]})
|
|
.bindPopup(html,{autoPan:false});
|
|
marker.on('click',()=>{selected=s.call;renderStations();});
|
|
marker.addTo(layers);markers.set(s.call,marker);
|
|
}else{
|
|
const current=marker.getLatLng();
|
|
if(current.lat!==point[0]||current.lng!==point[1])marker.setLatLng(point);
|
|
if(marker.options.fillColor!==color)marker.setStyle({fillColor:color});
|
|
if(marker.getPopup().getContent()!==html)marker.setPopupContent(html);
|
|
}
|
|
}
|
|
for(const [call,marker]of markers)if(!visible.has(call)){layers.removeLayer(marker);markers.delete(call);}
|
|
const own=data?.own;
|
|
if(own?.position){
|
|
const point=[own.position.lat,own.position.lon],label=esc(own.call)+' · '+BPQI18n.t('La tua stazione');
|
|
if(!ownMarker)ownMarker=L.circleMarker(point,{radius:10,color:'#efcf89',weight:2,fillColor:'#efcf89',fillOpacity:.3}).bindTooltip(label).addTo(layers);
|
|
else{const current=ownMarker.getLatLng();if(current.lat!==point[0]||current.lng!==point[1])ownMarker.setLatLng(point);if(ownMarker.getTooltip().getContent()!==label)ownMarker.setTooltipContent(label);}
|
|
}else if(ownMarker){layers.removeLayer(ownMarker);ownMarker=null;}
|
|
$('#aprs-map-count').textContent=visible.size+' '+BPQI18n.t('sulla mappa')+' · '+(list.length-visible.size)+' '+BPQI18n.t('senza posizione');
|
|
if(!fitted&&(visible.size||own?.position)){fit();fitted=true;}
|
|
}
|
|
function renderStations(){const list=stations();markup('#aprs-received-stations',list.map(s=>'<button data-aprs-station="'+esc(s.call)+'" class="aprs-received-station '+(s.call===selected?'selected':'')+'"><span><b>'+esc(s.call)+'</b><i class="aprs-source-dot '+s.transport.toLowerCase()+'"></i></span><small>'+esc(s.transport)+(s.port?' · Port '+s.port:'')+' · '+esc(time(s.lastAt))+'</small><p>'+esc(s.status||s.lastBody||'—').slice(0,170)+'</p>'+(!s.position?'<small>Senza posizione</small>':'')+'</button>').join('')||'<p class="empty">Nessuna stazione ricevuta con questi filtri.</p>');}
|
|
function render(){if(!data)return;const events=data.events.filter(e=>(!source()||e.transport===source())&&(!$('#aprs-direction').value||e.direction===$('#aprs-direction').value)&&(!query()||(e.packet+' '+e.from).toUpperCase().includes(query()))).slice().reverse();
|
|
$('#aprs-live-state').textContent=paused?'Vista in pausa':data.monitor==='online'?'● APRS in tempo reale':'Monitor '+data.monitor;
|
|
markup('#aprs-activity-kpis',[['Radio RX',events.filter(e=>e.transport==='Radio'&&e.direction==='RX').length],['Radio TX · BPQ',events.filter(e=>e.transport==='Radio'&&e.direction==='TX').length],['Internet RX',events.filter(e=>e.transport==='Internet'&&e.direction==='RX').length],['Internet TX',events.filter(e=>e.transport==='Internet'&&e.direction==='TX').length],['Stazioni ricevute',stations().length]].map(([k,v])=>'<article><span>'+esc(k)+'</span><strong>'+v+'</strong></article>').join(''));
|
|
$('#aprs-traffic-count').textContent=events.length+' '+BPQI18n.t('pacchetti nel registro');markup('#aprs-traffic-rows',events.slice(0,400).map(e=>'<tr data-aprs-event="'+e.id+'" tabindex="0" aria-expanded="'+(selectedEvent===e.id)+'"><td>'+esc(time(e.at))+'</td><td><span class="aprs-packet-direction '+e.direction.toLowerCase()+'">'+e.direction+'</span></td><td>'+esc(e.transport)+(e.port?'<small>Port '+e.port+'</small>':'')+'</td><td><b>'+esc(e.from)+'</b><small>→ '+esc(e.to)+'</small></td><td><span class="aprs-packet-type">'+esc(type(e.type))+'</span><span class="aprs-packet-preview">'+esc(e.body.slice(0,180))+'</span></td></tr>'+(selectedEvent===e.id?'<tr class="aprs-packet-detail"><td colspan="5"><pre>'+esc(e.packet)+'</pre><small>'+esc(e.evidence)+'</small></td></tr>':'')).join('')||'<tr><td colspan="5" class="empty">In attesa di pacchetti APRS ricevuti o inviati.</td></tr>');
|
|
$('#aprs-traffic-scope').textContent=BPQI18n.t('Ultimi 2000 pacchetti · TX radio = richieste registrate da BPQ.');$('#aprs-activity-status').textContent=[...data.errors,...(!data.loggingInternet?[BPQI18n.t('Log Internet non disponibile')]:[]),BPQI18n.t('Aggiornato')+' '+time(data.updatedAt)].join(' · ');renderStations();renderMap();
|
|
}
|
|
async function start(){if(!csrf)return;if(starting||data?.started){if(data)render();return;}starting=true;try{data=await api('/aprs/activity/start',{method:'POST',body:'{}'});render();}catch(e){$('#aprs-activity-status').textContent=e.message;}finally{starting=false;}}
|
|
async function poll(background=true){if(!csrf||loading||paused||document.hidden||page!=='aprs'||view!=='activity')return;loading=true;try{const next=await api('/aprs/activity',{busy:!background});data=next;render();if(!data.started)start();}catch(e){$('#aprs-activity-status').textContent=e.message;}finally{loading=false;}}
|
|
$('#aprs-map-fit').onclick=fit;$('#aprs-activity-refresh').onclick=()=>{if(paused){render();return;}poll(false);};$('#aprs-activity-pause').onclick=()=>{paused=!paused;$('#aprs-activity-pause').textContent=paused?'Riprendi vista':'Pausa vista';if(!paused)poll();else render();};for(const id of ['aprs-source','aprs-direction','aprs-search'])$('#'+id).addEventListener(id==='aprs-search'?'input':'change',()=>{render();if(id==='aprs-source')fit();});
|
|
$('#aprs-received-stations').onclick=e=>{const call=e.target.closest('[data-aprs-station]')?.dataset.aprsStation;if(!call)return;selected=call;const marker=markers.get(call);if(marker){map.setView(marker.getLatLng(),Math.max(map.getZoom(),13));marker.openPopup();}renderStations();};
|
|
$('#aprs-traffic-rows').onclick=e=>{const row=e.target.closest('[data-aprs-event]');if(row){const id=Number(row.dataset.aprsEvent);selectedEvent=selectedEvent===id?null:id;render();}};$('#aprs-traffic-rows').onkeydown=e=>{if(['Enter',' '].includes(e.key)&&e.target.matches('[data-aprs-event]')){e.preventDefault();e.target.click();}};
|
|
const prior=navigate;navigate=function(next){prior(next);if(next==='aprs'&&view==='activity'){start();requestAnimationFrame(()=>map?.invalidateSize({pan:false}));}};document.addEventListener('station-ready',()=>{if(page==='aprs')start();});document.addEventListener('bpq-languagechange',()=>{if(data)render();});setInterval(poll,2000);setView('activity');
|
|
})();
|