diff --git a/src/index.js b/src/index.js
index a208ab2..826d773 100644
--- a/src/index.js
+++ b/src/index.js
@@ -54,15 +54,26 @@ app.get('/api/v1/nodes', async (req, res) => {
// get nodes from db
const nodes = await prisma.node.findMany();
+ const nodesWithNeighbourInfo = [];
+ for(const node of nodes){
+ nodesWithNeighbourInfo.push({
+ ...node,
+ node_id_hex: "!" + node.node_id.toString(16),
+ hardware_model_name: HardwareModel.valuesById[node.hardware_model] ?? "UNKNOWN",
+ role_name: Role.valuesById[node.role] ?? "UNKNOWN",
+ neighbour_info: await prisma.neighbourInfo.findFirst({
+ where: {
+ node_id: node.node_id,
+ },
+ orderBy: {
+ createdAt: 'desc',
+ },
+ }),
+ })
+ }
+
res.json({
- nodes: nodes.map((node) => {
- return {
- ...node,
- node_id_hex: "!" + node.node_id.toString(16),
- hardware_model_name: HardwareModel.valuesById[node.hardware_model] ?? "UNKNOWN",
- role_name: Role.valuesById[node.role] ?? "UNKNOWN",
- }
- }),
+ nodes: nodesWithNeighbourInfo,
});
} catch(err) {
diff --git a/src/public/index.html b/src/public/index.html
index 1affafb..0b53c3b 100644
--- a/src/public/index.html
+++ b/src/public/index.html
@@ -368,6 +368,18 @@
}
+ function findNodeById(id) {
+
+ // find node by id
+ var node = nodes.find((node) => node.node_id.toString() === id.toString());
+ if(node){
+ return node;
+ }
+
+ return null;
+
+ }
+
function findNodeMarkerById(id) {
// find node marker by id
@@ -557,6 +569,62 @@
}
+ for(var node of updatedNodes){
+
+ // find current node
+ const currentNode = findNodeMarkerById(node.node_id);
+ if(!currentNode){
+ continue;
+ }
+
+ // add node connections
+ const neighbours = node.neighbour_info?.neighbours ?? [];
+ console.log(neighbours);
+ for(const neighbour of neighbours){
+
+ // fixme: skipping zero snr? saw some crazy long neighbours with zero snr...
+ if(neighbour.snr === 0){
+ continue;
+ }
+
+ const neighbourNode = findNodeById(neighbour.node_id);
+ if(!neighbourNode){
+ continue;
+ }
+
+ const neighbourNodeMarker = findNodeMarkerById(neighbour.node_id);
+ if(neighbourNodeMarker){
+
+ const line = L.polyline([
+ currentNode.getLatLng(),
+ neighbourNodeMarker.getLatLng(),
+ ], {
+ color: '#2563eb',
+ opacity: 0.5,
+ }).addTo(connectionsLayerGroup);
+
+ const tooltip = `${node.long_name} heard ${neighbourNode.long_name}`
+ + `
SNR: ${neighbour.snr}dB`
+ + `
ID: ${neighbourNode.node_id} -> ${node.node_id}`
+ + `
Hex ID: ${neighbourNode.node_id_hex} -> ${node.node_id_hex}`
+ + `
Updated: ${moment(new Date(node.neighbour_info.updated_at)).fromNow()}`;
+
+ line.bindTooltip(tooltip, {
+ sticky: true,
+ opacity: 1,
+ interactive: true,
+ })
+ .bindPopup(tooltip)
+ .on('click', function(event) {
+ // close tooltip on click to prevent tooltip and popup showing at same time
+ event.target.closeTooltip();
+ });
+
+ }
+ }
+
+ }
+
}
function setLoading(loading){