From b6722214de2aa5cc3124d21f69ebef1e9bdfed90 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Wed, 29 Nov 2023 15:43:38 +0100 Subject: [PATCH] #12541 changes in graph analytics --- .../include/javascript/graph_analytics.js | 183 +++++++++++++++--- .../operation/reporting/graph_analytics.php | 99 ++++++++-- 2 files changed, 240 insertions(+), 42 deletions(-) diff --git a/pandora_console/include/javascript/graph_analytics.js b/pandora_console/include/javascript/graph_analytics.js index 6c14f3f8c8..742e43201e 100644 --- a/pandora_console/include/javascript/graph_analytics.js +++ b/pandora_console/include/javascript/graph_analytics.js @@ -1,3 +1,4 @@ +/* global $ */ // Droppable options. var droppableOptions = { accept: ".draggable", @@ -422,12 +423,38 @@ $("[data-button=new]").click(function(e) { }); }); +function updateSelect(element, fields, selected) { + if (typeof fields === "object") { + $(element) + .find("select option[value!=0]") + .remove(); + $(element) + .find(".select2-container .select2-selection__rendered") + .empty(); + Object.keys(fields).forEach(function(key) { + if (key === selected) { + $(element) + .find(".select2-container .select2-selection__rendered") + .append(`${fields[key]}`); + $(element) + .find("select") + .append(``); + } else { + $(element) + .find("select") + .append(``); + } + }); + } +} + // Save graps modal. $("[data-button=save]").click(function(e) { // Filter save mode selector $("#save_filter_row1").show(); $("#save_filter_row2").show(); $("#update_filter_row1").hide(); + $("#delete_filter_row2").hide(); $("#radiobtn0002").prop("checked", false); $("#radiobtn0001").prop("checked", true); $("#text-id_name").val(""); @@ -438,20 +465,43 @@ $("[data-button=save]").click(function(e) { $("#save_filter_row2").show(); $("#submit-save_filter").show(); $("#update_filter_row1").hide(); - } else { + $("#delete_filter_row2").hide(); + } else if ($(this).val() == "update") { $("#save_filter_row1").hide(); $("#save_filter_row2").hide(); $("#update_filter_row1").show(); $("#submit-save_filter").hide(); + $("#delete_filter_row2").hide(); + } else { + $("#save_filter_row1").hide(); + $("#save_filter_row2").hide(); + $("#update_filter_row1").hide(); + $("#submit-save_filter").hide(); + $("#delete_filter_row2").show(); } }); - $("#save-filter-select").dialog({ - resizable: true, - draggable: true, - modal: false, - closeOnEscape: true, - width: 350 + $.ajax({ + method: "POST", + url: "ajax.php", + dataType: "json", + data: { + page: "operation/reporting/graph_analytics", + load_list_filters: 1 + }, + success: function(data) { + if (data) { + updateSelect("#save_filter_form", data, 0); + $("#save-filter-select").dialog({ + resizable: true, + draggable: true, + modal: false, + closeOnEscape: true, + width: 350, + title: titleModalActions + }); + } + } }); }); @@ -535,14 +585,67 @@ function save_update_filter() { }); } +// Delete filter. +function delete_filter() { + confirmDialog({ + title: titleDelete, + message: messageDelete, + onAccept: function() { + $.ajax({ + method: "POST", + url: "ajax.php", + dataType: "html", + data: { + page: "operation/reporting/graph_analytics", + delete_filter: $("#delete_filter").val() + }, + success: function(data) { + if (data == "deleted") { + confirmDialog({ + title: titleDeleteConfirm, + message: messageDeleteConfirm, + hideCancelButton: true, + onAccept: function() { + $( + "button.ui-button.ui-corner-all.ui-widget.ui-button-icon-only.ui-dialog-titlebar-close" + ).click(); + } + }); + } else { + confirmDialog({ + title: titleDeleteError, + message: messageDeleteError, + hideCancelButton: true + }); + } + } + }); + } + }); +} + // Load graps modal. $("[data-button=load]").click(function(e) { - $("#load-filter-select").dialog({ - resizable: true, - draggable: true, - modal: false, - closeOnEscape: true, - width: "auto" + $.ajax({ + method: "POST", + url: "ajax.php", + dataType: "json", + data: { + page: "operation/reporting/graph_analytics", + load_list_filters: 1 + }, + success: function(data) { + if (data) { + updateSelect("#load_filter_form", data, 0); + $("#load-filter-select").dialog({ + resizable: true, + draggable: true, + modal: false, + closeOnEscape: true, + width: "auto" + }); + } + } }); }); @@ -618,12 +721,26 @@ function loadFilter(url, filterId, homeurl, id) { // Share button. $("[data-button=share]").click(function(e) { - $("#share-select").dialog({ - resizable: true, - draggable: true, - modal: false, - closeOnEscape: true, - width: "auto" + $.ajax({ + method: "POST", + url: "ajax.php", + dataType: "json", + data: { + page: "operation/reporting/graph_analytics", + load_list_filters: 1 + }, + success: function(data) { + if (data) { + updateSelect("#share_form-0-0", data, 0); + $("#share-select").dialog({ + resizable: true, + draggable: true, + modal: false, + closeOnEscape: true, + width: "auto" + }); + } + } }); }); @@ -643,13 +760,27 @@ $("#button-share-modal").click(function(e) { // Export button. $("[data-button=export]").click(function(e) { - $("#export-select").dialog({ - resizable: true, - draggable: true, - modal: false, - closeOnEscape: true, - width: "auto", - title: titleExport + $.ajax({ + method: "POST", + url: "ajax.php", + dataType: "json", + data: { + page: "operation/reporting/graph_analytics", + load_list_filters: 1 + }, + success: function(data) { + if (data) { + updateSelect("#export_form-0-0", data, 0); + $("#export-select").dialog({ + resizable: true, + draggable: true, + modal: false, + closeOnEscape: true, + width: "auto", + title: titleExport + }); + } + } }); }); diff --git a/pandora_console/operation/reporting/graph_analytics.php b/pandora_console/operation/reporting/graph_analytics.php index 8797376070..b85a0cb84d 100644 --- a/pandora_console/operation/reporting/graph_analytics.php +++ b/pandora_console/operation/reporting/graph_analytics.php @@ -45,8 +45,10 @@ if (is_ajax()) { $save_filter = get_parameter('save_filter'); $load_filter = get_parameter('load_filter'); $update_filter = get_parameter('update_filter'); + $delete_filter = get_parameter('delete_filter'); $get_new_values = get_parameter('get_new_values'); $export_filter = get_parameter('export_filter'); + $load_list_filters = get_parameter('load_list_filters'); if (empty($search_left) === false) { $output = []; @@ -289,6 +291,11 @@ if (is_ajax()) { return; } + if (empty($delete_filter) === false) { + $result = db_process_sql_delete('tgraph_analytics_filter', ['id' => $delete_filter]); + echo ((bool) $result === true) ? 'deleted' : ''; + } + // Get new values. if (empty($get_new_values) === false) { $data = []; @@ -322,19 +329,19 @@ if (is_ajax()) { $graphs = json_decode(db_get_value('graph_modules', 'tgraph_analytics_filter', 'id', $filter)); $interval = db_get_value('tgraph_analytics_filter.interval', 'tgraph_analytics_filter', 'id', $filter); - foreach ($graphs as $graph) { - $id_graph = db_process_sql_insert( - 'tgraph', - [ - 'id_user' => $config['id_user'], - 'id_group' => $group, - 'name' => $filter_name.' ('.__('Graph').' '.($counter + 1).')', - 'description' => __('Created from Graph analytics. Filter:').' '.$filter_name.'. '.__('Graph').' '.($counter + 1), - 'period' => $interval, - 'stacked' => 2, - ] - ); + $id_graph = db_process_sql_insert( + 'tgraph', + [ + 'id_user' => $config['id_user'], + 'id_group' => $group, + 'name' => $filter_name.' ('.__('Graph').') ', + 'description' => __('Created from Graph analytics. Filter:').' '.$filter_name.'. '.__('Graph'), + 'period' => $interval, + 'stacked' => 2, + ] + ); + foreach ($graphs as $graph) { if ($id_graph > 0) { $counter++; $field_order = 1; @@ -360,6 +367,11 @@ if (is_ajax()) { echo $counter; } + if (empty($load_list_filters) === false) { + $filters = graph_analytics_filter_select(); + echo json_encode($filters); + } + return; } @@ -384,7 +396,7 @@ if (check_acl($config['id_user'], 0, 'RW') === 1 || check_acl($config['id_user'] 'content' => html_print_radio_button( 'filter_mode', 'new', - __('New filter'), + __('Create'), true, true ), @@ -398,7 +410,21 @@ if (check_acl($config['id_user'], 0, 'RW') === 1 || check_acl($config['id_user'] 'content' => html_print_radio_button( 'filter_mode', 'update', - __('Update filter'), + __('Update'), + false, + true + ), + ], + true + ); + + $data[2] = html_print_div( + [ + 'style' => 'display: flex;', + 'content' => html_print_radio_button( + 'filter_mode', + 'delete', + __('Delete'), false, true ), @@ -466,7 +492,37 @@ if (check_acl($config['id_user'], 0, 'RW') === 1 || check_acl($config['id_user'] ); $table->data[] = $data; - $table->rowclass[] = ''; + $table->rowclass[] = 'display-grid'; + + $data = []; + $table->rowid[4] = 'delete_filter_row2'; + $data[0] = __('Delete filter'); + + $select_filters_delete = graph_analytics_filter_select(); + + $data[0] .= html_print_select( + $select_filters_delete, + 'delete_filter', + '', + '', + '', + 0, + true + ); + $data[1] = html_print_submit_button( + __('Delete filter'), + 'delete_filter', + false, + [ + 'class' => 'mini ', + 'icon' => 'delete', + 'style' => 'margin-left: 155px; width: 145px;', + 'onclick' => 'delete_filter();', + ], + true + ); + + $table->data[] = $data; html_print_table($table); } else { @@ -583,7 +639,7 @@ echo ''; echo '