diff --git a/include/layout.js b/include/layout.js
index 1e710b6a64..b11cffb7f9 100644
--- a/include/layout.js
+++ b/include/layout.js
@@ -1630,7 +1630,7 @@ function responsiveUI(event) {
}
});
- $('.filterTable').each(function () {
+ $('table.filterTable').each(function () {
tuneFilter($(this), mainWidth);
});
@@ -3501,7 +3501,7 @@ function setSelectMenus() {
$('select.colordropdown').dropcolor();
- $('select').not('.colordropdown').not('.drop-icon').not('.multi-select').not('#user_language').each(function() {
+ $('select').not('.colordropdown').not('.drop-icon').not('.multi-select').not('.graph-multiselect').not('#user_language').each(function() {
if ($(this).prop('multiple') != true) {
$(this).each(function() {
let id = $(this).attr('id');
@@ -3536,6 +3536,76 @@ function setSelectMenus() {
$(this).addClass('ui-state-default ui-corner-all');
}
});
+
+ var msWidth = 200;
+
+ $('#graph_template_id.graph-multiselect').hide().multiselect({
+ menuHeight: $(window).height()*.7,
+ menuWidth: 'auto',
+ linkInfo: faIcons,
+ buttonWidth: 'auto',
+ noneSelectedText: allSelectedText,
+ selectedText: function(numChecked, numTotal, checkedItems) {
+ myReturn = numChecked + ' ' + templatesSelected;
+
+ $.each(checkedItems, function(index, value) {
+ if (value.value == '-1') {
+ myReturn = allSelectedText;
+ return false;
+ } else if (value.value == '0') {
+ myReturn = notTemplated;
+
+ return false;
+ }
+ });
+
+ return myReturn;
+ },
+ checkAllText: allText,
+ uncheckAllText: noneText,
+ uncheckAll: function() {
+ $(this).multiselect('widget').find(':checkbox:first').each(function() {
+ $(this).prop('checked', true);
+ });
+ },
+ close: function(event, ui) {
+ applyGraphFilter();
+ },
+ open: function(event, ui) {
+ $("input[type='search']:first").focus();
+ },
+ click: function(event, ui) {
+ checked=$(this).multiselect('widget').find('input:checked').length;
+
+ if (ui.value == -1 || ui.value == 0) {
+ if (ui.checked == true) {
+ $('#graph_template_id').multiselect('uncheckAll');
+ if (ui.value == -1) {
+ $(this).multiselect('widget').find(':checkbox:first').prop('checked', true);
+ } else {
+ $(this).multiselect('widget').find(':checkbox[value="0"]').prop('checked', true);
+ }
+ }
+ } else if (checked == 0) {
+ $(this).multiselect('widget').find(':checkbox:first').each(function() {
+ $(this).click();
+ });
+ } else if ($(this).multiselect('widget').find('input:checked:first').val() == '-1') {
+ if (checked > 0) {
+ $(this).multiselect('widget').find(':checkbox:first').each(function() {
+ $(this).click();
+ $(this).prop('disable', true);
+ });
+ }
+ } else {
+ $(this).multiselect('widget').find(':checkbox[value="0"]').prop('checked', false);
+ }
+ }
+ }).multiselectfilter({
+ label: searchPlaceholder,
+ placeholder: searchEnterKeyword,
+ width: msWidth
+ });
}
function setupObjectChange() {
@@ -4038,10 +4108,6 @@ function clearGraphTimespanFilter() {
funcEnd: 'finalizeGraphFilter',
}, {
button_clear: 1,
- date1: $('#date1').val(),
- date2: $('#date2').val(),
- predefined_timespan: $('#predefined_timespan').val(),
- predefined_timeshift: $('#predefined_timeshift').val(),
__csrf_magic: csrfMagicToken
});
}
@@ -4181,6 +4247,10 @@ function redrawGraph(graph_id) {
var myColumns = $('#columns').val();
var graphRow = $('.tableRowGraph').width();
var drillDown = $('.graphDrillDown:first').outerWidth() + 10;
+ var isSource = $('#graph_source').length ? true:false;
+ var isOrder = $('#graph_order').length ? true:false;
+ var isCF = $('#cf').length ? true:false;
+ var isMeasure = $('#measure').length ? true:false;
if (mainWidth < graphRow) {
graphRow = mainWidth - drillDown;
@@ -4202,6 +4272,10 @@ function redrawGraph(graph_id) {
'&graph_height=' + graph_height +
'&graph_width=' + graph_width +
(isThumb ? '&graph_nolegend=true' : '') +
+ (isSource ? '&graph_source='+$('#graph_source').val() : '') +
+ (isOrder ? '&graph_order='+$('#graph_order').val() : '') +
+ (isCF ? '&cf='+$('#cf').val() : '') +
+ (isMeasure ? '&measure='+$('#measure').val() : '') +
'&business_hours=' + (isBusiness ? 'true' : 'false') +
loadUrl({
@@ -4358,6 +4432,10 @@ function initializeGraphs(disable_cache) {
var isBusiness = $('#business_hours').is(':checked');
var myWidth = (mainWidth - (30 * myColumns)) / myColumns;
var numGraphs = $('.graphWrapper').length;
+ var isSource = $('#graph_source').length ? true:false;
+ var isOrder = $('#graph_order').length ? true:false;
+ var isCF = $('#cf').length ? true:false;
+ var isMeasure = $('#measure').length ? true:false;
$('.graphWrapper').each(function () {
var graph_id = $(this).attr('graph_id');
@@ -4383,6 +4461,10 @@ function initializeGraphs(disable_cache) {
'&graph_end=' + graph_end +
'&graph_height=' + graph_height +
'&graph_width=' + graph_width +
+ (isSource ? '&graph_source='+$('#graph_source').val() : '') +
+ (isOrder ? '&graph_order='+$('#graph_order').val() : '') +
+ (isCF ? '&cf='+$('#cf').val() : '') +
+ (isMeasure ? '&measure='+$('#measure').val() : '') +
(disable_cache ? '&disable_cache=true' : '') +
(isThumb ? '&graph_nolegend=true' : '') +
'&business_hours=' + (isBusiness ? 'true' : 'false');
diff --git a/lib/html.php b/lib/html.php
index 0c03a591ca..89c7441591 100644
--- a/lib/html.php
+++ b/lib/html.php
@@ -2423,6 +2423,189 @@ function html_graph_tabs_right() {
print '';
}
+function html_transform_graph_template_ids($ids) {
+ $return_ids = array();
+
+ if (strpos($ids, ',') !== false) {
+ $ids = explode(',', $ids);
+ } else {
+ $ids = array($ids);
+ }
+
+ foreach($ids as $id) {
+ if (is_numeric($id)) {
+ $return_ids[] = $id;
+ } elseif (strpos($id, 'cg_') !== false) {
+ $new_id = str_replace('cg_', '', $id);
+ $return_ids[] = $new_id;
+ } else {
+ $id = str_replace('dq_', '', $id);
+
+ $return_ids[] = db_fetch_cell_prepared('SELECT graph_template_id
+ FROM snmp_query_graph
+ WHERE id = ?',
+ array($id));
+ }
+ }
+
+ return implode(',', $return_ids);
+}
+
+function html_graph_order_filter_array() {
+ $return = array();
+
+ if (read_config_option('dsstats_enable') == '') {
+ $data_sources = array('-1' => __('Enable Data Source Statistics to Sort'));
+
+ $return['graph_source'] = array(
+ 'method' => 'drop_array',
+ 'friendly_name' => __('Metric'),
+ 'filter' => FILTER_CALLBACK,
+ 'filter_options' => array('options' => 'sanitize_search_string'),
+ 'array' => $data_sources,
+ 'value' => '-1'
+ );
+ } else {
+ $mode = read_config_option('dsstats_mode'); // 0 - Peak/Average only, 1 - Kitchen Sink
+ $peak = read_config_option('dsstats_peak'); // '' - Average CF Only, 'on' - Average and Max CF's
+
+ if (isset_request_var('graph_template_id')) {
+ $graph_templates = get_nfilter_request_var('graph_template_id');
+
+ if (strpos($graph_templates, ',') !== false || $graph_templates == '' || $graph_templates <= 0) {
+ $show_sort = false;
+
+ $data_sources = array('-1' => __('Select a Single Template'));
+ } else {
+ $show_sort = true;
+
+ if (is_numeric($graph_templates)) {
+ $graph_template_id = $graph_templates;
+ } elseif (strpos($graph_templates, 'cg_') !== false) {
+ $graph_template_id = str_replace('cg_', '', $graph_templates);
+ } else {
+ $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id
+ FROM snmp_query_graph
+ WHERE id = ?',
+ array(str_replace('dq_', '', $graph_templates)));
+ }
+
+ $data_sources = array_rekey(
+ db_fetch_assoc_prepared("SELECT DISTINCT data_source_name AS graph_source
+ FROM graph_templates_item AS gti
+ INNER JOIN data_template_rrd AS dtr
+ ON dtr.id = gti.task_item_id
+ WHERE graph_template_id = ?
+ AND local_graph_id = 0
+ ORDER BY data_source_name",
+ array($graph_template_id)),
+ 'graph_source', 'graph_source'
+ );
+
+ if (get_nfilter_request_var('graph_source') == '') {
+ if (cacti_sizeof($data_sources)) {
+ set_request_var('graph_source', $data_sources[0]['graph_source']);
+ set_request_var('graph_order', 'desc');
+ }
+ }
+ }
+
+ $return['graph_source'] = array(
+ 'method' => 'drop_array',
+ 'friendly_name' => __('Metric'),
+ 'filter' => FILTER_CALLBACK,
+ 'filter_options' => array('options' => 'sanitize_search_string'),
+ 'array' => $data_sources,
+ 'value' => '-1'
+ );
+
+ if ($show_sort) {
+ $options = array(
+ 'asc' => __('Ascending'),
+ 'desc' => __('Descending')
+ );
+
+ $return['graph_order'] = array(
+ 'method' => 'drop_array',
+ 'friendly_name' => __('Order'),
+ 'filter' => FILTER_CALLBACK,
+ 'filter_options' => array('options' => 'sanitize_search_string'),
+ 'default' => 'desc',
+ 'array' => $options,
+ 'value' => 'desc'
+ );
+
+ if ($peak == 'on') {
+ $options = array(
+ '0' => __esc('Average'),
+ '1' => __esc('Maximum')
+ );
+
+ $return['cf'] = array(
+ 'method' => 'drop_array',
+ 'friendly_name' => __('CF'),
+ 'filter' => FILTER_VALIDATE_INT,
+ 'default' => 'desc',
+ 'array' => $options,
+ 'value' => get_nfilter_request_var('cf')
+ );
+ }
+
+ if ($mode == 0) {
+ $options = array(
+ 'average' => __esc('Average'),
+ 'peak' => __esc('Maximum')
+ );
+
+ $return['measure'] = array(
+ 'method' => 'drop_array',
+ 'friendly_name' => __('Measure'),
+ 'filter' => FILTER_CALLBACK,
+ 'filter_options' => array('options' => 'sanitize_search_string'),
+ 'default' => 'desc',
+ 'array' => $options,
+ 'value' => get_nfilter_request_var('measure')
+ );
+ } else {
+ $options = array(
+ 'average' => __esc('Average'),
+ 'peak' => __esc('Maximum'),
+ 'p25n' => __esc('25th Percentile'),
+ 'p50n' => __esc('50th Percentile (Median)'),
+ 'p75n' => __esc('75th Percentile'),
+ 'p90n' => __esc('90th Percentile'),
+ 'p95n' => __esc('95th Percentile'),
+ 'sum' => __esc('Total/Sum/Bandwidth')
+ );
+
+ $return['measure'] = array(
+ 'method' => 'drop_array',
+ 'friendly_name' => __('Measure'),
+ 'filter' => FILTER_CALLBACK,
+ 'filter_options' => array('options' => 'sanitize_search_string'),
+ 'default' => 'desc',
+ 'array' => $options,
+ 'value' => get_nfilter_request_var('measure')
+ );
+ }
+ }
+ } else {
+ $data_sources = array('-1' => __('Select a Single Template'));
+
+ $return['graph_source'] = array(
+ 'method' => 'drop_array',
+ 'friendly_name' => __('Metric'),
+ 'filter' => FILTER_CALLBACK,
+ 'filter_options' => array('options' => 'sanitize_search_string'),
+ 'array' => $data_sources,
+ 'value' => '-1'
+ );
+ }
+ }
+
+ return $return;
+}
+
function html_graph_order_filter() {
$output = '';
$output .= '
' . __('Metric') . ' | ';
@@ -2441,6 +2624,17 @@ function html_graph_order_filter() {
} else {
$output .= '';
+ if (is_numeric($graph_templates)) {
+ $graph_template_id = $graph_templates;
+ } elseif (strpos($graph_templates, 'cg_') !== false) {
+ $graph_template_id = str_replace('cg_', '', $graph_templates);
+ } else {
+ $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id
+ FROM snmp_query_graph
+ WHERE id = ?',
+ array(str_replace('dq_', '', $graph_templates)));
+ }
+
$data_sources = db_fetch_assoc_prepared("SELECT DISTINCT data_source_name AS graph_source
FROM graph_templates_item AS gti
INNER JOIN data_template_rrd AS dtr
@@ -2448,35 +2642,20 @@ function html_graph_order_filter() {
WHERE graph_template_id = ?
AND local_graph_id = 0
ORDER BY data_source_name",
- array($graph_templates));
+ array($graph_template_id));
- if (get_request_var('graph_source') != '') {
- $exists = db_fetch_row_prepared("SELECT DISTINCT data_source_name
- FROM graph_templates_item AS gti
- INNER JOIN data_template_rrd AS dtr
- ON dtr.id = gti.task_item_id
- WHERE graph_template_id = ?
- AND data_source_name = ?
- AND local_graph_id = 0
- LIMIT 1",
- array($graph_templates, get_request_var('graph_source')));
-
- if (cacti_sizeof($exists)) {
- $exists = true;
+ if (get_request_var('graph_source') == '') {
+ if (cacti_sizeof($data_sources)) {
+ set_request_var('graph_source', $data_sources[0]['graph_source']);
+ set_request_var('graph_order', 'desc');
}
- } else {
- $exists = false;
- }
-
- if (!$exists) {
- set_request_var('graph_order', 'desc');
}
if (cacti_sizeof($data_sources)) {
$output .= " |