fix error events sound modal pandora_enterprise#12607

This commit is contained in:
daniel 2023-12-05 16:48:12 +01:00
parent 34784752b7
commit 5c6f11511c
3 changed files with 89 additions and 36 deletions

View File

@ -2565,3 +2565,13 @@ function WarningPeriodicityModal(title, message) {
hideOkButton: 1 hideOkButton: 1
}); });
} }
function checkExistParameterUrl(url, parameter) {
var regex = new RegExp(
"[?&]" + encodeURIComponent(parameter) + "(=([^&#]*)|&|#|$)"
);
var exists = regex.exec(url);
return exists;
}

View File

@ -1,4 +1,4 @@
/*global jQuery, $, forced_title_callback, confirmDialog, progressTimeBar*/ /*global jQuery, $, forced_title_callback, confirmDialog, progressTimeBar, checkExistParameterUrl*/
// Show the modal window of an event // Show the modal window of an event
function show_event_dialog(event, dialog_page) { function show_event_dialog(event, dialog_page) {
@ -975,9 +975,32 @@ function process_buffers(buffers) {
} }
} }
function openSoundEventsDialogModal(settings, dialog_parameters, reload) { function changeUrlParameterForModalSound(settings, filter_id) {
/*
Basicamente esta funcion lo que hace es: cuando activas el modal sound
y das al start para empezar a filtrar lo que hace es mirar si paras o arrancas
con el mode y settear en la url los settings necesarios para iniciar el modal,
si estaba en star añadira los parametros y si estaba parado los quitara,
con esto se consigue que si se hace f5 o reload en la pagina mantenga la busqueda.
*/
let mode = $("#hidden-mode_alert").val(); let mode = $("#hidden-mode_alert").val();
if (reload != false) { if ("history" in window) {
let href = window.location.href;
if (checkExistParameterUrl(href, "settings") === null) {
href += "&settings=1";
}
var regex_settings = /(settings=)[^&]+(&?)/gi;
var replacement_settings = "$1" + settings + "$2";
href = href.replace(regex_settings, replacement_settings);
if (checkExistParameterUrl(href, "filter_id") === null) {
href += "&filter_id=1";
}
var regex_filter_id = /(filter_id=)[^&]+(&?)/gi;
var replacement_filter_id = "$1" + filter_id + "$2";
href = href.replace(regex_filter_id, replacement_filter_id);
if (mode == 0) { if (mode == 0) {
let filter_id = $("#filter_id option:selected").val(); let filter_id = $("#filter_id option:selected").val();
let interval = $("#interval option:selected").val(); let interval = $("#interval option:selected").val();
@ -992,25 +1015,34 @@ function openSoundEventsDialogModal(settings, dialog_parameters, reload) {
}; };
parameters = JSON.stringify(parameters); parameters = JSON.stringify(parameters);
parameters = btoa(parameters); parameters = btoa(parameters);
let url =
window.location + "&settings=" + settings + "&parameters=" + parameters; if (checkExistParameterUrl(href, "parameters") === null) {
$(location).attr("href", url); href += "&parameters=1";
}
var regex_parameters = /(parameters=)[^&]+(&?)/gi;
var replacement_parameters = "$1" + parameters + "$2";
href = href.replace(regex_parameters, replacement_parameters);
} else { } else {
let url = window.location + "&settings=" + settings; if (checkExistParameterUrl(href, "parameters") !== null) {
$(location).attr("href", url); var regex = new RegExp(
"([?&])" + encodeURIComponent("parameters") + "=[^&]*(&|$)",
"i"
);
href = href.replace(regex, "$1");
}
} }
} else {
openSoundEventsDialog(settings, dialog_parameters, reload); window.history.replaceState({}, document.title, href);
} }
} }
function openSoundEventsDialog(settings, dialog_parameters, reload) { function openSoundEventsDialog(settings, dialog_parameters) {
let encode_settings = settings; let encode_settings = settings;
if (reload == undefined) { if (dialog_parameters != undefined && dialog_parameters) {
reload = true;
}
if (dialog_parameters != undefined) {
dialog_parameters = JSON.parse(atob(dialog_parameters)); dialog_parameters = JSON.parse(atob(dialog_parameters));
} else {
dialog_parameters = undefined;
} }
settings = JSON.parse(atob(settings)); settings = JSON.parse(atob(settings));
// Check modal exists and is open. // Check modal exists and is open.
@ -1063,9 +1095,8 @@ function openSoundEventsDialog(settings, dialog_parameters, reload) {
// Play Stop. // Play Stop.
$("#button-start-search").click(function() { $("#button-start-search").click(function() {
if (reload == true) { var id_filter_event = $("#hidden-id_filter_event").val();
openSoundEventsDialogModal(encode_settings, 0, reload); changeUrlParameterForModalSound(encode_settings, id_filter_event);
}
var mode = $("#hidden-mode_alert").val(); var mode = $("#hidden-mode_alert").val();
var action = false; var action = false;
if (mode == 0) { if (mode == 0) {
@ -1094,7 +1125,7 @@ function openSoundEventsDialog(settings, dialog_parameters, reload) {
action_events_sound(action, settings); action_events_sound(action, settings);
}); });
if (reload == false && dialog_parameters != undefined) { if (dialog_parameters != undefined) {
if ($("#button-start-search").hasClass("play")) { if ($("#button-start-search").hasClass("play")) {
$("#filter_id").val(dialog_parameters.filter_id); $("#filter_id").val(dialog_parameters.filter_id);
$("#interval").val(dialog_parameters.interval); $("#interval").val(dialog_parameters.interval);
@ -1150,6 +1181,25 @@ function openSoundEventsDialog(settings, dialog_parameters, reload) {
$("#minimize_arrow_event_sound").hide(); $("#minimize_arrow_event_sound").hide();
remove_audio(); remove_audio();
$(this).dialog("destroy"); $(this).dialog("destroy");
let href = window.location.href;
if (checkExistParameterUrl(href, "parameters") !== null) {
var regex_parameter = new RegExp(
"([?&])" + encodeURIComponent("parameters") + "=[^&]*(&|$)",
"i"
);
href = href.replace(regex_parameter, "$1");
}
if (checkExistParameterUrl(href, "settings") !== null) {
var regex_settings = new RegExp(
"([?&])" + encodeURIComponent("settings") + "=[^&]*(&|$)",
"i"
);
href = href.replace(regex_settings, "$1");
}
window.history.replaceState({}, document.title, href);
} }
}) })
.show(); .show();
@ -1719,20 +1769,6 @@ $(document).ajaxSend(function(event, jqXHR, ajaxOptions) {
} }
}); });
function loadModal() {
const urlSearch = window.location.search;
const urlParams = new URLSearchParams(urlSearch);
if (urlParams.has("settings")) {
let modal_parameters = "";
if (urlParams.has("parameters")) {
modal_parameters = urlParams.get("parameters");
}
let settings = urlParams.get("settings");
openSoundEventsDialogModal(settings, modal_parameters, false);
}
}
window.onload = loadModal;
function openEvents(severity) { function openEvents(severity) {
$('input[name="filter[severity]"]').val(severity); $('input[name="filter[severity]"]').val(severity);
$("#event_redirect").submit(); $("#event_redirect").submit();

View File

@ -3405,8 +3405,6 @@ $(document).ready( function() {
} }
}); });
/* Update summary */ /* Update summary */
$("#status").on("change",function(){ $("#status").on("change",function(){
$('#summary_status').html($("#status option:selected").text()); $('#summary_status').html($("#status option:selected").text());
@ -3538,7 +3536,6 @@ $(document).ready( function() {
show_events_graph(); show_events_graph();
}); });
//Autorefresh in fullscreen //Autorefresh in fullscreen
var pure = '<?php echo $pure; ?>'; var pure = '<?php echo $pure; ?>';
var pure = '<?php echo $pure; ?>'; var pure = '<?php echo $pure; ?>';
@ -3606,6 +3603,16 @@ $(document).ready( function() {
} }
const urlSearch = window.location.search;
const urlParams = new URLSearchParams(urlSearch);
if (urlParams.has("settings")) {
let modal_parameters = "";
if (urlParams.has("parameters")) {
modal_parameters = urlParams.get("parameters");
}
let settings = urlParams.get("settings");
openSoundEventsDialog(settings, modal_parameters);
}
}); });
function checked_slide_events(element) { function checked_slide_events(element) {