Skip to content

Commit

Permalink
Added ID to edges so we know when to add/remove them (librenms#16816)
Browse files Browse the repository at this point in the history
* Added ID to edges so we know when to add/remove them

* Remove edges from the device dependency map if the dependency disappears
  • Loading branch information
eskyuu authored Dec 5, 2024
1 parent 7f15280 commit 41cbd87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion resources/views/map/device-dependency.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ function deviceSort(a,b) {
return (data[a]["sname"] > data[b]["sname"]) ? 1 : -1;
}
// Keep track of all edges so we know if any go missing
all_edges = [];
var keys = Object.keys(data).sort(deviceSort);
$.each( keys, function( dev_idx, device_id ) {
var device = data[device_id];
Expand Down Expand Up @@ -172,10 +175,12 @@ function deviceSort(a,b) {
}
$.each( device["parents"], function( parent_idx, parent_id ) {
link_id = device_id + "." + parent_id;
all_edges[link_id] = null;
if (!network_edges.get(link_id)) {
network_edges.add([{from: device_id, to: parent_id, width: 2}]);
network_edges.add([{id: link_id, from: device_id, to: parent_id, width: 2}]);
}
})
})
// Initialise map if we haven't already. If we do it earlier, the radom seeding doesn not work
Expand Down Expand Up @@ -208,13 +213,21 @@ function deviceSort(a,b) {
}
});
} else {
// Remove any nodes that have disappeared
$.each( network_nodes.getIds(), function( dev_idx, device_id ) {
if (!(device_id in data)) {
network_nodes.remove(device_id);
var option_id = "#highlight-device-" + device_id;
$(option_id).remove();
}
});
// Remove any edges that have disappeared
$.each( network_edges.getIds(), function( link_idx, link_id ) {
if (!(link_id in all_edges)) {
network_edges.remove(link_id);
}
});
}
$("#alert").text("");
Expand Down
1 change: 1 addition & 0 deletions resources/views/map/netmap.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ function highlightSelectedNode() {
success: function (data) {
$.each( data, function( link_id, link ) {
var this_edge = link['style'];
this_edge['id'] = link_id;
this_edge['from'] = link['ldev'];
this_edge['to'] = link['rdev'];
this_edge['label'] = link['ifnames'];
Expand Down

0 comments on commit 41cbd87

Please sign in to comment.