mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-16 14:34:45 -06:00
Network list node deletion works
This commit is contained in:
parent
07f82661f8
commit
c3e7c84e02
@ -1056,6 +1056,7 @@
|
||||
html += " <button class='btn btn-sm btn-secondary' onclick='promoteNode(\"" + key + "\") '><i class='fa fa-arrow-left'></i> Promote</button>";
|
||||
}
|
||||
html += " <button class='btn btn-sm btn-secondary' onclick='renameNode(\"" + key + "\") '><i class='fa fa-pencil'></i> Rename</button>";
|
||||
html += " <button class='btn btn-sm btn-warning' onclick='deleteNode(\"" + key + "\") '><i class='fa fa-trash'></i> Delete</button>";
|
||||
html += "<br />";
|
||||
html += "Download: <input type='number' value='" + value.downloadBandwidthMbps + "'></input><br />";
|
||||
html += "Upload: <input type='number' value='" + value.uploadBandwidthMbps + "'></input><br />";
|
||||
@ -1133,9 +1134,76 @@
|
||||
RenderNetworkJson();
|
||||
}
|
||||
|
||||
function deleteNode(nodeId) {
|
||||
if (!confirm("Are you sure you want to delete " + nodeId + "? All child nodes will also be deleted.")) {
|
||||
return;
|
||||
}
|
||||
let deleteList = [ nodeId ];
|
||||
let deleteParent = "";
|
||||
|
||||
// Find the node to delete
|
||||
function iterate(tree, depth, parent) {
|
||||
for (const [key, value] of Object.entries(tree)) {
|
||||
if (key === nodeId) {
|
||||
// Find nodes that will go away
|
||||
if (value.children != null) {
|
||||
iterateTargets(value.children, depth+1);
|
||||
}
|
||||
deleteParent = parent;
|
||||
delete tree[key];
|
||||
}
|
||||
|
||||
if (value.children != null) {
|
||||
iterate(value.children, depth+1, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function iterateTargets(tree, depth) {
|
||||
for (const [key, value] of Object.entries(tree)) {
|
||||
deleteList.push(key);
|
||||
|
||||
if (value.children != null) {
|
||||
iterateTargets(value.children, depth+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find the nodes to delete and erase them
|
||||
iterate(network_json, "");
|
||||
|
||||
// Now we have a list in deleteList of all the nodes that were deleted
|
||||
// We need to go through ShapedDevices and re-parent devices
|
||||
console.log(deleteParent);
|
||||
if (deleteParent == null) {
|
||||
// We deleted something at the top of the tree, so there's no
|
||||
// natural parent! So we'll set them to be at the root. That's
|
||||
// only really the right answer if the user went "flat" - but there's
|
||||
// no way to know. So they'll have to fix some validation themselves.
|
||||
for (let i=0; i<shaped_devices.length; i++) {
|
||||
let sd = shaped_devices[i];
|
||||
if (deleteList.indexOf(sd.parent_node) > -1) {
|
||||
sd.parent_node = "";
|
||||
}
|
||||
}
|
||||
alert("Because there was no obvious parent, you may have to fix some parenting in your Shaped Devices list.");
|
||||
} else {
|
||||
// Move everything up the tree
|
||||
for (let i=0; i<shaped_devices.length; i++) {
|
||||
let sd = shaped_devices[i];
|
||||
if (deleteList.indexOf(sd.parent_node) > -1) {
|
||||
sd.parent_node = deleteParent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the display
|
||||
RenderNetworkJson();
|
||||
shapedDevices();
|
||||
}
|
||||
|
||||
function renameNode(nodeId) {
|
||||
let newName = prompt("New node name?");
|
||||
console.log(newName);
|
||||
|
||||
function iterate(tree, depth) {
|
||||
for (const [key, value] of Object.entries(tree)) {
|
||||
|
Loading…
Reference in New Issue
Block a user