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.
This commit is contained in:
Alejandro Gallardo Escobar 2019-05-28 18:34:07 +02:00
parent 5ea79cdfb8
commit f5d5cbf5b8
5 changed files with 155 additions and 23 deletions

View File

@ -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") {

View File

@ -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;

View File

@ -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':

View File

@ -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);
}

View File

@ -1128,30 +1128,58 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background)
true
).'</td>';
$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'] = '<td align="left">'.__('Cache expiration').'</td>
<td align="left">'.html_print_select($interval, 'cache_expiration', $jeje, '', '', '0', 10, false, false, false).'</td>';
$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'] = '<td align="left">';
$form_items_advance['cache_expiration_row']['html'] .= __('Cache expiration');
$form_items_advance['cache_expiration_row']['html'] .= '</td>';
$form_items_advance['cache_expiration_row']['html'] .= '<td align="left">';
$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'] .= '</td>';
}
// 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) {