From f5d5cbf5b88a025b6d78ed3fe5d79dbf6c66af80 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Tue, 28 May 2019 18:34:07 +0200 Subject: [PATCH] VC item cache improvements. -Added a default value to the configuration. -Changed the control to edit the cache expiration. - Added the cache to more items. --- .../visual_console_builder.editor.js | 65 +++++++++++++++++- .../godmode/setup/setup_visuals.php | 35 ++++++++++ .../ajax/visual_console_builder.ajax.php | 2 +- pandora_console/include/functions_config.php | 8 +++ .../include/functions_visual_map_editor.php | 68 +++++++++++++------ 5 files changed, 155 insertions(+), 23 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index 1432b95f5c..cb72ce58ce 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -1,3 +1,5 @@ +/* globals $ */ + // Pandora FMS - http://pandorafms.com // ================================================== // Copyright (c) 2005-2009 Artica Soluciones Tecnologicas @@ -31,6 +33,8 @@ var SIZE_GRID = 16; //Const the size (for width and height) of grid. var img_handler_start; var img_handler_end; +var default_cache_expiration = null; + function toggle_advance_options_palette(close) { if ($("#advance_options").css("display") == "none") { $("#advance_options").css("display", ""); @@ -1183,7 +1187,10 @@ function readFields() { values["timezone"] = $("select[name=timezone]").val(); values["clock_animation"] = $("select[name=clock_animation]").val(); values["show_last_value"] = $("select[name=last_value]").val(); - values["cache_expiration"] = $("select[name=cache_expiration]").val(); + values["cache_expiration"] = + typeof $("#hidden-cache_expiration").val() !== "undefined" + ? $("#hidden-cache_expiration").val() + : $("#cache_expiration").val(); // Color Cloud values if (selectedItem == "color_cloud" || creationItem == "color_cloud") { @@ -2220,7 +2227,23 @@ function loadFieldsFromDB(item) { } if (key == "cache_expiration") { - $("select[name=cache_expiration]").val(val); + var intoCacheExpSelect = false; + var cacheExpId = $("#hidden-cache_expiration").attr("class"); + $("#" + cacheExpId + "_select option").each(function() { + if ($(this).val() == val) { + $(this).prop("selected", true); + $(this).trigger("change"); + intoCacheExpSelect = true; + } + }); + if (intoCacheExpSelect == false) { + $("#" + cacheExpId + "_select").val(0); + $("#" + cacheExpId + "_units").val(1); + $("#hidden-cache_expiration").val(val); + $("#text-" + cacheExpId + "_text").val(val); + $("#" + cacheExpId + "_default").hide(); + $("#" + cacheExpId + "_manual").show(); + } } if (key == "value_show") { @@ -2675,6 +2698,44 @@ function cleanFields(item) { $("table.color-range-creation input[type=color]").val("#FFFFFF"); $("table.color-range:not(table.color-range-creation)").remove(); + // Clean the cache expiration selection. + if (default_cache_expiration === null) { + var cacheExpVal = $("#hidden-cache_expiration").val(); + if (!Number.isNaN(Number.parseInt(cacheExpVal))) { + cacheExpVal = Number.parseInt(cacheExpVal); + } else { + cacheExpVal = 0; + } + + default_cache_expiration = cacheExpVal; + } + var cacheExpId = $("#hidden-cache_expiration").attr("class"); + $("#hidden-cache_expiration").val(default_cache_expiration); + + var intoCacheExpSelect = false; + $("#" + cacheExpId + "_select option").each(function() { + if ($(this).val() == default_cache_expiration) { + $(this).prop("selected", true); + $(this).trigger("change"); + intoCacheExpSelect = true; + } + }); + if (!intoCacheExpSelect) { + // Show input. + $("#" + cacheExpId + "_select").val(0); + $("#" + cacheExpId + "_units").val(1); + $("#text-" + cacheExpId + "_text").val(default_cache_expiration); + $("#" + cacheExpId + "_default").hide(); + $("#" + cacheExpId + "_manual").show(); + } else { + // Show select. + $("#" + cacheExpId + "_select").val(default_cache_expiration); + $("#" + cacheExpId + "_units").val(0); + $("#text-" + cacheExpId + "_text").val(""); + $("#" + cacheExpId + "_default").show(); + $("#" + cacheExpId + "_manual").hide(); + } + $("#preview").empty(); if (item == "simple_value") { diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index cff2c81c34..bcaff54d95 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -918,6 +918,32 @@ $row++; ); $row++; + $intervals = [ + 10 => '10 '.__('seconds'), + 30 => '30 '.__('seconds'), + 60 => '1 '.__('minutes'), + 300 => '5 '.__('minutes'), + 900 => '15 '.__('minutes'), + 1800 => '30 '.__('minutes'), + 3600 => '1 '.__('hour'), + ]; + $table_vc->data[$row][0] = __('Default cache expiration'); + $table_vc->data[$row][1] = html_print_extended_select_for_time( + 'vc_default_cache_expiration', + $config['vc_default_cache_expiration'], + '', + __('No cache'), + 0, + false, + true, + false, + false, + '', + false, + $intervals + ); + $row++; + $table_vc->data[$row][0] = __('Default interval for refresh on Visual Console').ui_print_help_tip(__('This interval will affect to Visual Console pages'), true); $table_vc->data[$row][1] = html_print_select($values, 'vc_refr', (int) $config['vc_refr'], '', 'N/A', 0, true, false, false); $row++; @@ -1394,6 +1420,15 @@ tinyMCE.init({ }); $(document).ready (function () { + + // Show the cache expiration conf or not. + $("input[name=legacy_vc]").change(function (e) { + if ($(this).prop("checked") === true) { + $("select#vc_default_cache_expiration_select").closest("tr").hide(); + } else { + $("select#vc_default_cache_expiration_select").closest("tr").show(); + } + }).change(); var comfort = 0; diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php index 8c83322f1f..b941c022f8 100755 --- a/pandora_console/include/ajax/visual_console_builder.ajax.php +++ b/pandora_console/include/ajax/visual_console_builder.ajax.php @@ -176,7 +176,7 @@ $default_color = get_parameter('default_color', '#FFFFFF'); $color_range_from_values = get_parameter('color_range_from_values', []); $color_range_to_values = get_parameter('color_range_to_values', []); $color_range_colors = get_parameter('color_range_colors', []); -$cache_expiration = get_parameter('cache_expiration', 0); +$cache_expiration = (int) get_parameter('cache_expiration'); switch ($action) { case 'get_font': diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index ffc071acd6..91462fc2ad 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -984,6 +984,10 @@ function config_update_config() $error_update[] = __('Use the legacy Visual Console'); } + if (!config_update_value('vc_default_cache_expiration', (int) get_parameter('vc_default_cache_expiration'))) { + $error_update[] = __("Default expiration of the Visual Console item's cache"); + } + if (!config_update_value('vc_refr', (int) get_parameter('vc_refr'))) { $error_update[] = __('Default interval for refresh on Visual Console'); } @@ -2423,6 +2427,10 @@ function config_process_config() config_update_value('legacy_vc', 1); } + if (!isset($config['vc_default_cache_expiration'])) { + config_update_value('vc_default_cache_expiration', 60); + } + if (!isset($config['vc_refr'])) { config_update_value('vc_refr', 300); } diff --git a/pandora_console/include/functions_visual_map_editor.php b/pandora_console/include/functions_visual_map_editor.php index e4abe410eb..b51f9fce76 100755 --- a/pandora_console/include/functions_visual_map_editor.php +++ b/pandora_console/include/functions_visual_map_editor.php @@ -1128,30 +1128,58 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) true ).''; - $interval = []; - $interval[0] = __('No cache'); - $interval[10] = '10 '.__('seconds'); - $interval[30] = '30 '.__('seconds'); - $interval[60] = '1 '.__('minutes'); - $interval[300] = '5 '.__('minutes'); - $interval[900] = '15 '.__('minutes'); - $interval[1800] = '30 '.__('minutes'); - $interval[3600] = '1 '.__('hour'); + if (!$config['legacy_vc']) { + $intervals = [ + 10 => '10 '.__('seconds'), + 30 => '30 '.__('seconds'), + 60 => '1 '.__('minutes'), + 300 => '5 '.__('minutes'), + 900 => '15 '.__('minutes'), + 1800 => '30 '.__('minutes'), + 3600 => '1 '.__('hour'), + ]; - $form_items_advance['cache_expiration_row'] = []; - $form_items_advance['cache_expiration_row']['items'] = [ - 'group_item', - 'module_graph', - 'auto_sla_graph', - 'bars_graph', - 'donut_graph', - ]; - $form_items_advance['cache_expiration_row']['html'] = ''.__('Cache expiration').' - '.html_print_select($interval, 'cache_expiration', $jeje, '', '', '0', 10, false, false, false).''; + $form_items_advance['cache_expiration_row'] = []; + $form_items_advance['cache_expiration_row']['items'] = [ + 'static_graph', + 'percentile_bar', + 'percentile_item', + 'module_graph', + 'simple_value', + 'label', + 'datos', + 'auto_sla_graph', + 'bars_graph', + 'donut_graph', + 'color_cloud', + 'service', + ]; + $form_items_advance['cache_expiration_row']['html'] = ''; + $form_items_advance['cache_expiration_row']['html'] .= __('Cache expiration'); + $form_items_advance['cache_expiration_row']['html'] .= ''; + $form_items_advance['cache_expiration_row']['html'] .= ''; + $form_items_advance['cache_expiration_row']['html'] .= html_print_extended_select_for_time( + 'cache_expiration', + $config['vc_default_cache_expiration'], + '', + __('No cache'), + 0, + false, + true, + false, + true, + '', + false, + $intervals + ); + $form_items_advance['cache_expiration_row']['html'] .= ''; + } // Insert and modify before the buttons to create or update. if (enterprise_installed()) { - enterprise_visual_map_editor_modify_form_items_advance_palette($form_items_advance); + enterprise_visual_map_editor_modify_form_items_advance_palette( + $form_items_advance + ); } foreach ($form_items_advance as $item => $item_options) {