Harden generic installation and startup, preserve station settings and coalesce mail reads

This commit is contained in:
alberto committed 2026-10-16 21:03:18 +02:00
1 parent 3f6d35690b
commit 5358cad695
14 files changed
+398 -146

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ function renderMap(keepInfo=false){if(!data)return;const stations=mapStations(),
svg.innerHTML=content;svg.setAttribute('viewBox',view.join(' '));$$('#station-map [data-map-call]').forEach(el=>{el.onclick=e=>{if(moved)return;e.stopPropagation();mapCall=el.dataset.mapCall;renderMap();};el.onkeydown=e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();mapCall=el.dataset.mapCall;renderMap();}};});
$('#map-station-list').innerHTML=stations.map(s=>`<button class="map-station ${mapCall===s.call?'selected':''}" data-peer="${esc(s.call)}"><b>${esc(s.call)}</b><span>${s.position?esc(s.position.locator):'+ Aggiungi locator'}</span><small>${esc(s.services.join(' · '))}</small></button>`).join('')||'<p class="empty">Nessun collegamento stabilito nel periodo selezionato.</p>';$$('[data-peer]').forEach(b=>b.onclick=()=>{mapCall=b.dataset.peer;renderMap();});if(!keepInfo)mapInfo(stations.find(s=>s.call===mapCall));}
function mapInfo(s){if(!s){$('#map-info').innerHTML=`<div class="map-info-empty"><span>◎</span><h2>Scegli una stazione.</h2><p>Clicca un punto, una traccia o un nominativo nell’elenco.</p>${!data.own.position?'<p>Il LOCATOR della stazione locale non è presente in BPQ: le tracce non possono essere disegnate.</p>':''}</div>`;return;}
const sessions=mapSessions().filter(r=>base(r.call)===s.call),latest=sessions[0];const samePosition=p=>s.position&&p&&Math.abs(p.lat-s.position.lat)<1e-8&&Math.abs(p.lon-s.position.lon)<1e-8;const colocated=mapStations().filter(other=>samePosition(other.position));const sharedLocal=samePosition(data.own.position);const shared=sharedLocal||colocated.length>1?'<div class="map-shared"><b>Stazioni nello stesso punto</b>'+(sharedLocal?'<p>'+esc(data.own.call)+' · stazione locale</p>':'')+colocated.map(other=>'<button class="secondary" data-colocated="'+esc(other.call)+'">'+esc(other.call)+'</button>').join('')+'<small>Il locator individua un’area: le posizioni effettive possono essere diverse.</small></div>':'';$('#map-info').innerHTML=`<header><span class="eyebrow">STAZIONE COLLEGATA</span><h2>${esc(s.call)}</h2><p>${s.position?esc(s.position.locator)+' · '+(s.distance==null?'Distanza non disponibile':s.distance===0?'Stesso locator del nodo':s.distance+' km dal nodo'):'Posizione non disponibile'}</p></header>${shared}<div class="map-last"><span>Ultimo collegamento nel periodo</span><b>${esc(time(latest?.startedAt))}</b><small>${esc(latest?.service||'')} · ${esc(transport(latest?.transport))} · ${esc(direction(latest?.direction))}</small></div><form id="locator-form"><label>Locator Maidenhead<input id="station-locator" name="locator" required maxlength="8" placeholder="Es. JN45NN" value="${esc(s.position?.locator||'')}"></label><button class="secondary" type="submit">Salva posizione</button><small>${esc(s.position?.source||'Inserisci il locator comunicato dalla stazione.')}</small></form><h3>${sessions.length} collegamenti nel periodo</h3><div class="map-recent">${sessions.slice(0,8).map(r=>`<button data-map-session="${esc(r.id)}"><b>${esc(r.service)} <span>${esc(duration(r.duration))}</span></b><small>${esc(time(r.startedAt))}</small><small>TX ${esc(bytes(r.txBytes))} / RX ${esc(bytes(r.rxBytes))}</small></button>`).join('')}</div>`;$$('[data-colocated]').forEach(b=>b.onclick=()=>{mapCall=b.dataset.colocated;renderMap();});$('#locator-form').onsubmit=async e=>{e.preventDefault();try{data=await api('/stations/location',{method:'POST',body:JSON.stringify({call:s.call,locator:$('#station-locator').value})});render();fit();toast('Locator salvato per '+s.call);}catch(err){toast(err.message)}};$$('[data-map-session]').forEach(b=>b.onclick=()=>{navigate('journal');detail(b.dataset.mapSession);});}
const sessions=mapSessions().filter(r=>base(r.call)===s.call),latest=sessions[0];const samePosition=p=>s.position&&p&&Math.abs(p.lat-s.position.lat)<1e-8&&Math.abs(p.lon-s.position.lon)<1e-8;const colocated=mapStations().filter(other=>samePosition(other.position));const sharedLocal=samePosition(data.own.position);const shared=sharedLocal||colocated.length>1?'<div class="map-shared"><b>Stazioni nello stesso punto</b>'+(sharedLocal?'<p>'+esc(data.own.call)+' · stazione locale</p>':'')+colocated.map(other=>'<button class="secondary" data-colocated="'+esc(other.call)+'">'+esc(other.call)+'</button>').join('')+'<small>Il locator individua un’area: le posizioni effettive possono essere diverse.</small></div>':'';$('#map-info').innerHTML=`<header><span class="eyebrow">STAZIONE COLLEGATA</span><h2>${esc(s.call)}</h2><p>${s.position?esc(s.position.locator)+' · '+(s.distance==null?'Distanza non disponibile':s.distance===0?'Stesso locator del nodo':s.distance+' km dal nodo'):'Posizione non disponibile'}</p></header>${shared}<div class="map-last"><span>Ultimo collegamento nel periodo</span><b>${esc(time(latest?.startedAt))}</b><small>${esc(latest?.service||'')} · ${esc(transport(latest?.transport))} · ${esc(direction(latest?.direction))}</small></div><form id="locator-form"><label>Locator Maidenhead<input id="station-locator" name="locator" required maxlength="8" placeholder="Es. IO91AA" value="${esc(s.position?.locator||'')}"></label><button class="secondary" type="submit">Salva posizione</button><small>${esc(s.position?.source||'Inserisci il locator comunicato dalla stazione.')}</small></form><h3>${sessions.length} collegamenti nel periodo</h3><div class="map-recent">${sessions.slice(0,8).map(r=>`<button data-map-session="${esc(r.id)}"><b>${esc(r.service)} <span>${esc(duration(r.duration))}</span></b><small>${esc(time(r.startedAt))}</small><small>TX ${esc(bytes(r.txBytes))} / RX ${esc(bytes(r.rxBytes))}</small></button>`).join('')}</div>`;$$('[data-colocated]').forEach(b=>b.onclick=()=>{mapCall=b.dataset.colocated;renderMap();});$('#locator-form').onsubmit=async e=>{e.preventDefault();try{data=await api('/stations/location',{method:'POST',body:JSON.stringify({call:s.call,locator:$('#station-locator').value})});render();fit();toast('Locator salvato per '+s.call);}catch(err){toast(err.message)}};$$('[data-map-session]').forEach(b=>b.onclick=()=>{navigate('journal');detail(b.dataset.mapSession);});}
function fit(){const points=mapStations().filter(s=>s.position).map(s=>xy(s.position));if(data?.own.position)points.push(xy(data.own.position));if(!points.length){view=[0,0,1000,500];renderMap();return;}const xs=points.map(p=>p[0]),ys=points.map(p=>p[1]);const w=Math.min(1000,Math.max(100,(Math.max(...xs)-Math.min(...xs))*1.7,(Math.max(...ys)-Math.min(...ys))*3.4)),cx=(Math.min(...xs)+Math.max(...xs))/2,cy=(Math.min(...ys)+Math.max(...ys))/2;view=[Math.max(0,Math.min(1000-w,cx-w/2)),Math.max(0,Math.min(500-w/2,cy-w/4)),w,w/2];renderMap();}
function zoom(factor,anchor){const w=Math.max(5,Math.min(1000,view[2]*factor));if(w===view[2])return;const point=anchor||{x:view[0]+view[2]/2,y:view[1]+view[3]/2},u=(point.x-view[0])/view[2],v=(point.y-view[1])/view[3];view=[Math.max(0,Math.min(1000-w,point.x-u*w)),Math.max(0,Math.min(500-w/2,point.y-v*w/2)),w,w/2];renderMap(true);}
$('#map-plus').onclick=()=>zoom(.65);$('#map-minus').onclick=()=>zoom(1.5);$('#map-fit').onclick=fit;$('#map-tracks').onchange=renderMap;for(const id of ['map-period','map-service'])$('#'+id).onchange=()=>{mapCall=null;renderMap();fit();};