From 2a8afbe2374ce6deec03a75e5236dc93d9789285 Mon Sep 17 00:00:00 2001 From: juanmanuelr Date: Mon, 25 Jun 2012 15:30:05 +0000 Subject: [PATCH] 2012-06-25 Juan Manuel Ramon * include/functions_visual_map.php godmode/reporting/visual_console_builder.wizard.php godmode/reporting/visual_console_builder.php: Visual console wizard 'item per agent' functionality. Merged from branches. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6701 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 9 ++ .../reporting/visual_console_builder.php | 98 +++++++++------- .../visual_console_builder.wizard.php | 56 ++++++++-- .../include/functions_visual_map.php | 105 ++++++++++++++++++ 4 files changed, 221 insertions(+), 47 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 9573f88042..a89468664b 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,12 @@ +2012-06-25 Juan Manuel Ramon + + * include/functions_visual_map.php + godmode/reporting/visual_console_builder.wizard.php + godmode/reporting/visual_console_builder.php: Visual console + wizard 'item per agent' functionality. + + Merged from branches. + 2012-06-25 Miguel de Dios * include/functions_graph.php, include/functions_reporting.php, diff --git a/pandora_console/godmode/reporting/visual_console_builder.php b/pandora_console/godmode/reporting/visual_console_builder.php index 3c2e0c5a32..1b7c7d89fd 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.php +++ b/pandora_console/godmode/reporting/visual_console_builder.php @@ -187,56 +187,74 @@ switch ($activeTab) { $type_percentile = get_parameter ("type_percentile", 'percentile'); $value_show = get_parameter ("value_show", 'percent'); $label_type = get_parameter ("label_type", 'agent_module'); + // This var switch between creation of items, item_per_agent = 0 => item per module; item_per_agent <> 0 => item per agent + $item_per_agent = get_parameter ("item_per_agent", 0); $message = ''; - if (empty($name_modules)) { - $statusProcessInDB = array('flag' => true, 'message' => ui_print_error_message (__('No modules selected'), '', true)); - } - else { - //Any module - if ($name_modules[0] == '0') { - $id_modules = array(); - foreach ($id_agents as $id_agent) { - $id_modulo = agents_get_modules($id_agent, array('id_agente_modulo')); - if (empty($id_modulo)) $id_modulo = array(); - - foreach ($id_modulo as $id) { - $id_modules[] = $id['id_agente_modulo']; - } - } + // One item per agent + if ($item_per_agent == 1) { + $id_agents_result = array(); + foreach ($id_agents as $id_agent_key => $id_agent_id) + $id_agents_result[] = $id_agent_id; + + $message .= visual_map_process_wizard_add_agents($id_agents_result, + $image, $idVisualConsole, $range, $width, $height, + $period, $process_value, $percentileitem_width, + $max_value, $type_percentile, $value_show, $label_type, $type); - $message .= visual_map_process_wizard_add_modules($id_modules, - $image, $idVisualConsole, $range, $width, $height, - $period, $process_value, $percentileitem_width, - $max_value, $type_percentile, $value_show, $label_type, $type); + $statusProcessInDB = array('flag' => true, 'message' => $message); + + } else { + // One item per module + if (empty($name_modules)) { + $statusProcessInDB = array('flag' => true, 'message' => ui_print_error_message (__('No modules selected'), '', true)); } else { - $id_modules = array(); - - foreach ($name_modules as $mod) { - foreach ($id_agents as $ag) { - $id_module = agents_get_modules($ag, - array('id_agente_modulo'), - array('nombre' => $mod)); - - if (empty($id_module)) - continue; - else { - $id_module = reset($id_module); - $id_module = $id_module['id_agente_modulo']; - } + //Any module + if ($name_modules[0] == '0') { + $id_modules = array(); + foreach ($id_agents as $id_agent) { + $id_modulo = agents_get_modules($id_agent, array('id_agente_modulo')); + if (empty($id_modulo)) $id_modulo = array(); - $id_modules[] = $id_module; + foreach ($id_modulo as $id) { + $id_modules[] = $id['id_agente_modulo']; + } } + + $message .= visual_map_process_wizard_add_modules($id_modules, + $image, $idVisualConsole, $range, $width, $height, + $period, $process_value, $percentileitem_width, + $max_value, $type_percentile, $value_show, $label_type, $type); } - - $message .= visual_map_process_wizard_add_modules($id_modules, - $image, $idVisualConsole, $range, $width, $height, - $period, $process_value, $percentileitem_width, - $max_value, $type_percentile, $value_show, $label_type, $type); + else { + $id_modules = array(); + + foreach ($name_modules as $mod) { + foreach ($id_agents as $ag) { + $id_module = agents_get_modules($ag, + array('id_agente_modulo'), + array('nombre' => $mod)); + + if (empty($id_module)) + continue; + else { + $id_module = reset($id_module); + $id_module = $id_module['id_agente_modulo']; + } + + $id_modules[] = $id_module; + } + } + + $message .= visual_map_process_wizard_add_modules($id_modules, + $image, $idVisualConsole, $range, $width, $height, + $period, $process_value, $percentileitem_width, + $max_value, $type_percentile, $value_show, $label_type, $type); + } + $statusProcessInDB = array('flag' => true, 'message' => $message); } - $statusProcessInDB = array('flag' => true, 'message' => $message); } $action = 'edit'; break; diff --git a/pandora_console/godmode/reporting/visual_console_builder.wizard.php b/pandora_console/godmode/reporting/visual_console_builder.wizard.php index 71dd5193d6..0e051183ef 100644 --- a/pandora_console/godmode/reporting/visual_console_builder.wizard.php +++ b/pandora_console/godmode/reporting/visual_console_builder.wizard.php @@ -34,7 +34,12 @@ $table->data = array (); $table->style = array (); $table->style[0] = 'font-weight: bold; vertical-align: text-top;'; $table->style[1] = 'font-weight: bold; vertical-align: top;'; +$table->style[2] = 'font-weight: bold; vertical-align: top'; $table->size = array (); +$table->size[0] = "20%"; +$table->size[1] = "20%"; +$table->size[2] = "20%"; +$table->size[3] = "20%"; $table->data = array (); $images_list = array (); @@ -72,7 +77,7 @@ $table->data["all_1"][1] = html_print_input_text ('range', 50, '', 5, 5, true); $table->rowstyle["staticgraph_modulegraph"] = 'display: none;'; $table->data["staticgraph_modulegraph"][0] = __('Size (px)'); $table->data["staticgraph_modulegraph"][1] = __('Width').': '.html_print_input_text ('width', 0, '', 5, 5, true); -$table->data["staticgraph_modulegraph"][1] .= ' ' . __('Height').': '.html_print_input_text ('height', 0, '', 5, 5, true); +$table->data["staticgraph_modulegraph"][1] .= '   ' . __('Height').': '.html_print_input_text ('height', 0, '', 5, 5, true); $table->rowstyle["modulegraph_simplevalue"] = 'display: none;'; $table->data["modulegraph_simplevalue"][0] = __('Period'); @@ -108,12 +113,21 @@ $table->data["all_2"][0] = __('Groups'); $table->data["all_2"][1] = html_print_select_groups($config['id_user'], "AR", true, 'groups', '', '', '', 0, true); +$table->rowstyle["all_one_item_per_agent"] = 'display: none'; +$table->data["all_one_item_per_agent"][0] = __('One item per agent'); +$table->data["all_one_item_per_agent"][1] = __('Yes').'   '.html_print_radio_button_extended ('item_per_agent', 1, '', '', false, 'item_per_agent_change(1)', '', true).'  '; +$table->data["all_one_item_per_agent"][1] .= __('No').'   '.html_print_radio_button_extended ('item_per_agent', 0, '', 0, false, 'item_per_agent_change(0)', '', true); +$table->data["all_one_item_per_agent"][1] .= html_print_input_hidden ('item_per_agent_test', 0, true); + $table->rowstyle["all_3"] = 'display: none;'; $table->data["all_3"][0] = __('Agents'); + $table->data["all_3"][1] = html_print_select (agents_get_group_agents (0, false, "none", false, true), - 'id_agents[]', 0, false, '', '', true, true) . - ' ' . __('Modules') . '' . - html_print_select (array (), 'module[]', 0, false, __('None'), -1, true, true); + 'id_agents[]', 0, false, '', '', true, true); + +$table->data["all_3"][2] = ' ' . __('Modules') . ''; + +$table->data["all_3"][3] = html_print_select (array (), 'module[]', 0, false, __('None'), -1, true, true); $table->rowstyle["all_5"] = 'display: none;'; $table->data["all_5"][0] = __('Label'); @@ -126,8 +140,7 @@ $table->data["all_5"][1] = html_print_select ($label_type, 'label_type', 'agent_ echo '
'; -$table->size[0] = "20%"; -$table->size[1] = "80%"; + html_print_table ($table); echo '
'; @@ -204,7 +217,11 @@ $(document).ready (function () { return; }); - $("#id_agents").change (agent_changed_by_multiple_agents); + + $("#id_agents").change ( function() { + if ($("#hidden-item_per_agent_test").val() == 0) + agent_changed_by_multiple_agents(); + }); }); function check_fields() { @@ -247,4 +264,29 @@ function hidden_rows() { break; } } + +function item_per_agent_change(itemPerAgent) { + + // Disable Module select + if (itemPerAgent == 1) { + $('#module').empty(); + $('#module').append ($('').html ().attr("value", -1)); + $('#module').attr('disabled', true); + $('#label_type').empty(); + $('#label_type').append ($('').html ().attr('value', 'agent').attr('selected', true)); + $('#label_type').append ($('').html ().attr('value', 'none')); + + $('#hidden-item_per_agent_test').val(1); + } else { + $('#module').removeAttr('disabled'); + $('#hidden-item_per_agent_test').val(0); + $('#label_type').empty(); + $('#label_type').append ($('').html ().attr('value', 'agent')); + $('#label_type').append ($('').html ().attr('value', 'agent_module').attr('selected', true)); + $('#label_type').append ($('').html ().attr('value', 'module')); + $('#label_type').append ($('').html ().attr('value', 'none')); + + } + +} diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 97977d5b2e..d68bd927b0 100644 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -554,6 +554,111 @@ function visual_map_process_wizard_add_modules ($id_modules, $image, $id_layout, return $return; } +/** + * The function to save the new elements of agents make as wizard. + * + * @param array $id_agents The list of id of agents. + * @param string $image The image to set the elements. + * @param integer $id_layout The id of visual console to insert the elements. + * @param integer $range The distance between elements. + * @param integer $width Width of image. + * @param integer $height Height of image. + * + * @return string Return the message status to insert DB. + */ +function visual_map_process_wizard_add_agents ($id_agents, $image, $id_layout, + $range, $width = 0, $height = 0, $period, $process_value, $percentileitem_width, + $max_value, $type_percentile, $value_show, $label_type, $type) { + + if (empty ($id_agents)) { + $return = ui_print_error_message (__('No agents selected'), '', true); + return $return; + } + + $id_agents = (array) $id_agents; + + $error = false; + $pos_y = 10; + $pos_x = 10; + + foreach ($id_agents as $id_agent) { + if ($pos_x > 600) { + $pos_x = 10; + $pos_y = $pos_y + $range; + } + + $value_height = $height; + $value_image = $image; + $value_type = $type; + $value_width = $width; + + switch ($type) { + case PERCENTILE_BAR: + case PERCENTILE_BUBBLE: + $value_height = $max_value; + $value_width = $percentileitem_width; + $value_image = $value_show; + if ($type_percentile == 'percentile') { + $value_type = PERCENTILE_BAR; + } + else { + $value_type = PERCENTILE_BUBBLE; + } + break; + case SIMPLE_VALUE: + $value_image = ''; + switch ($process_value) { + case PROCESS_VALUE_NONE: + $value_type = SIMPLE_VALUE; + break; + case PROCESS_VALUE_MIN: + $value_type = SIMPLE_VALUE_MIN; + break; + case PROCESS_VALUE_MAX: + $value_type = SIMPLE_VALUE_MAX; + break; + case PROCESS_VALUE_AVG: + $value_type = SIMPLE_VALUE_AVG; + break; + } + break; + } + + switch ($label_type) { + case 'agent': + $agent_label = ui_print_truncate_text(agents_get_name ($id_agent), 'agent_small', false, true, false, '…', false); + $label = $agent_label; + break; + case 'none': + $label = ''; + break; + } + $label = io_safe_input($label); + + $values = array ('type' => $value_type, + 'id_layout' => $id_layout, + 'pos_x' => $pos_x, + 'pos_y' => $pos_y, + 'label' => $label, + 'image' => $value_image, + 'id_agent' => $id_agent, + 'id_agente_modulo' => 0, + 'width' => $value_width, + 'period' => $period, + 'height' => $value_height, + 'label_color' => '#000000'); + + db_process_sql_insert ('tlayout_data', $values); + + $pos_x = $pos_x + $range; + } + + $return = ui_print_success_message (__('Agents successfully added to layout'), '', true); + + return $return; +} + + /** * Get the color of line between elements in the visual map. *