diff --git a/pandora_console/include/javascript/map/MapController.js b/pandora_console/include/javascript/map/MapController.js index 05ee7d7c85..4018817bbc 100644 --- a/pandora_console/include/javascript/map/MapController.js +++ b/pandora_console/include/javascript/map/MapController.js @@ -592,18 +592,13 @@ MapController.prototype.nodeGetDetails = function(data_id, type, id_map, data_gr MapController.prototype.deleteNode = function(self, target) { var id_node = d3.select(target).attr("id"); var arrowsToDelete = self.getArrows(self, id_node); - $.each(nodes, function(i, e) { - var node = "node_" + e["graph_id"]; - if (node == id_node) { - nodes.splice(i, 1); - return false; - } - }); - self.deleteEdges(arrowsToDelete); + // Delete edges and nodes in "nodes" and "edges" arrays + self.deleteEdgesAndNode(arrowsToDelete, id_node); - $.each(arrowsToDelete, function(i, e) { - d3.select("#arrow_" + e).remove(); + // Delete visual edges and nodes + arrowsToDelete.forEach(function(arrow) { + d3.select("#arrow_" + arrow).remove(); }); d3.select(target).remove(); } @@ -613,7 +608,7 @@ MapController.prototype.deleteNode = function(self, target) { * Return void * This function delete the edges of a node in the edges array */ -MapController.prototype.deleteEdges = function(arrowsToDelete) { +MapController.prototype.deleteEdgesAndNode = function(arrowsToDelete, id_node) { var newEdges = []; arrowsToDelete.forEach(function(arrow) { @@ -627,9 +622,10 @@ MapController.prototype.deleteEdges = function(arrowsToDelete) { }); arrowsToDelete.forEach(function(arrow) { - nodes.forEach(function(edge) { - if (edge["graph_id"] != arrow) { - newEdges.push(edge); + nodes.forEach(function(nodeOrEdge) { + var nodeToDel = "node_" + nodeOrEdge["graph_id"]; + if ((nodeOrEdge["graph_id"] != arrow) && (nodeToDel != id_node)) { + newEdges.push(nodeOrEdge); } }); nodes = newEdges; @@ -645,14 +641,15 @@ MapController.prototype.deleteEdges = function(arrowsToDelete) { MapController.prototype.getArrows = function(self, id_node) { var edgesToDel = []; var j = 0; - $.each(edges, function(i, e) { - var nodeTo = "node_" + e["to"]; - var nodeFrom = "node_" + e["from"]; - if (nodeTo == id_node ||nodeFrom == id_node) { - edgesToDel[j] = e["graph_id"]; - j++; + + edges.forEach(function(edge, index) { + var nodeTo = "node_" + edge["to"]; + var nodeFrom = "node_" + edge["from"]; + if (nodeTo == id_node || nodeFrom == id_node) { + edgesToDel[index] = edge["graph_id"]; } }); + return edgesToDel; }