diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 97e312f4b4..8899bc4979 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2012-04-13 Sergio Martin + + * include/functions_visual_map.php + include/ajax/visual_console_builder.ajax.php + godmode/reporting/visual_console_builder.editor.js: Fixed several + bugs in the simple value item in the visual console and unified + repeated code merged from 4.0 + 2012-04-13 Miguel de Dios * include/functions_config.php, index.php, diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index 3af8396450..f37af2b6c2 100644 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -258,6 +258,7 @@ function updateAction() { break; case 'simple_value': $("#text_" + idItem).html(values['label']); + $("#simplevalue_" + idItem).html(getModuleValue(idItem,values['process_simple_value'])); break; case 'label': $("#" + idItem).css('color', values['label_color']); @@ -394,10 +395,6 @@ function createAction() { alert($("#message_alert_no_module").html()); validate = false; } - if ((values['process_simple_value'] == 0)) { - alert($("#message_alert_no_process").html()); - validate = false; - } break; } @@ -769,11 +766,14 @@ function getModuleGraph(id_data) { return img; } -function getModuleValue(id_data) { +function getModuleValue(id_data, process_simple_value) { var parameter = Array(); parameter.push ({name: "page", value: "include/ajax/visual_console_builder.ajax"}); parameter.push ({name: "action", value: "get_module_value"}); parameter.push ({name: "id_element", value: id_data}); + if(process_simple_value != undefined) { + parameter.push ({name: "process_simple_value", value: process_simple_value}); + } jQuery.ajax({ async: false, url: "ajax.php", diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php index e98960953b..582e00b554 100644 --- a/pandora_console/include/ajax/visual_console_builder.ajax.php +++ b/pandora_console/include/ajax/visual_console_builder.ajax.php @@ -89,47 +89,12 @@ switch ($action) { $unit_text = false; $layoutData = db_get_row_filter('tlayout_data', array('id' => $id_element)); switch ($layoutData['type']) { + case SIMPLE_VALUE: case SIMPLE_VALUE_MAX: - $unit = db_get_sql ('SELECT unit FROM tagente_modulo WHERE id_agente_modulo = ' . $layoutData['id_agente_modulo']); - $unit = trim(io_safe_output($unit)); - - $value = reporting_get_agentmodule_data_max ($layoutData['id_agente_modulo'], 86400, 0); - if ($value === false) { - $returnValue = __('Unknown'); - } - else { - $returnValue = format_for_graph($returnValue, 2); - if (!empty($unit_text)) - $returnValue .= " " . $unit_text; - } - break; case SIMPLE_VALUE_MIN: - $unit = db_get_sql ('SELECT unit FROM tagente_modulo WHERE id_agente_modulo = ' . $layoutData['id_agente_modulo']); - $unit = trim(io_safe_output($unit)); - - $value = reporting_get_agentmodule_data_min ($layoutData['id_agente_modulo'], 86400, 0); - if ($value === false) { - $returnValue = __('Unknown'); - } - else { - $returnValue = format_for_graph($returnValue, 2); - if (!empty($unit_text)) - $returnValue .= " " . $unit_text; - } - break; case SIMPLE_VALUE_AVG: - $unit = db_get_sql ('SELECT unit FROM tagente_modulo WHERE id_agente_modulo = ' . $layoutData['id_agente_modulo']); - $unit = trim(io_safe_output($unit)); - - $value = reporting_get_agentmodule_data_average ($layoutData['id_agente_modulo'], 86400, 0); - if ($value === false) { - $returnValue = __('Unknown'); - } - else { - $returnValue = format_for_graph($returnValue, 2); - if (!empty($unit_text)) - $returnValue .= " " . $unit_text; - } + $type = visual_map_get_simple_value_type($process_simple_value); + $returnValue = visual_map_get_simple_value($type, $layoutData['id_agente_modulo']); break; case PERCENTILE_BAR: case PERCENTILE_BUBBLE: @@ -235,9 +200,9 @@ switch ($action) { break; case 'update': case 'move': + $values = array(); switch ($type) { case 'background': - $values = array(); if ($background !== null) $values['background'] = $background; if ($width !== null) @@ -248,13 +213,13 @@ switch ($action) { echo (int)$result; break; case 'simple_value': + $values['type'] = visual_map_get_simple_value_type($process_simple_value); case 'percentile_bar': case 'percentile_item': case 'static_graph': case 'module_graph': case 'label': case 'icon': - $values = array(); if ($label !== null) { $values['label'] = $label; } @@ -456,21 +421,8 @@ switch ($action) { $values['height'] = $height; break; case 'simple_value': - //This allows min, max and avg process in a simple value - switch ($process_simple_value){ - case 0: - $values['type'] = SIMPLE_VALUE; - break; - case 1: - $values['type'] = SIMPLE_VALUE_MIN; - break; - case 2: - $values['type'] = SIMPLE_VALUE_MAX; - break; - case 3: - $values['type'] = SIMPLE_VALUE_AVG; - break; - } + //This allows min, max and avg process in a simple value + $values['type'] = visual_map_get_simple_value_type($process_simple_value); break; case 'label': $values['type'] = LABEL; diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 70b1b5eca3..cbd05a880a 100644 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -234,57 +234,10 @@ function visual_map_print_item($layoutData) { case SIMPLE_VALUE_MAX: case SIMPLE_VALUE_MIN: case SIMPLE_VALUE_AVG: - $unit_text = db_get_sql ('SELECT unit FROM tagente_modulo WHERE id_agente_modulo = ' . $id_module); - $unit_text = trim(io_safe_output($unit_text)); - - echo '
'; + echo '
'; echo $text; - switch ($type){ - case SIMPLE_VALUE: - $value = db_get_value ('datos', 'tagente_estado', 'id_agente_modulo', $id_module); - $value = format_for_graph($value, 2); - if (!empty($unit_text)) - $value .= " " . $unit_text; - echo ' ' . $value . ''; - break; - case SIMPLE_VALUE_MAX: - $value = reporting_get_agentmodule_data_max ($id_module, 86400, 0); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2); - if (!empty($unit_text)) - $value .= " " . $unit_text; - } - - echo ' ' . $value . ''; - break; - case SIMPLE_VALUE_MIN: - $value = reporting_get_agentmodule_data_min ($id_module, 86400, 0); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2); - if (!empty($unit_text)) - $value .= " " . $unit_text; - } - echo ' ' . $value . ''; - break; - case SIMPLE_VALUE_AVG: - $value = reporting_get_agentmodule_data_average ($id_module, 86400, 0); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2); - if (!empty($unit_text)) - $value .= " " . $unit_text; - } - echo ' ' . $value . ''; - break; - } + $value = visual_map_get_simple_value($type, $id_module); + echo ' ' . $value . ''; echo '
'; break; case LABEL: @@ -328,6 +281,90 @@ function visual_map_print_item($layoutData) { } } +/** + * The function to get simple value type from the value of process type in the form + * + * @param int process simple value from form + * + * @return int type among the constants: + * SIMPLE_VALUE, SIMPLE_VALUE_MAX, SIMPLE_VALUE_MIN, SIMPLE_VALUE_AVG + */ +function visual_map_get_simple_value_type($process_simple_value) { + switch ($process_simple_value){ + case 0: + return SIMPLE_VALUE; + break; + case 1: + return SIMPLE_VALUE_MIN; + break; + case 2: + return SIMPLE_VALUE_MAX; + break; + case 3: + return SIMPLE_VALUE_AVG; + break; + } +} + +/** + * The function to get the simple value of a module + * + * @param int type of the retrieving choosed among the constants: + * SIMPLE_VALUE, SIMPLE_VALUE_MAX, SIMPLE_VALUE_MIN, SIMPLE_VALUE_AVG + * @param int id agent module + * + * @return string value retrieved with units + */ +function visual_map_get_simple_value($type, $id_module) { + $unit_text = db_get_sql ('SELECT unit FROM tagente_modulo WHERE id_agente_modulo = ' . $id_module); + $unit_text = trim(io_safe_output($unit_text)); + switch ($type){ + case SIMPLE_VALUE: + $value = db_get_value ('datos', 'tagente_estado', 'id_agente_modulo', $id_module); + $value = format_for_graph($value, 2); + if (!empty($unit_text)) + $value .= " " . $unit_text; + return $value; + break; + case SIMPLE_VALUE_MAX: + $value = reporting_get_agentmodule_data_max ($id_module, 86400, 0); + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = format_for_graph($value, 2); + if (!empty($unit_text)) + $value .= " " . $unit_text; + } + return $value; + break; + case SIMPLE_VALUE_MIN: + $value = reporting_get_agentmodule_data_min ($id_module, 86400, 0); + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = format_for_graph($value, 2); + if (!empty($unit_text)) + $value .= " " . $unit_text; + } + return $value; + break; + case SIMPLE_VALUE_AVG: + $value = reporting_get_agentmodule_data_average ($id_module, 86400, 0); + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = format_for_graph($value, 2); + if (!empty($unit_text)) + $value .= " " . $unit_text; + } + return $value; + break; + } +} + /** * The function to save the new elements of agents make as wizard. *