diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 0aea4cf37f..5488622b25 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -542,7 +542,7 @@ if ($load_filter_modal) { ); $action = 'index.php?sec=eventos&sec2=operation/events/events&pure='; - if ($settings_modal !== 0 && $parameters_modal !== 0) { + if ($settings_modal != 0 && $parameters_modal != 0) { $action .= '&settings='.$settings_modal.'¶meters='.$parameters_modal; } @@ -2644,8 +2644,8 @@ if ($get_events_fired) { // Set time. $filter['event_view_hr'] = 0; - $start = (time() - $interval); - $end = time(); + $start = ((time() - $interval) + 1); + $end = (time() + 1); $filter['date_from'] = date('Y-m-d', $start); $filter['date_to'] = date('Y-m-d', $end); diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 18494eea2b..247a0a8eda 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -2600,6 +2600,16 @@ function showPeriodicityOptions(element) { } } +function checkExistParameterUrl(url, parameter) { + var regex = new RegExp( + "[?&]" + encodeURIComponent(parameter) + "(=([^]*)|&|#|$)" + ); + + var exists = regex.exec(url); + + return exists; +} + function christmas_click(flagEasternEgg) { let counter = $("#count_click").val(); counter++; diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index c7b296ebaa..fe807833b7 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -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 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(); - 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) { let filter_id = $("#filter_id option:selected").val(); let interval = $("#interval option:selected").val(); @@ -992,25 +1015,34 @@ function openSoundEventsDialogModal(settings, dialog_parameters, reload) { }; parameters = JSON.stringify(parameters); parameters = btoa(parameters); - let url = - window.location + "&settings=" + settings + "¶meters=" + parameters; - $(location).attr("href", url); + + if (checkExistParameterUrl(href, "parameters") === null) { + href += "¶meters=1"; + } + + var regex_parameters = /(parameters=)[^&]+(&?)/gi; + var replacement_parameters = "$1" + parameters + "$2"; + href = href.replace(regex_parameters, replacement_parameters); } else { - let url = window.location + "&settings=" + settings; - $(location).attr("href", url); + if (checkExistParameterUrl(href, "parameters") !== null) { + 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; - if (reload == undefined) { - reload = true; - } - if (dialog_parameters != undefined) { + if (dialog_parameters != undefined && dialog_parameters) { dialog_parameters = JSON.parse(atob(dialog_parameters)); + } else { + dialog_parameters = undefined; } settings = JSON.parse(atob(settings)); // Check modal exists and is open. @@ -1063,9 +1095,8 @@ function openSoundEventsDialog(settings, dialog_parameters, reload) { // Play Stop. $("#button-start-search").click(function() { - if (reload == true) { - openSoundEventsDialogModal(encode_settings, 0, reload); - } + var id_filter_event = $("#hidden-id_filter_event").val(); + changeUrlParameterForModalSound(encode_settings, id_filter_event); var mode = $("#hidden-mode_alert").val(); var action = false; if (mode == 0) { @@ -1094,7 +1125,7 @@ function openSoundEventsDialog(settings, dialog_parameters, reload) { action_events_sound(action, settings); }); - if (reload == false && dialog_parameters != undefined) { + if (dialog_parameters != undefined) { if ($("#button-start-search").hasClass("play")) { $("#filter_id").val(dialog_parameters.filter_id); $("#interval").val(dialog_parameters.interval); @@ -1150,6 +1181,25 @@ function openSoundEventsDialog(settings, dialog_parameters, reload) { $("#minimize_arrow_event_sound").hide(); remove_audio(); $(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(); @@ -1723,43 +1773,12 @@ $(document).ajaxSend(function(event, jqXHR, ajaxOptions) { "display", "none" ); - - // Handle the 'change' event for #modal-sound, simply to compact the size of the img "No alerts discovered" - // An image should always have a size assigned!!! - $("#modal-sound").on("change", function() { - // Find the image within the specific div - var image = $(this).find( - 'img.invert_filter.forced_title[data-title="No alerts discovered"][alt="No alerts discovered"]' - ); - - // Set the desired width and height - var width = 48; - var height = 48; - - // Resize the image - image.width(width); - image.height(height); - }); } } catch (e) { console.log(e); } }); -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) { $('input[name="filter[severity]"]').val(severity); $("#event_redirect").submit(); diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index bc4d6dc78d..e0263ea844 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -3431,8 +3431,6 @@ $(document).ready( function() { } }); - - /* Update summary */ $("#status").on("change",function(){ $('#summary_status').html($("#status option:selected").text()); @@ -3564,7 +3562,6 @@ $(document).ready( function() { show_events_graph(); }); - //Autorefresh in fullscreen var pure = ''; var pure = ''; @@ -3632,6 +3629,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) { diff --git a/pandora_console/operation/events/sound_events.php b/pandora_console/operation/events/sound_events.php index 0bec0e65d8..4ff12e02f4 100644 --- a/pandora_console/operation/events/sound_events.php +++ b/pandora_console/operation/events/sound_events.php @@ -77,6 +77,7 @@ echo ''; echo ''; @@ -126,7 +127,7 @@ $output = '