diff --git a/templates/map.html b/templates/map.html index 1322ef4..891a5dc 100644 --- a/templates/map.html +++ b/templates/map.html @@ -15,33 +15,44 @@ var map = L.map('map').setView([0, 0], 2); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map); let myCoords = null; + const today = new Date(); - const getNodeDesc = (node) =>{ + const daysSince = (test) => { + if (test) { + const diffTime = Math.abs(test.getTime() - today.getTime()); + const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); + return diffDays; + } + return "N/A" + + } + + const getNodeDesc = (node) => { const deviceMetrics = node?.deviceMetrics const hopsAway = node?.hopsAway ?? 'N/A'; - const lastHeard = node?.lastHeard; + const lastHeard = node?.lastHeard ? new Date(node?.lastHeard * 1000) : null const num = node?.num; const position = node?.position; const snr = node?.snr ?? 'N/A'; const user = node?.user; const lat = position?.latitude - const lon = position?.longitude return ` - Id: ${user.id}
- Hops Away: ${hopsAway}
+ ${user.id}
+ ${user.shortName}
+ ${hopsAway} hop
S/N: ${snr} dbM
- Loc: ${lat}, ${lon} + Last Heard: ${daysSince(lastHeard)} days ` } - const updateNodes= async() => { + const updateNodes = async () => { const res = await fetch('/nodes'); const json = await res.json(); const myNodeId = json['myNodeId'] // const myNodeNum = json['myNodeNum'] const nodes = json['nodes'] - + let myNode = null; // const my // Object.entries(nodes).forEach() @@ -71,7 +82,7 @@ } }) - + } updateNodes(); center();