From a92d50303deca0938232f2453f463366e2864cad Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 30 Jun 2022 14:09:29 +0200 Subject: [PATCH] fix color tabs and block histogram pandora_enterprise#8621 --- pandora_console/include/functions_html.php | 10 ++- pandora_console/include/functions_modules.php | 4 ++ pandora_console/include/javascript/pandora.js | 20 +++--- .../lib/Dashboard/Widgets/BlockHistogram.php | 23 +++++-- .../lib/Dashboard/Widgets/ColorModuleTabs.php | 68 +++++++++++++++++-- pandora_console/include/styles/dashboards.css | 2 - 6 files changed, 103 insertions(+), 24 deletions(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index a2bf84eabe..94d329fb8e 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -983,6 +983,14 @@ function html_print_select( if ($select2_multiple_enable === true && $select2_multiple_enable_all === true ) { + $output .= 'if($("#'.$id.' > option").length !== $("#'.$id.' > option:selected").length) { + checked = false; + } else { + checked = true; + } + + $("#checkbox-'.$id.'-check-all").prop("checked", checked);'; + $output .= '$("#'.$id.'").on("change", function(e) { var checked = false; if(e.target.length !== $("#'.$id.' > option:selected").length) { @@ -994,8 +1002,6 @@ function html_print_select( $("#checkbox-'.$id.'-check-all").prop("checked", checked); });'; - $output .= '$("#'.$id.'").trigger("change");'; - $output .= 'var count_shift_'.$id.' = 0;'; $output .= 'var shift_array_'.$id.' = [];'; $output .= 'var options_selecteds_'.$id.' = [];'; diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 072d08d607..1cafccce6a 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -3766,6 +3766,10 @@ function get_same_modules($agents, array $modules=[]) return []; } + if (is_array($modules) === false || empty($modules) === true) { + return []; + } + $name_modules = modules_get_agentmodule_name_array_data( array_values($modules) ); diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index be6aac2818..690a9074ff 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -2043,17 +2043,15 @@ function agent_multiple_change(e, info) { }, function(data) { var name = info.modules_name.replace("[]", ""); - if (JSON.stringify($(e).val()) !== JSON.stringify(info.agent_ids)) { - $("#" + name).html(""); - $("#checkbox-" + name + "-check-all").prop("checked", false); - if (data) { - jQuery.each(data, function(id, value) { - var option = $("") - .attr("value", id) - .html(value); - $("#" + name).append(option); - }); - } + $("#" + name).html(""); + $("#checkbox-" + name + "-check-all").prop("checked", false); + if (data) { + jQuery.each(data, function(id, value) { + var option = $("") + .attr("value", id) + .html(value); + $("#" + name).append(option); + }); } }, "json" diff --git a/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php b/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php index a7a655451d..58d28847ce 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php +++ b/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php @@ -230,6 +230,7 @@ class BlockHistogram extends Widget $values['fontColor'] = $decoder['fontColor']; } + $values['label'] = 'module'; if (isset($decoder['label']) === true) { $values['label'] = $decoder['label']; } @@ -272,10 +273,10 @@ class BlockHistogram extends Widget ], ]; - // Type clock. + // Type Label. $fields = [ - 'agent' => __('Agent'), 'module' => __('Module'), + 'agent' => __('Agent'), 'agent_module' => __('Agent / module'), ]; @@ -344,9 +345,23 @@ class BlockHistogram extends Widget 'moduleBlockHistogram' ); + $agColor = []; + if (isset($values['agentsBlockHistogram'][0]) === true + && empty($values['agentsBlockHistogram'][0]) === false + ) { + $agColor = explode(',', $values['agentsBlockHistogram'][0]); + } + + $agModule = []; + if (isset($values['moduleBlockHistogram'][0]) === true + && empty($values['moduleBlockHistogram'][0]) === false + ) { + $agModule = explode(',', $values['moduleBlockHistogram'][0]); + } + $values['moduleBlockHistogram'] = get_same_modules_all( - explode(',', $values['agentsBlockHistogram'][0]), - explode(',', $values['moduleBlockHistogram'][0]) + $agColor, + $agModule ); $values['period'] = \get_parameter('period', 0); diff --git a/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php b/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php index d685a90eac..9883c06b2b 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php +++ b/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php @@ -226,6 +226,11 @@ class ColorModuleTabs extends Widget $values['formatData'] = $decoder['formatData']; } + $values['label'] = 'module'; + if (isset($decoder['label']) === true) { + $values['label'] = $decoder['label']; + } + return $values; } @@ -244,6 +249,24 @@ class ColorModuleTabs extends Widget // Retrieve global - common inputs. $inputs = parent::getFormInputs(); + // Type Label. + $fields = [ + 'module' => __('Module'), + 'agent' => __('Agent'), + 'agent_module' => __('Agent / module'), + ]; + + $inputs[] = [ + 'label' => __('Label'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'name' => 'label', + 'selected' => $values['label'], + 'return' => true, + ], + ]; + $inputs[] = [ 'arguments' => [ 'type' => 'select_multiple_modules_filtered_select2', @@ -295,13 +318,29 @@ class ColorModuleTabs extends Widget 'moduleColorModuleTabs' ); + $agColor = []; + if (isset($values['agentsColorModuleTabs'][0]) === true + && empty($values['agentsColorModuleTabs'][0]) === false + ) { + $agColor = explode(',', $values['agentsColorModuleTabs'][0]); + } + + $agModule = []; + if (isset($values['moduleColorModuleTabs'][0]) === true + && empty($values['moduleColorModuleTabs'][0]) === false + ) { + $agModule = explode(',', $values['moduleColorModuleTabs'][0]); + } + $values['moduleColorModuleTabs'] = get_same_modules_all( - explode(',', $values['agentsColorModuleTabs'][0]), - explode(',', $values['moduleColorModuleTabs'][0]) + $agColor, + $agModule ); $values['formatData'] = \get_parameter_switch('formatData', 0); + $values['label'] = \get_parameter('label', 'module'); + return $values; } @@ -397,10 +436,13 @@ class ColorModuleTabs extends Widget tagente_modulo.unit AS `unit`, tagente_estado.datos AS `data`, tagente_estado.timestamp AS `timestamp`, - tagente_estado.estado AS `status` + tagente_estado.estado AS `status`, + tagente.alias FROM tagente_modulo LEFT JOIN tagente_estado ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + LEFT JOIN tagente + ON tagente_modulo.id_agente = tagente.id_agente WHERE %s', $where ); @@ -437,7 +479,23 @@ class ColorModuleTabs extends Widget $output .= '
'; } - $output .= $data['name']; + $name = ''; + switch ($this->values['label']) { + case 'agent': + $name = $data['alias']; + break; + + case 'agent_module': + $name = $data['alias'].' / '.$data['name']; + break; + + default: + case 'module': + $name = $data['name']; + break; + } + + $output .= $name; $output .= ''; $output .= ''; if ($data['data'] !== null && $data['data'] !== '') { @@ -499,7 +557,7 @@ class ColorModuleTabs extends Widget { $size = [ 'width' => (is_metaconsole() === true) ? 700 : 600, - 'height' => 560, + 'height' => 610, ]; return $size; diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css index 01096c0635..6abd72d2a0 100644 --- a/pandora_console/include/styles/dashboards.css +++ b/pandora_console/include/styles/dashboards.css @@ -613,8 +613,6 @@ form.modal-dashboard display: flex; flex-direction: row; justify-content: flex-start; - align-items: center; - align-content: space-around; flex-wrap: wrap; }