Added interface links support to networkmaps. Ticket #132 GitLab

This commit is contained in:
Arturo Gonzalez 2016-12-30 08:51:31 +01:00
parent 33370bdb52
commit 71614ae81b
7 changed files with 314 additions and 28 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

View File

@ -425,28 +425,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
}
foreach ($modules_node_ref as $id_module => $node_count) {
if (! modules_relation_exists($id_module, array_keys($modules_node_ref))) {
if ($show_snmp_modules) {
$module_type = modules_get_agentmodule_type($id_module);
if ($module_type != 18) {
unset($nodes[$node_count]);
unset($orphans[$node_count]);
unset($parents[$node_count]);
}
}
else {
unset($nodes[$node_count]);
unset($orphans[$node_count]);
unset($parents[$node_count]);
}
}
else {
$module_type = modules_get_agentmodule_type($id_module);
if ($module_type != 18) {
unset($nodes[$node_count]);
unset($orphans[$node_count]);
unset($parents[$node_count]);
}
$module_type = modules_get_agentmodule_type($id_module);
if ($module_type != 18) {
unset($nodes[$node_count]);
unset($orphans[$node_count]);
unset($parents[$node_count]);
}
}

View File

@ -456,12 +456,14 @@ function networkmap_links_to_js_links($relations, $nodes_graph) {
$id_source_module = $relation['id_child_source_data'];
}
else if (($relation['parent_type'] == 1) && ($relation['child_type'] == 0)) {
$id_target_agent = agents_get_agent_id_by_module_id($relation['id_parent_source_data']);
$id_target_module = $relation['id_parent_source_data'];
$id_source_agent = $relation['id_child_source_data'];
}
else if (($relation['parent_type'] == 0) && ($relation['child_type'] == 1)) {
$id_target_agent = $relation['id_parent_source_data'];
$id_source_module = $relation['id_child_source_data'];
$id_source_agent = agents_get_agent_id_by_module_id($relation['id_child_source_data']);
}
else {
$id_target_agent = $relation['id_parent_source_data'];
@ -534,6 +536,10 @@ function networkmap_links_to_js_links($relations, $nodes_graph) {
$agent = $relation['id_parent_source_data'];
$agent2 = agents_get_agent_id_by_module_id($relation['id_child_source_data']);
}
else if ($relation['parent_type'] == 1) {
$agent = agents_get_agent_id_by_module_id($relation['id_parent_source_data']);
$agent2 = $relation['id_child_source_data'];
}
else if (($relation['parent_type'] == 3) && ($relation['child_type'] == 3)) {
foreach ($nodes_graph as $key => $node) {
if ($relation['id_parent'] == $node['id_db']) {
@ -593,7 +599,6 @@ function networkmap_links_to_js_links($relations, $nodes_graph) {
}
}
}
$return[] = $item;
}
return $return;
@ -738,6 +743,8 @@ function networkmap_write_js_array($id, $nodes_and_relations = array(), $map_das
echo "var dialog_node_edit_title = '" . __('Edit node %s') . "';\n";
echo "var holding_area_title = '" . __('Holding Area') . "';\n";
echo "var edit_menu = '" . __('Show details and options') . "';\n";
echo "var interface_link_add = '" . __('Add a interface link') . "';\n";
echo "var set_parent_link = '" . __('Set parent interface') . "';\n";
echo "var set_as_children_menu = '" . __('Set as children') . "';\n";
echo "var set_parent_menu = '" . __('Set parent') . "';\n";
echo "var abort_relationship_menu = '" . __('Abort the action of set relationship') . "';\n";
@ -746,6 +753,7 @@ function networkmap_write_js_array($id, $nodes_and_relations = array(), $map_das
echo "var set_center_menu = '" . __('Set center') . "';\n";
echo "var refresh_menu = '" . __('Refresh') . "';\n";
echo "var refresh_holding_area_menu = '" . __('Refresh Holding area') . "';\n";
echo "var abort_relationship_interface = '" . __('Abort the action of set interface relationship') . "';\n";
echo "var abort_relationship_menu = '" . __('Abort the action of set relationship') . "';\n";
echo "\n";
@ -1450,8 +1458,6 @@ if (empty($list_networkmaps))
$table->data['template_row']['node_target'] = '';
$table->data['template_row']['edit'] = "";
$table->data['template_row']['edit'] = '';
$table->data['template_row']['edit'] .=
'<span class="edit_icon_correct" style="display: none;">' .
html_print_image('images/dot_green.png', true) . '</span>' .
@ -1461,7 +1467,7 @@ if (empty($list_networkmaps))
html_print_image('images/spinner.gif', true) . '</span>' .
'<span class="edit_icon"><a class="edit_icon_link" title="' . __('Update') . '" href="#">' .
html_print_image('images/config.png', true) . '</a></span>';
$table->data['template_row']['edit'] .=
'<a class="delete_icon" href="#">' .
html_print_image('images/delete.png', true) . '</a>';
@ -1481,6 +1487,44 @@ if (empty($list_networkmaps))
</div>
</div>
<div id="dialog_interface_link" style="display: none;" title="Interface link">
<div style="text-align: left; width: 100%;">
<?php
$table = new stdClass();
$table->id = 'interface_link_table';
$table->width = "100%";
$table->head['node_source_interface'] = __('Node source');
$table->head['interface_source_select'] = __('Interface source');
$table->head['interface_target_select'] = __('Interface Target');
$table->head['node_target_interface'] = __('Node target');
$table->data = array();
$table->data['interface_row']['node_source_interface'] = html_print_label("", "node_source_interface");
$table->data['interface_row']['interface_source_select'] =
html_print_select(array(), 'interface_source_select', '', '',
__('None'), 0);
$table->data['interface_row']['interface_target_select'] =
html_print_select(array(), 'interface_target_select', '', '',
__('None'), 0);
$table->data['interface_row']['node_target_interface'] = html_print_label("", "node_target_interface");
?>
<br><br>
<?php
$table->data['interface_row']['interface_link_button'] =
html_print_button(__('Add interface link'), '', false,
'add_interface_link_js();', 'class="sub"');
html_print_table($table, true)
?>
</div>
</div>
<div id="dialog_node_add" style="display: none;" title="<?php echo __('Add node');?>">
<div style="text-align: left; width: 100%;">
<?php

View File

@ -141,7 +141,6 @@ function delete_link(source_id, source_module_id, target_id, target_module_id, i
url: action="ajax.php",
success: function (data) {
if (data['correct']) {
do {
found = -1;
@ -1495,6 +1494,38 @@ function show_menu(item, data) {
edit_node(data, false);
}
};
items_list["interface_link"] = {
name: interface_link_add,
icon: "interface_link_children",
disabled : function() {
if (enterprise_installed) {
return false;
}
else {
return true;
}
},
"callback": function(key, options) {
var selection = d3.selectAll('.node_children');
selection
.each(function(d) {
d3.select("#id_node_" + d.id + networkmap_id)
.classed("node_children", false);
}
);
selection = d3.selectAll('.node_selected');
selection
.each(function(d) {
d3.select("#id_node_" + d.id + networkmap_id)
.classed("node_selected", false)
.classed("node_children", true);
}
);
flag_setting_interface_link_running = true;
}
};
items_list["children"] = {
name: set_as_children_menu,
icon: "children",
@ -1527,7 +1558,50 @@ function show_menu(item, data) {
flag_setting_relationship_running = true;
}
};
if (flag_setting_interface_link_running) {
if (d3.select("#id_node_" + data.id + networkmap_id).attr("class").search("node_children") == -1) {
items_list["set_parent_interface"] = {
name: set_parent_link,
icon: "interface_link_parent",
disabled : function() {
if (enterprise_installed) {
return false;
}
else {
return true;
}
},
"callback": function(key, options) {
var selection = d3.selectAll('.node_selected');
selection = selection[0];
if (selection.length > 1) {
alert("Yo no tengo dedo, por eso no poido trabajo, una ayuda, amorfa");
}
else {
add_interface_link(data);
}
}
};
}
items_list["cancel_set_parent_interface"] = {
name: abort_relationship_interface,
icon: "interface_link_cancel",
disabled : function() {
if (enterprise_installed) {
return false;
}
else {
return true;
}
},
"callback": function(key, options) {
cancel_set_parent_interface();
}
};
}
if (flag_setting_relationship_running) {
if (d3.select("#id_node_" + data.id + networkmap_id).attr("class").search("node_children") == -1) {
items_list["set_parent"] = {
@ -1671,6 +1745,24 @@ function show_menu(item, data) {
}
};
}
if (flag_setting_relationship_running) {
items_list["cancel_set_parent_interface"] = {
name: abort_relationship_interface,
icon: "cancel_set_parent",
disabled : function() {
if (enterprise_installed) {
return false;
}
else {
return true;
}
},
"callback": function(key, options) {
cancel_set_parent_interface();
}
};
}
$.contextMenu('destroy');
@ -1690,6 +1782,148 @@ function show_menu(item, data) {
});
}
function add_interface_link(data_parent) {
var selection = d3.selectAll('.node_children');
count = selection.size();
selection.each(function(child_data) {
var repeat = false;
jQuery.each(graph.links, function(i, link_item) {
if ((link_item.source_id_db == child_data.id_db) &&
(link_item.target_id_db == data_parent.id_db)){
repeat = true;
}
if ((link_item.source_id_db == data_parent.id_db) &&
(link_item.target_id_db == child_data.id_db)){
repeat = true;
}
});
if (repeat) {
count = count - 1;
if (count == 0) {
draw_elements_graph();
set_positions_graph();
cancel_set_parent();
cancel_set_parent_interface();
}
return; //Break
}
var params = [];
params.push("set_relationship_interface=1");
params.push("id=" + networkmap_id);
params.push("child=" + child_data.id_db);
params.push("parent=" + data_parent.id_db);
params.push("page=enterprise/operation/agentes/pandora_networkmap.view");
jQuery.ajax ({
data: params.join ("&"),
dataType: 'json',
type: 'POST',
url: action="ajax.php",
success: function (data) {
var parent_name = data_parent.text;
var child_name = child_data.text;
$('#label-node_source_interface').text(child_name);
$('#label-node_target_interface').text(parent_name);
$("#interface_target_select").empty();
$('#interface_target_select').append('<option value="' + data_parent.id_agent + '">None</option>');
jQuery.each(data.interfaces_parent, function(i, interface) {
$('#interface_target_select').append('<option value="' + interface.id_agente_modulo + '">' + interface.nombre + '</option>');
});
$("#interface_source_select").empty();
$('#interface_source_select').append('<option value="' + child_data.id_agent + '">None</option>');
jQuery.each(data.interfaces_child, function(i, interface) {
$('#interface_source_select').append('<option value="' + interface.id_agente_modulo + '">' + interface.nombre + '</option>');
});
$('#dialog_interface_link').dialog("open");
}
});
});
}
function add_interface_link_js () {
cancel_set_parent_interface();
$('#dialog_interface_link').dialog("close");
source_value = $('#interface_source_select').val();
source_text = $('#interface_source_select').find('option:selected').text();
target_value = $('#interface_target_select').val();
target_text = $('#interface_target_select').find('option:selected').text();
var params = [];
params.push("add_interface_relation=1");
params.push("id=" + networkmap_id);
params.push("source_value=" + source_value);
params.push("target_value=" + target_value);
params.push("source_text=" + source_text);
params.push("target_text=" + target_text);
params.push("page=enterprise/operation/agentes/pandora_networkmap.view");
jQuery.ajax ({
data: params.join ("&"),
dataType: 'json',
type: 'POST',
url: action="ajax.php",
success: function (data) {
if (data['correct']) {
var temp_link = {};
temp_link['id_db'] = data['id_db_link'];
if (data['type_source'] == 1) {
temp_link['arrow_start'] = "module";
temp_link['id_module_start'] = source_value;
}
else {
temp_link['arrow_start'] = "";
temp_link['id_agent_start'] = source_value;
temp_link['id_module_start'] = 0;
}
if (data['type_target'] == 1) {
temp_link['arrow_end'] = "module";
temp_link['id_module_end'] = target_value;
}
else {
temp_link['arrow_end'] = "";
temp_link['id_agent_end'] = target_value;
temp_link['id_module_end'] = 0;
}
temp_link['status_start'] = "0";
temp_link['status_end'] = "0";
//temp_link['text_start'] = link['text_start'];
//temp_link['text_end'] = link['text_end'];
jQuery.each(graph.nodes, function(j, node) {
console.log(node['id_db']);
if (node['id_agent'] == data['id_db_target']) {
temp_link['target'] = graph.nodes[j];
}
if (node['id_agent'] == data['id_db_source']) {
temp_link['source'] = graph.nodes[j];
}
});
graph.links.push(temp_link);
draw_elements_graph();
init_drag_and_drop();
set_positions_graph();
}
}
});
}
function refresh_holding_area() {
if (enterprise_installed) {
var params = [];
@ -1817,6 +2051,7 @@ function set_parent(parent_data) {
set_positions_graph();
cancel_set_parent();
cancel_set_parent_interface();
}
return; //Break
@ -1862,6 +2097,7 @@ function set_parent(parent_data) {
set_positions_graph();
cancel_set_parent();
cancel_set_parent_interface();
}
}
});
@ -1870,6 +2106,20 @@ function set_parent(parent_data) {
}
}
function cancel_set_parent_interface () {
var selection = d3.selectAll('.node_children');
selection
.each(function(d) {
d3.select("#id_node_" + d.id + networkmap_id)
.classed("node_selected", true)
.classed("node_children", false);
}
);
flag_setting_interface_link_running = false;
}
function cancel_set_parent() {
var selection = d3.selectAll('.node_children');
@ -2112,6 +2362,7 @@ function init_graph(parameter_object) {
window.in_a_node = false;
window.enterprise_installed = false;
window.flag_setting_relationship_running = false;
window.flag_setting_interface_link_running = false;
window.minimap_w = 0;
window.minimap_h = 0;
@ -2468,6 +2719,11 @@ function init_graph(parameter_object) {
autoOpen: false,
width: 650
});
$("#dialog_interface_link").dialog({
autoOpen: false,
width: 650
});
$("#dialog_node_add").dialog({
autoOpen: false,

View File

@ -117,6 +117,9 @@
.context-menu-item.icon-set_parent { background-image: url(../../images/father.png); }
.context-menu-item.icon-add_node { background-image: url(../../images/add.png); }
.context-menu-item.icon-refresh_holding_area { background-image: url(../../images/refresh_holding_area.png); }
.context-menu-item.icon-interface_link_children { background-image: url(../../images/icono_link_hijo.png); }
.context-menu-item.icon-interface_link_parent { background-image: url(../../images/icono_link_padre.png); }
.context-menu-item.icon-interface_link_cancel { background-image: url(../../images/link_abortar.png); }
/* vertically align inside labels */
.context-menu-input > label > * { vertical-align: top; }