From b2fe6780ac6885d6c11fb08406d8a347bd5b4bb6 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 18 Jan 2022 11:39:37 +0100 Subject: [PATCH] Fixed links in networkmaps --- .../functions_pandora_networkmap.js | 32 ++++++++++++++++--- .../agentes/pandora_networkmap.view.php | 18 +++++------ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/javascript/functions_pandora_networkmap.js b/pandora_console/include/javascript/functions_pandora_networkmap.js index 262c31f860..fb88c9f3e5 100644 --- a/pandora_console/include/javascript/functions_pandora_networkmap.js +++ b/pandora_console/include/javascript/functions_pandora_networkmap.js @@ -683,10 +683,10 @@ function update_link(row_index, id_link) { temp_link["text_end"] = data["text_end"]; $.each(graph.nodes, function(k, node) { - if (node["id_agent"] == data["id_db_target"]) { + if (node["id_db"] == data["id_db_target"]) { temp_link["target"] = graph.nodes[k]; } - if (node["id_agent"] == data["id_db_source"]) { + if (node["id_db"] == data["id_db_source"]) { temp_link["source"] = graph.nodes[k]; } }); @@ -703,9 +703,21 @@ function update_link(row_index, id_link) { .append("g") .attr("id", "layer_graph_nodes_" + networkmap_id); + var graph_links_aux = graph.links.filter(function(d, i) { + if (typeof d["source"] === "undefined") { + return false; + } + + if (typeof d["target"] === "undefined") { + return false; + } + + return d; + }); + force .nodes(graph.nodes) - .links(graph.links) + .links(graph_links_aux) .start(); window.node = layer_graph_nodes.selectAll(".node"); @@ -2353,9 +2365,21 @@ function refresh_holding_area() { .append("g") .attr("id", "layer_graph_nodes_" + networkmap_id); + var graph_links_aux = graph.links.filter(function(d, i) { + if (typeof d["source"] === "undefined") { + return false; + } + + if (typeof d["target"] === "undefined") { + return false; + } + + return d; + }); + force .nodes(graph.nodes) - .links(graph.links) + .links(graph_links_aux) .start(); window.node = layer_graph_nodes.selectAll(".node"); diff --git a/pandora_console/operation/agentes/pandora_networkmap.view.php b/pandora_console/operation/agentes/pandora_networkmap.view.php index 3b29b6317f..7747c0cbdc 100644 --- a/pandora_console/operation/agentes/pandora_networkmap.view.php +++ b/pandora_console/operation/agentes/pandora_networkmap.view.php @@ -1026,12 +1026,12 @@ if (is_ajax() === true) { // Source_value is id_agente. $source_text = ''; $source_agent = $interface_source; - $source_type = NODE_AGENT; + $source_type = ($interface_source == 0) ? NODE_PANDORA : NODE_AGENT; $source_link_value = $source_agent; } // Search node id in map. - $child_id = db_get_value_filter( + $parent_id = db_get_value_filter( 'id', 'titem', [ @@ -1073,7 +1073,7 @@ if (is_ajax() === true) { } // Search node id in map. - $parent_id = db_get_value_filter( + $child_id = db_get_value_filter( 'id', 'titem', [ @@ -1089,10 +1089,10 @@ if (is_ajax() === true) { $link['id_item'] = 0; $link['deleted'] = 0; $link['id_map'] = $networkmap_id; - $link['parent_type'] = $target_type; - $link['id_parent_source_data'] = $target_link_value; - $link['child_type'] = $source_type; - $link['id_child_source_data'] = $source_link_value; + $link['parent_type'] = $source_type; + $link['id_parent_source_data'] = $source_link_value; + $link['child_type'] = $target_type; + $link['id_child_source_data'] = $target_link_value; $insert_result = db_process_sql_insert('trel_item', $link); @@ -1123,8 +1123,8 @@ if (is_ajax() === true) { $return['text_start'] = $source_text; $return['text_end'] = $target_text; $return['id_db_link'] = $insert_result; - $return['id_db_source'] = $source_agent; - $return['id_db_target'] = $target_agent; + $return['id_db_source'] = $parent_id; + $return['id_db_target'] = $child_id; $return['type_source'] = $source_type; $return['type_target'] = $target_type; } else {