#12541 changes in graph analytics
This commit is contained in:
parent
e7ad23c477
commit
b6722214de
|
@ -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(`<option value="${key}" selected>${fields[key]}</option>`);
|
||||
} else {
|
||||
$(element)
|
||||
.find("select")
|
||||
.append(`<option value="${key}">${fields[key]}</option>`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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 '</div>';
|
|||
echo '<div id="export-select" class="load-filter-modal invisible">';
|
||||
|
||||
$table = new StdClass;
|
||||
$table->id = 'share_form';
|
||||
$table->id = 'export_form';
|
||||
$table->width = '100%';
|
||||
$table->cellspacing = 4;
|
||||
$table->cellpadding = 4;
|
||||
|
@ -920,6 +976,15 @@ const titleError = "<?php echo __('Error'); ?>";
|
|||
const titleUpdate = "<?php echo __('Override filter?'); ?>";
|
||||
const messageUpdate = "<?php echo __('Do you want to overwrite the filter?'); ?>";
|
||||
|
||||
const titleDelete = "<?php echo __('Delete filter?'); ?>";
|
||||
const messageDelete = "<?php echo __('Do you want to delete the filter?'); ?>";
|
||||
|
||||
const titleDeleteConfirm = "<?php echo __('Deleted successfully'); ?>";
|
||||
const messageDeleteConfirm = "<?php echo __('The filter has been deleted successfully'); ?>";
|
||||
|
||||
const titleDeleteError = "<?php echo __('Error'); ?>";
|
||||
const messageDeleteError = "<?php echo __('It is not possible delete the filter'); ?>";
|
||||
|
||||
const titleUpdateConfirm = "<?php echo __('Updated successfully'); ?>";
|
||||
const messageUpdateConfirm = "<?php echo __('The filter has been updated successfully'); ?>";
|
||||
|
||||
|
@ -943,4 +1008,6 @@ const messageExportError = "<?php echo __('Filter cannot be None'); ?>";
|
|||
const titleRemoveConfirm = "<?php echo __('Delete graph'); ?>";
|
||||
const messageRemoveConfirm = "<?php echo __('Do you want to delete the graph? Remember to save the changes.'); ?>";
|
||||
|
||||
const titleModalActions = "<?php echo __('Filter actions'); ?>"
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue