From ac36c701f79fe0f790d55f1b490b250354756c27 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Mon, 11 Sep 2017 16:09:13 +0200 Subject: [PATCH 1/9] Added a first contact with the new functions --- pandora_server/util/pandora_manage.pl | 105 +++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 48e42b5d2f..3fafbf8d25 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -213,6 +213,15 @@ sub help_screen{ help_screen_line('--create_tag', ' [] []', 'Create a new tag'); help_screen_line('--add_tag_to_user_profile', ' ', 'Add a tag to the given user profile'); help_screen_line('--add_tag_to_module', ' ', 'Add a tag to the given module'); + + print "\nVISUAL CONSOLES\n\n" unless $param ne ''; + help_screen_line('--create_visual_console', ' [] []', 'Create a new visual console'); + help_screen_line('--edit_visual_console', ' [] []', 'Edit a visual console'); + help_screen_line('--delete_visual_console', '', 'Delete a visual console'); + help_screen_line('--delete_visual_console_objects', ' ', 'Delete a visual console elements'); + help_screen_line('--duplicate_visual_console', ' []', 'Duplicate a visual console'); + help_screen_line('--export_json_visual_console', '', 'Creates a json with the visual console elements information'); + print "\n"; exit; @@ -4753,6 +4762,76 @@ sub cli_delete_special_day() { exist_check($result,'special day',$special_day); } +############################################################################## +# Creates a new visual console. +# Related option: --create_visual_console +############################################################################## + +sub cli_create_visual_console() { + my ($name,$background,$width,$height,$group,$background_color,$elements) = @ARGV[2..8]; + + if($name eq '') { + print_log "[ERROR] Name field cannot be empty.\n\n"; + exit 1; + } + elsif ($background eq '') { + print_log "[ERROR] Background field cannot be empty.\n\n"; + exit 1; + } + elsif (($width eq '') || ($height eq '')) { + print_log "[ERROR] Please specify size.\n\n"; + exit 1; + } + elsif ($group eq '') { + print_log "[ERROR] Group field cannot be empty.\n\n"; + exit 1; + } + + if ($background_color eq '') { + $background_color = '#FFF'; + } + + print_log "[INFO] Creating visual console '$name' \n\n"; + + my $vc_id = db_insert ($dbh, 'id', 'INSERT INTO tlayout (name, id_group, background, width, height, background_color) + VALUES (?, ?, ?, ?, ?, ?)', safe_input($name), $group, $background, $width, $height, $background_color); + + print_log "[INFO] The visual console id is '$vc_id' \n\n"; + + if ($elements ne '') { + my @elements_in_array = json_decoce($elements); + + foreach my $elem (@elements_in_array) { + print_log $elem . "\n\n"; + } + } +} + +############################################################################## +# Delete a visual console. +# Related option: --delete_visual_console +############################################################################## + +sub cli_delete_visual_console() { + my ($id) = @ARGV[2]; + + if($id eq '') { + print_log "[ERROR] ID field cannot be empty.\n\n"; + exit 1; + } + + print_log "[INFO] Delete visual console with ID '$id' \n\n"; + + my $delete_layout = db_do($dbh, 'DELETE FROM tlayout WHERE id = ?', $id); + + if ($delete_layout eq 1) { + db_do($dbh, 'DELETE FROM tlayout_data WHERE id_layout = ?', $id); + } + else { + print_log "[ERROR] Error at remove the visual console.\n\n"; + exit 1; + } +} ############################################################################### ############################################################################### @@ -5183,7 +5262,31 @@ sub pandora_manage_main ($$$) { elsif ($param eq '--locate_agent') { param_check($ltotal, 1); cli_locate_agent(); - } + } + elsif ($param eq '--create_visual_console') { + param_check($ltotal, 7, 2); + cli_create_visual_console(); + } + elsif ($param eq '--edit_visual_console') { + param_check($ltotal, 6, 2); + cli_edit_visual_console(); + } + elsif ($param eq '--delete_visual_console') { + param_check($ltotal, 1); + cli_delete_visual_console(); + } + elsif ($param eq '--delete_visual_console_objects') { + param_check($ltotal, 3); + cli_delete_visual_console_objects(); + } + elsif ($param eq '--duplicate_visual_console') { + param_check($ltotal, 2, 1); + cli_duplicate_visual_console(); + } + elsif ($param eq '--export_json_visual_console') { + param_check($ltotal, 1); + cli_export_visual_console(); + } else { print_log "[ERROR] Invalid option '$param'.\n\n"; $param = ''; From 4dec318607349db8519c4786db03ac4dc0ad2b63 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Mon, 11 Sep 2017 17:56:42 +0200 Subject: [PATCH 2/9] Added function to create visual console with elements in cli --- pandora_server/util/pandora_manage.pl | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 3fafbf8d25..ee45368900 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -21,6 +21,7 @@ use JSON qw(decode_json encode_json); use MIME::Base64; use Encode qw(decode encode_utf8); use LWP::Simple; +use Data::Dumper; # Default lib dir for RPM and DEB packages use lib '/usr/lib/perl5'; @@ -4799,10 +4800,33 @@ sub cli_create_visual_console() { print_log "[INFO] The visual console id is '$vc_id' \n\n"; if ($elements ne '') { - my @elements_in_array = json_decoce($elements); + my $elements_in_array = decode_json($elements); - foreach my $elem (@elements_in_array) { - print_log $elem . "\n\n"; + foreach my $elem (@$elements_in_array) { + my $pos_x = $elem->{'pos_x'}; + my $pos_y = $elem->{'pos_y'}; + my $width = $elem->{'width'}; + my $height = $elem->{'height'}; + my $label = $elem->{'label'}; + my $image = $elem->{'image'}; + my $type = $elem->{'type'}; + my $period = $elem->{'period'}; + my $id_agente_modulo = $elem->{'id_agente_modulo'}; + my $id_agent = $elem->{'id_agent'}; + my $id_layout_linked = $elem->{'id_layout_linked'}; + my $parent_item = $elem->{'parent_item'}; + my $enable_link = $elem->{'enable_link'}; + my $id_metaconsole = $elem->{'id_metaconsole'}; + my $id_group = $elem->{'id_group'}; + my $id_custom_graph = $elem->{'id_custom_graph'}; + my $border_width = $elem->{'border_width'}; + my $type_graph = $elem->{'type_graph'}; + my $label_position = $elem->{'label_position'}; + my $border_color = $elem->{'border_color'}; + my $fill_color = $elem->{'fill_color'}; + + db_insert ($dbh, 'id', 'INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_agent, id_layout_linked, parent_item, enable_link, id_metaconsole, id_group, id_custom_graph, border_width, type_graph, label_position, border_color, fill_color, show_statistics) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $vc_id, $pos_x, $pos_y, $height, $width, $label, $image, $type, $period, $id_agente_modulo, $id_agent, $id_layout_linked, $parent_item, $enable_link, $id_metaconsole, $id_group, $id_custom_graph, $border_width, $type_graph, $label_position, $border_color, $fill_color, 0); } } } From e7cdf9b049660be547c87d0162b0a036be418660 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 13 Sep 2017 13:27:37 +0200 Subject: [PATCH 3/9] Added creation when elements position is auto --- pandora_server/util/pandora_manage.pl | 149 +++++++++++++++++++++----- 1 file changed, 122 insertions(+), 27 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index ee45368900..f258082280 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -216,7 +216,7 @@ sub help_screen{ help_screen_line('--add_tag_to_module', ' ', 'Add a tag to the given module'); print "\nVISUAL CONSOLES\n\n" unless $param ne ''; - help_screen_line('--create_visual_console', ' [] []', 'Create a new visual console'); + help_screen_line('--create_visual_console', ' [] [] []', 'Create a new visual console'); help_screen_line('--edit_visual_console', ' [] []', 'Edit a visual console'); help_screen_line('--delete_visual_console', '', 'Delete a visual console'); help_screen_line('--delete_visual_console_objects', ' ', 'Delete a visual console elements'); @@ -4769,7 +4769,7 @@ sub cli_delete_special_day() { ############################################################################## sub cli_create_visual_console() { - my ($name,$background,$width,$height,$group,$background_color,$elements) = @ARGV[2..8]; + my ($name,$background,$width,$height,$group,$mode,$element_square_positions,$background_color,$elements) = @ARGV[2..10]; if($name eq '') { print_log "[ERROR] Name field cannot be empty.\n\n"; @@ -4787,6 +4787,10 @@ sub cli_create_visual_console() { print_log "[ERROR] Group field cannot be empty.\n\n"; exit 1; } + elsif ($mode eq '') { + print_log "[ERROR] Mode parameter must be 'static_objects' or 'auto_creation'.\n\n"; + exit 1; + } if ($background_color eq '') { $background_color = '#FFF'; @@ -4802,31 +4806,120 @@ sub cli_create_visual_console() { if ($elements ne '') { my $elements_in_array = decode_json($elements); - foreach my $elem (@$elements_in_array) { - my $pos_x = $elem->{'pos_x'}; - my $pos_y = $elem->{'pos_y'}; - my $width = $elem->{'width'}; - my $height = $elem->{'height'}; - my $label = $elem->{'label'}; - my $image = $elem->{'image'}; - my $type = $elem->{'type'}; - my $period = $elem->{'period'}; - my $id_agente_modulo = $elem->{'id_agente_modulo'}; - my $id_agent = $elem->{'id_agent'}; - my $id_layout_linked = $elem->{'id_layout_linked'}; - my $parent_item = $elem->{'parent_item'}; - my $enable_link = $elem->{'enable_link'}; - my $id_metaconsole = $elem->{'id_metaconsole'}; - my $id_group = $elem->{'id_group'}; - my $id_custom_graph = $elem->{'id_custom_graph'}; - my $border_width = $elem->{'border_width'}; - my $type_graph = $elem->{'type_graph'}; - my $label_position = $elem->{'label_position'}; - my $border_color = $elem->{'border_color'}; - my $fill_color = $elem->{'fill_color'}; + if ($mode eq 'static_objects') { + my $elem_count = 1; - db_insert ($dbh, 'id', 'INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_agent, id_layout_linked, parent_item, enable_link, id_metaconsole, id_group, id_custom_graph, border_width, type_graph, label_position, border_color, fill_color, show_statistics) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $vc_id, $pos_x, $pos_y, $height, $width, $label, $image, $type, $period, $id_agente_modulo, $id_agent, $id_layout_linked, $parent_item, $enable_link, $id_metaconsole, $id_group, $id_custom_graph, $border_width, $type_graph, $label_position, $border_color, $fill_color, 0); + foreach my $elem (@$elements_in_array) { + my $pos_x = $elem->{'pos_x'}; + my $pos_y = $elem->{'pos_y'}; + my $width = $elem->{'width'}; + my $height = $elem->{'height'}; + my $label = $elem->{'label'}; + my $image = $elem->{'image'}; + my $type = $elem->{'type'}; + my $period = $elem->{'period'}; + my $id_agente_modulo = $elem->{'id_agente_modulo'}; + my $id_agent = $elem->{'id_agent'}; + my $id_layout_linked = $elem->{'id_layout_linked'}; + my $parent_item = $elem->{'parent_item'}; + my $enable_link = $elem->{'enable_link'}; + my $id_metaconsole = $elem->{'id_metaconsole'}; + my $id_group = $elem->{'id_group'}; + my $id_custom_graph = $elem->{'id_custom_graph'}; + my $border_width = $elem->{'border_width'}; + my $type_graph = $elem->{'type_graph'}; + my $label_position = $elem->{'label_position'}; + my $border_color = $elem->{'border_color'}; + my $fill_color = $elem->{'fill_color'}; + + my $elem_id = db_insert ($dbh, 'id', 'INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_agent, id_layout_linked, parent_item, enable_link, id_metaconsole, id_group, id_custom_graph, border_width, type_graph, label_position, border_color, fill_color, show_statistics) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $vc_id, $pos_x, $pos_y, $height, $width, $label, $image, $type, $period, $id_agente_modulo, $id_agent, $id_layout_linked, $parent_item, $enable_link, $id_metaconsole, $id_group, $id_custom_graph, $border_width, $type_graph, $label_position, $border_color, $fill_color, 0); + + print_log "[INFO] The element id in position $elem_count is '$elem_id' \n\n"; + + $elem_count++; + } + } + elsif ($mode eq 'auto_creation') { + if ($element_square_positions eq '') { + print_log "[ERROR] With this mode, square positions is obligatory'.\n\n"; + exit 1; + } + else { + my $positions = decode_json($element_square_positions); + + my $pos1X = $positions->{'pos1x'}; + my $pos1Y = $positions->{'pos1y'}; + my $pos2X = $positions->{'pos2x'}; + my $pos2Y = $positions->{'pos2y'}; + + my $number_of_elements = scalar(@$elements_in_array); + + my $x_divider = 4; + my $y_divider = 1; + + for (my $i = 1; $i <= 1000; $i++) { + if (($i * 4) < $number_of_elements) { + $y_divider++; + } + else { + last; + } + } + + my $elem_width = ($pos2X - $pos1X) / $x_divider; + my $elem_height = ($pos2Y - $pos1Y) / $y_divider; + + if ($number_of_elements < 4) { + $elem_height = ($pos2Y - $pos1Y) / 3; + } + + my $elem_count = 1; + my $pos_helper_x = 0; + my $pos_helper_y = 0; + foreach my $elem (@$elements_in_array) { + my $pos_x = $pos_helper_x * $elem_width; + my $pos_y = $pos_helper_y * $elem_height; + my $width = $elem_width; + my $height = $elem_height; + my $label = $elem->{'label'}; + my $image = $elem->{'image'}; + my $type = $elem->{'type'}; + my $period = $elem->{'period'}; + my $id_agente_modulo = $elem->{'id_agente_modulo'}; + my $id_agent = $elem->{'id_agent'}; + my $id_layout_linked = $elem->{'id_layout_linked'}; + my $parent_item = $elem->{'parent_item'}; + my $enable_link = $elem->{'enable_link'}; + my $id_metaconsole = $elem->{'id_metaconsole'}; + my $id_group = $elem->{'id_group'}; + my $id_custom_graph = $elem->{'id_custom_graph'}; + my $border_width = $elem->{'border_width'}; + my $type_graph = $elem->{'type_graph'}; + my $label_position = $elem->{'label_position'}; + my $border_color = $elem->{'border_color'}; + my $fill_color = $elem->{'fill_color'}; + + my $elem_id = db_insert ($dbh, 'id', 'INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_agent, id_layout_linked, parent_item, enable_link, id_metaconsole, id_group, id_custom_graph, border_width, type_graph, label_position, border_color, fill_color, show_statistics) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $vc_id, $pos_x, $pos_y, $height, $width, $label, $image, $type, $period, $id_agente_modulo, $id_agent, $id_layout_linked, $parent_item, $enable_link, $id_metaconsole, $id_group, $id_custom_graph, $border_width, $type_graph, $label_position, $border_color, $fill_color, 0); + + print_log "[INFO] The element id in position $elem_count is '$elem_id' \n\n"; + + $elem_count++; + + if ($pos_helper_x == 3) { + $pos_helper_x = 0; + $pos_helper_y++; + } + else { + $pos_helper_x++; + } + } + } + } + else { + print_log "[ERROR] Mode parameter must be 'static_objects' or 'auto_creation'.\n\n"; + exit 1; } } } @@ -4850,6 +4943,8 @@ sub cli_delete_visual_console() { if ($delete_layout eq 1) { db_do($dbh, 'DELETE FROM tlayout_data WHERE id_layout = ?', $id); + + print_log "[INFO] Delete visual console elements with console ID '$id' \n\n"; } else { print_log "[ERROR] Error at remove the visual console.\n\n"; @@ -5288,7 +5383,7 @@ sub pandora_manage_main ($$$) { cli_locate_agent(); } elsif ($param eq '--create_visual_console') { - param_check($ltotal, 7, 2); + param_check($ltotal, 9, 3); cli_create_visual_console(); } elsif ($param eq '--edit_visual_console') { From 26522ecaaa459e67c3fa1fc5baa9a7cbc2e3fff8 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 13 Sep 2017 15:19:41 +0200 Subject: [PATCH 4/9] Added remove console items function to cli --- pandora_server/util/pandora_manage.pl | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index f258082280..67e1214907 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -4952,6 +4952,39 @@ sub cli_delete_visual_console() { } } +############################################################################## +# Delete a visual console objects. +# Related option: --delete_visual_console_objects +############################################################################## + +sub cli_delete_visual_console_objects() { + my ($id_console,$mode,$id_mode) = @ARGV[2..4]; + + if($id_console eq '') { + print_log "[ERROR] Console ID field cannot be empty.\n\n"; + exit 1; + } + elsif ($mode eq '') { + print_log "[ERROR] Mode field cannot be empty.\n\n"; + exit 1; + } + elsif ($id_mode eq '') { + print_log "[ERROR] Mode index field cannot be empty.\n\n"; + exit 1; + } + + if (($mode eq 'type') || ($mode eq 'image') || ($mode eq 'id_agent') || + ($mode eq 'id_agente_modulo') || ($mode eq 'id_group') || ($mode eq 'type_graph')) { + print_log "[INFO] Removind objects with mode '$mode' and id '$id_mode' \n\n"; + + db_do($dbh, 'DELETE FROM tlayout_data WHERE id_layout = ' . $id_console . ' AND ' . $mode . ' = "' . $id_mode . '"'); + } + else { + print_log "[ERROR] Mode is not correct.\n\n"; + exit 1; + } +} + ############################################################################### ############################################################################### # MAIN From 351f9e27b19f436d6e668bdf2550188d05d33e21 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 13 Sep 2017 17:39:17 +0200 Subject: [PATCH 5/9] Added duplicate function --- pandora_server/util/pandora_manage.pl | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 67e1214907..e0322c3718 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -4985,6 +4985,80 @@ sub cli_delete_visual_console_objects() { } } +sub cli_duplicate_visual_console () { + my ($id_console,$prefix) = @ARGV[2..3]; + + if($id_console eq '') { + print_log "[ERROR] Console ID field cannot be empty.\n\n"; + exit 1; + } + + my $console = get_db_single_row ($dbh, "SELECT * + FROM tlayout + WHERE id = $id_console"); + + my $name_to_compare = $console->{'name'}; + my $new_name = $console->{'name'} . "_1"; + my $name_count = 2; + + if ($prefix ne '') { + $new_name = $prefix; + $name_to_compare = $prefix; + $name_count = 1; + } + + my $exist = 1; + while ($exist == 1) { + my $name_in_db = get_db_single_row ($dbh, "SELECT name FROM tlayout WHERE name = '$new_name'"); + + if (defined($name_in_db->{'name'}) && ($name_in_db->{'name'} eq $new_name)) { + $new_name = $name_to_compare . "_" . $name_count; + $name_count++; + } + else { + $exist = 0; + } + } + + my $new_console_id = db_insert ($dbh, 'id', 'INSERT INTO tlayout (name, id_group, background, width, height, background_color) + VALUES (?, ?, ?, ?, ?, ?)', $new_name, $console->{'id_group'}, $console->{'background'}, $console->{'width'}, $console->{'height'}, $console->{'background_color'}); + + print_log "[INFO] The new visual console '$new_name' has been created. The new ID is '$new_console_id' \n\n"; + + my @console_elements = get_db_rows ($dbh, "SELECT * + FROM tlayout_data + WHERE id_layout = $id_console"); + + foreach my $element (@console_elements) { + my $pos_x = $element->{'pos_x'}; + my $pos_y = $element->{'pos_y'}; + my $width = $element->{'width'}; + my $height = $element->{'height'}; + my $label = $element->{'label'}; + my $image = $element->{'image'}; + my $type = $element->{'type'}; + my $period = $element->{'period'}; + my $id_agente_modulo = $element->{'id_agente_modulo'}; + my $id_agent = $element->{'id_agent'}; + my $id_layout_linked = $element->{'id_layout_linked'}; + my $parent_item = $element->{'parent_item'}; + my $enable_link = $element->{'enable_link'}; + my $id_metaconsole = $element->{'id_metaconsole'}; + my $id_group = $element->{'id_group'}; + my $id_custom_graph = $element->{'id_custom_graph'}; + my $border_width = $element->{'border_width'}; + my $type_graph = $element->{'type_graph'}; + my $label_position = $element->{'label_position'}; + my $border_color = $element->{'border_color'}; + my $fill_color = $element->{'fill_color'}; + + my $element_id = db_insert ($dbh, 'id', 'INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_agent, id_layout_linked, parent_item, enable_link, id_metaconsole, id_group, id_custom_graph, border_width, type_graph, label_position, border_color, fill_color, show_statistics) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $new_console_id, $pos_x, $pos_y, $height, $width, $label, $image, $type, $period, $id_agente_modulo, $id_agent, $id_layout_linked, $parent_item, $enable_link, $id_metaconsole, $id_group, $id_custom_graph, $border_width, $type_graph, $label_position, $border_color, $fill_color, 0); + + print_log "[INFO] Element with ID " . $element->{"id"} . " has been duplicated to the new console \n\n"; + } +} + ############################################################################### ############################################################################### # MAIN From f03514c77106912b753891da7c768a7dd850b20b Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 13 Sep 2017 18:07:45 +0200 Subject: [PATCH 6/9] Added first version to export console elements to json --- pandora_server/util/pandora_manage.pl | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index e0322c3718..34c42053e4 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -4985,6 +4985,11 @@ sub cli_delete_visual_console_objects() { } } +############################################################################## +# Duplicate a visual console. +# Related option: --duplicate_visual_console +############################################################################## + sub cli_duplicate_visual_console () { my ($id_console,$prefix) = @ARGV[2..3]; @@ -5059,6 +5064,87 @@ sub cli_duplicate_visual_console () { } } +############################################################################## +# Export a visual console elements to json. +# Related option: --export_json_visual_console +############################################################################## + +sub cli_export_visual_console() { + my ($id) = @ARGV[2]; + + if($id eq '') { + print_log "[ERROR] ID field cannot be empty.\n\n"; + exit 1; + } + + print_log "[INFO] Exporting visual console elements with ID '$id' \n\n"; + + my @console_elements = get_db_rows ($dbh, "SELECT * + FROM tlayout_data + WHERE id_layout = $id"); + + my $data_to_json = '['; + my $first = 1; + + foreach my $element (@console_elements) { + my $pos_x = $element->{'pos_x'}; + my $pos_y = $element->{'pos_y'}; + my $width = $element->{'width'}; + my $height = $element->{'height'}; + my $label = $element->{'label'}; + my $image = $element->{'image'}; + my $type = $element->{'type'}; + my $period = $element->{'period'}; + my $id_agente_modulo = $element->{'id_agente_modulo'}; + my $id_agent = $element->{'id_agent'}; + my $id_layout_linked = $element->{'id_layout_linked'}; + my $parent_item = $element->{'parent_item'}; + my $enable_link = $element->{'enable_link'}; + my $id_metaconsole = $element->{'id_metaconsole'}; + my $id_group = $element->{'id_group'}; + my $id_custom_graph = $element->{'id_custom_graph'}; + my $border_width = $element->{'border_width'}; + my $type_graph = $element->{'type_graph'}; + my $label_position = $element->{'label_position'}; + my $border_color = $element->{'border_color'}; + my $fill_color = $element->{'fill_color'}; + + if ($first == 0) { + $data_to_json .= ',' + } + else { + $first = 0; + } + + $data_to_json .= '{"image":"' . $image . '"'; + $data_to_json .= ',"pos_y":' . $pos_y; + $data_to_json .= ',"pos_x":' . $pos_x; + $data_to_json .= ',"width":' . $width; + $data_to_json .= ',"height":' . $height; + $data_to_json .= ',"label":"' . $label . '"'; + $data_to_json .= ',"type":' . $type; + $data_to_json .= ',"period":' . $period; + $data_to_json .= ',"id_agente_modulo":' . $id_agente_modulo; + $data_to_json .= ',"id_agent":' . $id_agent; + $data_to_json .= ',"id_layout_linked":' . $id_layout_linked; + $data_to_json .= ',"parent_item":' . $parent_item; + $data_to_json .= ',"enable_link":' . $enable_link; + $data_to_json .= ',"id_metaconsole":' . $id_metaconsole; + $data_to_json .= ',"id_group":' . $id_group; + $data_to_json .= ',"id_custom_graph":' . $id_custom_graph; + $data_to_json .= ',"border_width":' . $border_width; + $data_to_json .= ',"type_graph":"' . $type_graph . '"'; + $data_to_json .= ',"label_position":"' . $label_position . '"'; + $data_to_json .= ',"border_color":"' . $border_color . '"'; + $data_to_json .= ',"fill_color":"' . $fill_color . '"'; + $data_to_json .= '}'; + } + + $data_to_json .= ']'; + + print_log "[INFO] JSON file now contents: \n" . $data_to_json . "\n\n"; +} + ############################################################################### ############################################################################### # MAIN From aa8ee4278d36f969080d0ab30f2cd9d0ddb5f908 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Thu, 14 Sep 2017 09:37:45 +0200 Subject: [PATCH 7/9] Added export to JSON function to cli --- pandora_server/util/pandora_manage.pl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 34c42053e4..a34d918338 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -221,7 +221,7 @@ sub help_screen{ help_screen_line('--delete_visual_console', '', 'Delete a visual console'); help_screen_line('--delete_visual_console_objects', ' ', 'Delete a visual console elements'); help_screen_line('--duplicate_visual_console', ' []', 'Duplicate a visual console'); - help_screen_line('--export_json_visual_console', '', 'Creates a json with the visual console elements information'); + help_screen_line('--export_json_visual_console', ' []', 'Creates a json with the visual console elements information'); print "\n"; @@ -5070,7 +5070,7 @@ sub cli_duplicate_visual_console () { ############################################################################## sub cli_export_visual_console() { - my ($id) = @ARGV[2]; + my ($id,$path) = @ARGV[2..3]; if($id eq '') { print_log "[ERROR] ID field cannot be empty.\n\n"; @@ -5142,6 +5142,15 @@ sub cli_export_visual_console() { $data_to_json .= ']'; + if ($path eq '') { + open(FicheroJSON, ">console_" . $id . "_elements"); + } + else { + open(FicheroJSON, ">" . $path . "/console_" . $id . "_elements"); + } + + print FicheroJSON $data_to_json; + print_log "[INFO] JSON file now contents: \n" . $data_to_json . "\n\n"; } @@ -5596,7 +5605,7 @@ sub pandora_manage_main ($$$) { cli_duplicate_visual_console(); } elsif ($param eq '--export_json_visual_console') { - param_check($ltotal, 1); + param_check($ltotal, 2, 1); cli_export_visual_console(); } else { From bb0e15261a17c4c27beed7c85a0cd1291cd793ba Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Thu, 14 Sep 2017 12:07:52 +0200 Subject: [PATCH 8/9] Added editor function when static option is enabled --- pandora_server/util/pandora_manage.pl | 275 +++++++++++++++++++++++++- 1 file changed, 273 insertions(+), 2 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index a34d918338..8cdb7df9b8 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -217,7 +217,7 @@ sub help_screen{ print "\nVISUAL CONSOLES\n\n" unless $param ne ''; help_screen_line('--create_visual_console', ' [] [] []', 'Create a new visual console'); - help_screen_line('--edit_visual_console', ' [] []', 'Edit a visual console'); + help_screen_line('--edit_visual_console', ' [] [] [] [] [] [] [] [] []', 'Edit a visual console'); help_screen_line('--delete_visual_console', '', 'Delete a visual console'); help_screen_line('--delete_visual_console_objects', ' ', 'Delete a visual console elements'); help_screen_line('--duplicate_visual_console', ' []', 'Duplicate a visual console'); @@ -4924,6 +4924,277 @@ sub cli_create_visual_console() { } } +############################################################################## +# Edit a visual console. +# Related option: --edit_visual_console +############################################################################## + +sub cli_edit_visual_console() { + my ($id,$name,$background,$width,$height,$group,$mode,$element_square_positions,$background_color,$elements) = @ARGV[2..11]; + + if($id eq '') { + print_log "[ERROR] ID field cannot be empty.\n\n"; + exit 1; + } + + my $console = get_db_single_row ($dbh, "SELECT * + FROM tlayout + WHERE id = $id"); + + my $new_name = $console->{'name'}; + my $new_background = $console->{'background'}; + my $new_console_width = $console->{'width'}; + my $new_console_height = $console->{'height'}; + my $new_console_id_group = $console->{'id_group'}; + my $new_background_color = $console->{'background_color'}; + + if($name ne '') { + $new_name = $name; + } + if ($background ne '') { + $new_background = $background; + } + if ($width ne '') { + $new_console_width = $width; + } + if ($height ne '') { + $new_console_height = $height; + } + if ($group ne '') { + $new_console_id_group = $group; + } + if ($background_color ne '') { + $new_background_color = $background_color; + } + + print_log "[INFO] The visual console with id $id is updated \n\n"; + + db_update ($dbh, "UPDATE tlayout SET name = '" . $new_name . "', background = '" . $new_background . "', width = " . $new_console_width . ", height = " . $new_console_height . ", id_group = " . $new_console_id_group . ", background_color = '" . $new_background_color . "' WHERE id = " . $id); + + if ($elements ne '') { + my $elements_in_array = decode_json($elements); + + if ($mode eq 'static_objects') { + foreach my $elem (@$elements_in_array) { + if (defined($elem->{'id'})) { + + print_log "[INFO] Edit element with id " . $elem->{'id'} . " \n\n"; + + my $element_in_db = get_db_single_row ($dbh, "SELECT * + FROM tlayout_data + WHERE id = " . $elem->{'id'}); + + my $new_pos_x = $element_in_db->{'pos_x'}; + my $new_pos_y = $element_in_db->{'pos_y'}; + my $new_width = $element_in_db->{'width'}; + my $new_height = $element_in_db->{'height'}; + my $new_label = $element_in_db->{'label'}; + my $new_image = $element_in_db->{'image'}; + my $new_type = $element_in_db->{'type'}; + my $new_period = $element_in_db->{'period'}; + my $new_id_agente_modulo = $element_in_db->{'id_agente_modulo'}; + my $new_id_agent = $element_in_db->{'id_agent'}; + my $new_id_layout_linked = $element_in_db->{'id_layout_linked'}; + my $new_parent_item = $element_in_db->{'parent_item'}; + my $new_enable_link = $element_in_db->{'enable_link'}; + my $new_id_metaconsole = $element_in_db->{'id_metaconsole'}; + my $new_id_group = $element_in_db->{'id_group'}; + my $new_id_custom_graph = $element_in_db->{'id_custom_graph'}; + my $new_border_width = $element_in_db->{'border_width'}; + my $new_type_graph = $element_in_db->{'type_graph'}; + my $new_label_position = $element_in_db->{'label_position'}; + my $new_border_color = $element_in_db->{'border_color'}; + my $new_fill_color = $element_in_db->{'fill_color'}; + + if(defined($elem->{'pos_x'})) { + $new_pos_x = $elem->{'pos_x'}; + } + if(defined($elem->{'pos_y'})) { + $new_pos_y = $elem->{'pos_y'}; + } + if(defined($elem->{'width'})) { + $new_width = $elem->{'width'}; + } + if(defined($elem->{'height'})) { + $new_height = $elem->{'height'}; + } + if(defined($elem->{'label'})) { + $new_label = $elem->{'label'}; + } + if(defined($elem->{'image'})) { + $new_image = $elem->{'image'}; + } + if(defined($elem->{'type'})) { + $new_type = $elem->{'type'}; + } + if(defined($elem->{'period'})) { + $new_period = $elem->{'period'}; + } + if(defined($elem->{'id_agente_modulo'})) { + $new_id_agente_modulo = $elem->{'id_agente_modulo'}; + } + if(defined($elem->{'id_agent'})) { + $new_id_agent = $elem->{'id_agent'}; + } + if(defined($elem->{'id_layout_linked'})) { + $new_id_layout_linked = $elem->{'id_layout_linked'}; + } + if(defined($elem->{'parent_item'})) { + $new_parent_item = $elem->{'parent_item'}; + } + if(defined($elem->{'enable_link'})) { + $new_enable_link = $elem->{'enable_link'}; + } + if(defined($elem->{'id_metaconsole'})) { + $new_id_metaconsole = $elem->{'id_metaconsole'}; + } + if(defined($elem->{'id_group'})) { + $new_id_group = $elem->{'id_group'}; + } + if(defined($elem->{'id_custom_graph'})) { + $new_id_custom_graph = $elem->{'id_custom_graph'}; + } + if(defined($elem->{'border_width'})) { + $new_border_width = $elem->{'border_width'}; + } + if(defined($elem->{'type_graph'})) { + $new_type_graph = $elem->{'type_graph'}; + } + if(defined($elem->{'label_position'})) { + $new_label_position = $elem->{'label_position'}; + } + if(defined($elem->{'border_color'})) { + $new_border_color = $elem->{'border_color'}; + } + if(defined($elem->{'fill_color'})) { + $new_fill_color = $elem->{'fill_color'}; + } + + db_update ($dbh, "UPDATE tlayout_data SET pos_x = " . $new_pos_x . ", pos_y = " . $new_pos_y . ", width = " . $new_width . + ", height = " . $new_height . ", label = '" . $new_label . "', image = '" . $new_image . + "', type = " . $new_type . ", period = " . $new_period . ", id_agente_modulo = " . $new_id_agente_modulo . + ", id_agent = " . $new_id_agent . ", id_layout_linked = " . $new_id_layout_linked . ", parent_item = " . $new_parent_item . + ", enable_link = " . $new_enable_link . ", id_metaconsole = " . $new_id_metaconsole . ", id_group = " . $new_id_group . + ", id_custom_graph = " . $new_id_custom_graph . ", border_width = " . $new_border_width . ", type_graph = '" . $new_type_graph . + "', label_position = '" . $new_label_position . "', border_color = '" . $new_border_color . "', fill_color = '" . $new_fill_color . + "' WHERE id = " . $elem->{'id'}); + + print_log "[INFO] Element with id " . $elem->{'id'} . " has been updated \n\n"; + } + else { + my $pos_x = $elem->{'pos_x'}; + my $pos_y = $elem->{'pos_y'}; + my $width = $elem->{'width'}; + my $height = $elem->{'height'}; + my $label = $elem->{'label'}; + my $image = $elem->{'image'}; + my $type = $elem->{'type'}; + my $period = $elem->{'period'}; + my $id_agente_modulo = $elem->{'id_agente_modulo'}; + my $id_agent = $elem->{'id_agent'}; + my $id_layout_linked = $elem->{'id_layout_linked'}; + my $parent_item = $elem->{'parent_item'}; + my $enable_link = $elem->{'enable_link'}; + my $id_metaconsole = $elem->{'id_metaconsole'}; + my $id_group = $elem->{'id_group'}; + my $id_custom_graph = $elem->{'id_custom_graph'}; + my $border_width = $elem->{'border_width'}; + my $type_graph = $elem->{'type_graph'}; + my $label_position = $elem->{'label_position'}; + my $border_color = $elem->{'border_color'}; + my $fill_color = $elem->{'fill_color'}; + + my $new_elem_id = db_insert ($dbh, 'id', 'INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_agent, id_layout_linked, parent_item, enable_link, id_metaconsole, id_group, id_custom_graph, border_width, type_graph, label_position, border_color, fill_color, show_statistics) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id, $pos_x, $pos_y, $height, $width, $label, $image, $type, $period, $id_agente_modulo, $id_agent, $id_layout_linked, $parent_item, $enable_link, $id_metaconsole, $id_group, $id_custom_graph, $border_width, $type_graph, $label_position, $border_color, $fill_color, 0); + + print_log "[INFO] New element with id $new_elem_id has been created \n\n"; + } + } + } + elsif ($mode eq 'auto_creation') { + if ($element_square_positions eq '') { + print_log "[ERROR] With this mode, square positions is obligatory'.\n\n"; + exit 1; + } + else { + my $positions = decode_json($element_square_positions); + + my $pos1X = $positions->{'pos1x'}; + my $pos1Y = $positions->{'pos1y'}; + my $pos2X = $positions->{'pos2x'}; + my $pos2Y = $positions->{'pos2y'}; + + my $number_of_elements = scalar(@$elements_in_array); + + my $x_divider = 4; + my $y_divider = 1; + + for (my $i = 1; $i <= 1000; $i++) { + if (($i * 4) < $number_of_elements) { + $y_divider++; + } + else { + last; + } + } + + my $elem_width = ($pos2X - $pos1X) / $x_divider; + my $elem_height = ($pos2Y - $pos1Y) / $y_divider; + + if ($number_of_elements < 4) { + $elem_height = ($pos2Y - $pos1Y) / 3; + } + + my $elem_count = 1; + my $pos_helper_x = 0; + my $pos_helper_y = 0; + foreach my $elem (@$elements_in_array) { + my $pos_x = $pos_helper_x * $elem_width; + my $pos_y = $pos_helper_y * $elem_height; + my $width = $elem_width; + my $height = $elem_height; + my $label = $elem->{'label'}; + my $image = $elem->{'image'}; + my $type = $elem->{'type'}; + my $period = $elem->{'period'}; + my $id_agente_modulo = $elem->{'id_agente_modulo'}; + my $id_agent = $elem->{'id_agent'}; + my $id_layout_linked = $elem->{'id_layout_linked'}; + my $parent_item = $elem->{'parent_item'}; + my $enable_link = $elem->{'enable_link'}; + my $id_metaconsole = $elem->{'id_metaconsole'}; + my $id_group = $elem->{'id_group'}; + my $id_custom_graph = $elem->{'id_custom_graph'}; + my $border_width = $elem->{'border_width'}; + my $type_graph = $elem->{'type_graph'}; + my $label_position = $elem->{'label_position'}; + my $border_color = $elem->{'border_color'}; + my $fill_color = $elem->{'fill_color'}; + + my $elem_id = db_insert ($dbh, 'id', 'INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_agent, id_layout_linked, parent_item, enable_link, id_metaconsole, id_group, id_custom_graph, border_width, type_graph, label_position, border_color, fill_color, show_statistics) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id, $pos_x, $pos_y, $height, $width, $label, $image, $type, $period, $id_agente_modulo, $id_agent, $id_layout_linked, $parent_item, $enable_link, $id_metaconsole, $id_group, $id_custom_graph, $border_width, $type_graph, $label_position, $border_color, $fill_color, 0); + + print_log "[INFO] The element id in position $elem_count is '$elem_id' \n\n"; + + $elem_count++; + + if ($pos_helper_x == 3) { + $pos_helper_x = 0; + $pos_helper_y++; + } + else { + $pos_helper_x++; + } + } + } + } + else { + print_log "[ERROR] Mode parameter must be 'static_objects' or 'auto_creation'.\n\n"; + exit 1; + } + } +} + ############################################################################## # Delete a visual console. # Related option: --delete_visual_console @@ -5589,7 +5860,7 @@ sub pandora_manage_main ($$$) { cli_create_visual_console(); } elsif ($param eq '--edit_visual_console') { - param_check($ltotal, 6, 2); + param_check($ltotal, 10, 9); cli_edit_visual_console(); } elsif ($param eq '--delete_visual_console') { From 4fd4783bc56733368813bd2a87f6fb8ccf2dc2bb Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Thu, 14 Sep 2017 13:14:31 +0200 Subject: [PATCH 9/9] Added edit function with auto position --- pandora_server/util/pandora_manage.pl | 171 ++++++++++++++++++++++---- 1 file changed, 144 insertions(+), 27 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 8cdb7df9b8..9af7840fe9 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -5117,6 +5117,135 @@ sub cli_edit_visual_console() { exit 1; } else { + foreach my $elem (@$elements_in_array) { + if (defined($elem->{'id'})) { + print_log "[INFO] Edit element with id " . $elem->{'id'} . " \n\n"; + + my $element_in_db = get_db_single_row ($dbh, "SELECT * + FROM tlayout_data + WHERE id = " . $elem->{'id'}); + + my $new_pos_x = $element_in_db->{'pos_x'}; + my $new_pos_y = $element_in_db->{'pos_y'}; + my $new_width = $element_in_db->{'width'}; + my $new_height = $element_in_db->{'height'}; + my $new_label = $element_in_db->{'label'}; + my $new_image = $element_in_db->{'image'}; + my $new_type = $element_in_db->{'type'}; + my $new_period = $element_in_db->{'period'}; + my $new_id_agente_modulo = $element_in_db->{'id_agente_modulo'}; + my $new_id_agent = $element_in_db->{'id_agent'}; + my $new_id_layout_linked = $element_in_db->{'id_layout_linked'}; + my $new_parent_item = $element_in_db->{'parent_item'}; + my $new_enable_link = $element_in_db->{'enable_link'}; + my $new_id_metaconsole = $element_in_db->{'id_metaconsole'}; + my $new_id_group = $element_in_db->{'id_group'}; + my $new_id_custom_graph = $element_in_db->{'id_custom_graph'}; + my $new_border_width = $element_in_db->{'border_width'}; + my $new_type_graph = $element_in_db->{'type_graph'}; + my $new_label_position = $element_in_db->{'label_position'}; + my $new_border_color = $element_in_db->{'border_color'}; + my $new_fill_color = $element_in_db->{'fill_color'}; + + if(defined($elem->{'width'})) { + $new_width = $elem->{'width'}; + } + if(defined($elem->{'height'})) { + $new_height = $elem->{'height'}; + } + if(defined($elem->{'label'})) { + $new_label = $elem->{'label'}; + } + if(defined($elem->{'image'})) { + $new_image = $elem->{'image'}; + } + if(defined($elem->{'type'})) { + $new_type = $elem->{'type'}; + } + if(defined($elem->{'period'})) { + $new_period = $elem->{'period'}; + } + if(defined($elem->{'id_agente_modulo'})) { + $new_id_agente_modulo = $elem->{'id_agente_modulo'}; + } + if(defined($elem->{'id_agent'})) { + $new_id_agent = $elem->{'id_agent'}; + } + if(defined($elem->{'id_layout_linked'})) { + $new_id_layout_linked = $elem->{'id_layout_linked'}; + } + if(defined($elem->{'parent_item'})) { + $new_parent_item = $elem->{'parent_item'}; + } + if(defined($elem->{'enable_link'})) { + $new_enable_link = $elem->{'enable_link'}; + } + if(defined($elem->{'id_metaconsole'})) { + $new_id_metaconsole = $elem->{'id_metaconsole'}; + } + if(defined($elem->{'id_group'})) { + $new_id_group = $elem->{'id_group'}; + } + if(defined($elem->{'id_custom_graph'})) { + $new_id_custom_graph = $elem->{'id_custom_graph'}; + } + if(defined($elem->{'border_width'})) { + $new_border_width = $elem->{'border_width'}; + } + if(defined($elem->{'type_graph'})) { + $new_type_graph = $elem->{'type_graph'}; + } + if(defined($elem->{'label_position'})) { + $new_label_position = $elem->{'label_position'}; + } + if(defined($elem->{'border_color'})) { + $new_border_color = $elem->{'border_color'}; + } + if(defined($elem->{'fill_color'})) { + $new_fill_color = $elem->{'fill_color'}; + } + + db_update ($dbh, "UPDATE tlayout_data SET pos_x = " . $new_pos_x . ", pos_y = " . $new_pos_y . ", width = " . $new_width . + ", height = " . $new_height . ", label = '" . $new_label . "', image = '" . $new_image . + "', type = " . $new_type . ", period = " . $new_period . ", id_agente_modulo = " . $new_id_agente_modulo . + ", id_agent = " . $new_id_agent . ", id_layout_linked = " . $new_id_layout_linked . ", parent_item = " . $new_parent_item . + ", enable_link = " . $new_enable_link . ", id_metaconsole = " . $new_id_metaconsole . ", id_group = " . $new_id_group . + ", id_custom_graph = " . $new_id_custom_graph . ", border_width = " . $new_border_width . ", type_graph = '" . $new_type_graph . + "', label_position = '" . $new_label_position . "', border_color = '" . $new_border_color . "', fill_color = '" . $new_fill_color . + "' WHERE id = " . $elem->{'id'}); + + print_log "[INFO] Element with id " . $elem->{'id'} . " has been updated \n\n"; + } + else { + my $pos_x = 0; + my $pos_y = 0; + my $width = $elem->{'width'}; + my $height = $elem->{'height'}; + my $label = $elem->{'label'}; + my $image = $elem->{'image'}; + my $type = $elem->{'type'}; + my $period = $elem->{'period'}; + my $id_agente_modulo = $elem->{'id_agente_modulo'}; + my $id_agent = $elem->{'id_agent'}; + my $id_layout_linked = $elem->{'id_layout_linked'}; + my $parent_item = $elem->{'parent_item'}; + my $enable_link = $elem->{'enable_link'}; + my $id_metaconsole = $elem->{'id_metaconsole'}; + my $id_group = $elem->{'id_group'}; + my $id_custom_graph = $elem->{'id_custom_graph'}; + my $border_width = $elem->{'border_width'}; + my $type_graph = $elem->{'type_graph'}; + my $label_position = $elem->{'label_position'}; + my $border_color = $elem->{'border_color'}; + my $fill_color = $elem->{'fill_color'}; + + my $new_elem_id = db_insert ($dbh, 'id', 'INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_agent, id_layout_linked, parent_item, enable_link, id_metaconsole, id_group, id_custom_graph, border_width, type_graph, label_position, border_color, fill_color, show_statistics) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id, $pos_x, $pos_y, $height, $width, $label, $image, $type, $period, $id_agente_modulo, $id_agent, $id_layout_linked, $parent_item, $enable_link, $id_metaconsole, $id_group, $id_custom_graph, $border_width, $type_graph, $label_position, $border_color, $fill_color, 0); + + print_log "[INFO] New element with id $new_elem_id has been created \n\n"; + } + } + my $positions = decode_json($element_square_positions); my $pos1X = $positions->{'pos1x'}; @@ -5124,8 +5253,12 @@ sub cli_edit_visual_console() { my $pos2X = $positions->{'pos2x'}; my $pos2Y = $positions->{'pos2y'}; - my $number_of_elements = scalar(@$elements_in_array); - + my @console_elements = get_db_rows ($dbh, "SELECT * + FROM tlayout_data + WHERE id_layout = $id"); + + my $number_of_elements = scalar(@console_elements); + my $x_divider = 4; my $y_divider = 1; @@ -5148,33 +5281,17 @@ sub cli_edit_visual_console() { my $elem_count = 1; my $pos_helper_x = 0; my $pos_helper_y = 0; - foreach my $elem (@$elements_in_array) { - my $pos_x = $pos_helper_x * $elem_width; - my $pos_y = $pos_helper_y * $elem_height; - my $width = $elem_width; - my $height = $elem_height; - my $label = $elem->{'label'}; - my $image = $elem->{'image'}; - my $type = $elem->{'type'}; - my $period = $elem->{'period'}; - my $id_agente_modulo = $elem->{'id_agente_modulo'}; - my $id_agent = $elem->{'id_agent'}; - my $id_layout_linked = $elem->{'id_layout_linked'}; - my $parent_item = $elem->{'parent_item'}; - my $enable_link = $elem->{'enable_link'}; - my $id_metaconsole = $elem->{'id_metaconsole'}; - my $id_group = $elem->{'id_group'}; - my $id_custom_graph = $elem->{'id_custom_graph'}; - my $border_width = $elem->{'border_width'}; - my $type_graph = $elem->{'type_graph'}; - my $label_position = $elem->{'label_position'}; - my $border_color = $elem->{'border_color'}; - my $fill_color = $elem->{'fill_color'}; + foreach my $elem (@console_elements) { + my $new_pos_x = $pos_helper_x * $elem_width; + my $new_pos_y = $pos_helper_y * $elem_height; + my $new_elem_width = $elem_width; + my $new_elem_height = $elem_height; - my $elem_id = db_insert ($dbh, 'id', 'INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_agent, id_layout_linked, parent_item, enable_link, id_metaconsole, id_group, id_custom_graph, border_width, type_graph, label_position, border_color, fill_color, show_statistics) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id, $pos_x, $pos_y, $height, $width, $label, $image, $type, $period, $id_agente_modulo, $id_agent, $id_layout_linked, $parent_item, $enable_link, $id_metaconsole, $id_group, $id_custom_graph, $border_width, $type_graph, $label_position, $border_color, $fill_color, 0); + db_update ($dbh, "UPDATE tlayout_data SET pos_x = " . $new_pos_x . ", pos_y = " . $new_pos_y . + ", width = " . $new_elem_width . ", height = " . $new_elem_height . + " WHERE id = " . $elem->{'id'}); - print_log "[INFO] The element id in position $elem_count is '$elem_id' \n\n"; + print_log "[INFO] Recolocate element with id " . $elem->{'id'} . " \n\n"; $elem_count++;