New networkmaps in progress... (Fixed the node and fictional node adition)

This commit is contained in:
Arturo Gonzalez 2016-09-19 14:47:02 +02:00
parent b8ad4a0fa3
commit 5adcdd9b5f
3 changed files with 146 additions and 15 deletions

View File

@ -358,12 +358,18 @@ function networkmap_db_node_to_js_node($node, &$count, &$count_item_holding_area
$item['id'] = $count;
$item['id_db'] = (int)$node['id'];
if ((int)$node['type'] == 0) {
$item['type'] = 0;
$item['id_agent'] = (int)$node['source_data'];
$item['id_module'] = "";
}
else if ((int)$node['type'] == 1) {
$item['type'] = 1;
$item['id_agent'] = "";
$item['id_module'] = (int)$node['source_data'];
}else if ((int)$node['type'] == 3) {
$item['type'] = 3;
$item['id_agent'] = "";
$item['id_module'] = "";
}
$item['fixed'] = true;
$item['x'] = (int)$node['x'];
@ -414,7 +420,7 @@ function networkmap_db_node_to_js_node($node, &$count, &$count_item_holding_area
$color = "#364D1F";
}
else if ($node['source_data'] == -2) {
$color = $node['style']['fill_color'];
$color = "#364D1F";
}
else {
$color = get_status_color_networkmap($node['source_data']);
@ -1069,7 +1075,6 @@ function add_agent_networkmap($id, $agent_name_param, $x, $y,
$data['x'] = $x;
$data['y'] = $y;
$data['source_data'] = $id_agent;
$data['parent'] = 0;
$style = array();
$style['shape'] = 'circle';
$style['image'] = $img_node;
@ -1083,8 +1088,8 @@ function add_agent_networkmap($id, $agent_name_param, $x, $y,
$data['state'] = $other_values['state'];
}
if (isset($other_values['text'])) {
$agent_name = $other_values['text'];
if (isset($other_values['label'])) {
$agent_name = $other_values['label'];
}
if (isset($other_values['id_module'])) {
@ -1100,7 +1105,91 @@ function add_agent_networkmap($id, $agent_name_param, $x, $y,
$data['style'] = str_replace('json_encode_crash_with_ut8_chars',
$agent_name, $data['style']);
return db_process_sql_insert('titem', $data);
$id_node = db_process_sql_insert('titem', $data);
$node = db_get_all_rows_filter('titem', array('id' => $id_node));
$node = $node[0];
$rel = array();
/* FLECHAS EMPEZADO PARA MEJORAR
$index = 0;
if ($agent['id_parent'] != 0) {
$values = array();
$values['id_child'] = $agent['id_agente'];
$values['id_parent'] = $agent['id_parent'];
$values['parent_type'] = 0;
$values['child_type'] = 0;
$values['id_item'] = 0;
$values['deleted'] = 0;
$values['id_map'] = $id;
$parent = db_get_row('tagente', 'id_agente', $agent['id_parent']);
$parent_item = db_get_all_rows_filter('titem', array('source_data' => $agent['id_parent'], 'type' => 0));
$parent_item = $parent_item[0];
$rel[$index]['id_db'] = db_process_sql_insert('trel_item', $values);
$rel[$index]['id_agent_end'] = $parent['id_agente'];
$rel[$index]['id_agent_start'] = $agent['id_agente'];
$rel[$index]['id_module_end'] = 0;
$rel[$index]['id_module_start'] = 0;
$rel[$index]['source'] = $id_node;
$rel[$index]['target'] = $parent_item['id'];
$rel[$index]['source_in_db'] = $id_node;
$rel[$index]['target_in_db'] = $parent_item['id'];
$rel[$index]['arrow_end'] = "";
$rel[$index]['arrow_start'] = "";
$rel[$index]['status_end'] = "";
$rel[$index]['status_start'] = "";
$rel[$index]['text_end'] = "";
$rel[$index]['text_start'] = "";
$index++;
$childs_of_new_agent = db_get_all_rows_filter('tagente', array('id_parent' => $agent['id_agente']));
foreach ($childs_of_new_agent as $child) {
$values = array();
$values['id_child'] = $child['id_agente'];
$values['id_parent'] = $agent['id_agente'];
$values['parent_type'] = 0;
$values['child_type'] = 0;
$values['id_item'] = 0;
$values['deleted'] = 0;
$values['id_map'] = $id;
$child_item = db_get_all_rows_filter('titem', array('source_data' => $child['id_agente'], 'type' => 0));
$child_item = $child_item[0];
$rel[$index]['id_db'] = db_process_sql_insert('trel_item', $values);
$rel[$index]['id_agent_end'] = $agent['id_agente'];
$rel[$index]['id_agent_start'] = $child['id_agente'];
$rel[$index]['id_module_end'] = 0;
$rel[$index]['id_module_start'] = 0;
$rel[$index]['source'] = $child_item['id'];
$rel[$index]['target'] = $id_node;
$rel[$index]['source_in_db'] = $child_item['id'];
$rel[$index]['target_in_db'] = $id_node;
$rel[$index]['arrow_end'] = "";
$rel[$index]['arrow_start'] = "";
$rel[$index]['status_end'] = "";
$rel[$index]['status_start'] = "";
$rel[$index]['text_end'] = "";
$rel[$index]['text_start'] = "";
$index++;
}
}
*/
$return_data = array();
if ($id_node !== false) {
$return_data['id_node'] = $id_node;
$return_data['rel'] = $rel;
return $return_data;
}
else {
return false;
}
}
function show_node_info($id_node, $refresh_state, $user_readonly) {

View File

@ -705,7 +705,6 @@ function add_agent_node(agents) {
x = x + (i * 20);
y = y + (i * 20);
var params = [];
params.push("add_agent=1");
params.push("id=" + networkmap_id);
@ -727,20 +726,46 @@ function add_agent_node(agents) {
temp_node['id'] = graph.nodes.length;
temp_node['id_db'] = data['id_node'];
temp_node['id_agent'] = data['id_agent'];
temp_node['id_module'] = 0;
temp_node['id_module'] = "";
temp_node['px'] = data['x'];
temp_node['py'] = data['y'];
temp_node['x'] = data['x'];
temp_node['y'] = data['y'];
temp_node['z'] = 0;
temp_node['fixed'] = true;
temp_node['type'] = 'agent';
temp_node['type'] = 0;
temp_node['color'] = data['status'];
temp_node['shape'] = data['shape'];
temp_node['text'] = data['text'];
temp_node['image_url'] = data['image_url'];
temp_node['image_width'] = data['width'];
temp_node['image_height'] = data['height'];
temp_node['map_id'] = data['map_id'];
temp_node['state'] = data['state'];
graph.nodes.push(temp_node);
/* FLECHAS EMPEZADO PARA MEJORAR
jQuery.each(data['rel'], function(i, relation) {
var temp_link = {};
temp_link['id_db'] = String(relation['id_db']);
temp_link['id_agent_end'] = String(relation['id_agent_end']);
temp_link['id_agent_start'] = String(relation['id_agent_start']);
temp_link['id_module_end'] = relation['id_module_end'];
temp_link['id_module_start'] = relation['id_module_start'];
temp_link['source'] = relation['source'];
temp_link['target'] = relation['target'];
temp_link['source_in_db'] = String(relation['source_in_db']);
temp_link['target_in_db'] = String(relation['target_in_db']);
temp_link['arrow_end'] = relation['arrow_end'];
temp_link['arrow_start'] = relation['arrow_start'];
temp_link['status_end'] = relation['status_end'];
temp_link['status_start'] = relation['status_start'];
temp_link['text_end'] = relation['text_end'];
temp_link['text_start'] = relation['text_start'];
graph.links.push(temp_link);
});
*/
draw_elements_graph();
init_drag_and_drop();
@ -1321,6 +1346,14 @@ function show_menu(item, data) {
items_list["add_node"] = {
name: add_node_menu,
icon: "add_node",
disabled : function() {
if (enterprise_installed) {
return false;
}
else {
return true;
}
},
"callback": function(key, options) {
add_node();
}
@ -1693,7 +1726,7 @@ function add_fictional_node() {
temp_node['y'] = y;
temp_node['z'] = 0;
temp_node['fixed'] = true;
temp_node['type'] = 'fictional_node';
temp_node['type'] = 3;
temp_node['color'] = data['color'];
temp_node['shape'] = data['shape'];
temp_node['text'] = data['text'];

View File

@ -369,7 +369,10 @@ if (is_ajax ()) {
$data['x'] = $x;
$data['y'] = $y;
$data['source_data'] = -2; //The id for the fictional points.
$data['parent'] = 0;
$data['deleted'] = 0;
//Type in db to fictional nodes
$data['type'] = 3;
$data['state'] = "";
$style = array();
$style['shape'] = $shape;
$style['image'] = '';
@ -392,7 +395,6 @@ if (is_ajax ()) {
if ($return['correct']) {
$return['id_node'] = $id_node;
$return['id_agent'] = -2; //The finctional point id
$return['parent'] = 0;
$return['shape'] = $shape;
$return['image'] = '';
$return['width'] = $radious * 2;
@ -925,9 +927,10 @@ if (is_ajax ()) {
$return = array();
$return['correct'] = false;
$id_node = add_agent_networkmap($id, $agent, $x, $y, $id_agent);
$return_data = add_agent_networkmap($id, $agent, $x, $y, $id_agent);
if ($id_node !== false) {
if ($return_data['id_node'] !== false) {
$id_node = $return_data['id_node'];
$return['correct'] = true;
$node = db_get_row('titem', 'id',
@ -935,7 +938,7 @@ if (is_ajax ()) {
$style = json_decode($node['style'], true);
$return['id_node'] = $id_node;
$return['source_data'] = $node['id_agent'];
$return['id_agent'] = $node['source_data'];
$return['parent'] = $node['parent'];
$return['shape'] = $style['shape'];
$return['image'] = $style['image'];
@ -943,12 +946,18 @@ if (is_ajax ()) {
$style['image'], true, false, true);
$return['width'] = $style['width'];
$return['height'] = $style['height'];
$return['text'] = $style['text'];
$return['text'] = $style['label'];
$return['x'] = $x;
$return['y'] = $y;
$return['map_id'] = $node['id_map'];
$return['state'] = $node['state'];
$return['status'] = get_status_color_networkmap($id_agent);
}
if (!empty($return_data['rel'])) {
$return['rel'] = $return_data['rel'];
}
echo json_encode($return);
return;