From 2f2556ef79e3054536a8b6e43327ceaf4708f62d Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 4 Nov 2020 16:41:25 +0100 Subject: [PATCH] Ent 6680 ventana de perdida de conexion incorrecta --- pandora_console/general/login_page.php | 7 + .../include/javascript/connection_check.js | 170 ++++++++++++++++++ pandora_console/include/javascript/pandora.js | 117 ------------ .../include/javascript/pandora_ui.js | 58 ------ pandora_console/index.php | 2 +- .../operation/agentes/stat_win.php | 1 + .../operation/events/sound_events.php | 7 + .../operation/gis_maps/public_console.php | 2 + .../visual_console/legacy_public_view.php | 5 +- .../operation/visual_console/public_view.php | 9 +- 10 files changed, 191 insertions(+), 187 deletions(-) create mode 100644 pandora_console/include/javascript/connection_check.js diff --git a/pandora_console/general/login_page.php b/pandora_console/general/login_page.php index c4cd8482bc..9f50b10cb5 100755 --- a/pandora_console/general/login_page.php +++ b/pandora_console/general/login_page.php @@ -114,6 +114,13 @@ foreach ($custom_fields as $field) { } } +// Connection lost alert. +ui_require_css_file('register', 'include/styles/', true); +ui_require_javascript_file('connection_check'); +$conn_title = __('Connection with server has been lost'); +$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.'); +ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png'); + // Get the custom icons. $docs_logo = ui_get_docs_logo(); $support_logo = ui_get_support_logo(); diff --git a/pandora_console/include/javascript/connection_check.js b/pandora_console/include/javascript/connection_check.js new file mode 100644 index 0000000000..5ea72d2184 --- /dev/null +++ b/pandora_console/include/javascript/connection_check.js @@ -0,0 +1,170 @@ +/** + * ------------------------------------- + * Connection Check + * -------------------------------------- + */ + +checkConnection(1); + +/** + * Performs connection tests every minutes and add connection listeners + * @param {integer} time in minutes + */ + +function checkConnection(minutes) { + var cicle = minutes * 60 * 1000; + var checkConnection = setInterval(handleConnection, cicle); + + // Connection listeters. + window.addEventListener("online", handleConnection); + window.addEventListener("offline", handleConnection); +} + +/** + * Handle connection status test. + * + * Test conectivity with server and shows modal message. + */ +function handleConnection() { + var connected; + var msg = "online"; + + if (navigator.onLine) { + isReachable(getServerUrl()) + .then(function(online) { + if (online) { + // handle online status + connected = true; + showConnectionMessage(connected, msg); + } else { + connected = false; + msg = "No connectivity with server"; + showConnectionMessage(connected, msg); + } + }) + .catch(function(err) { + connected = false; + msg = err; + showConnectionMessage(connected, msg); + }); + } else { + // handle offline status + connected = false; + msg = "Connection offline"; + showConnectionMessage(connected, msg); + } +} + +/** + * Test server reachibilty and get response. + * + * @param {String} url + * + * Return {promise} + */ +function isReachable(url) { + /** + * Note: fetch() still "succeeds" for 404s on subdirectories, + * which is ok when only testing for domain reachability. + * + * Example: + * https://google.com/noexist does not throw + * https://noexist.com/noexist does throw + */ + return fetch(url, { method: "HEAD", mode: "no-cors" }) + .then(function(resp) { + return resp && (resp.ok || resp.type === "opaque"); + }) + .catch(function(error) { + console.warn("[conn test failure]:", error); + }); +} + +/** + * Gets server origin url + */ +function getServerUrl() { + var server_url; + + server_url = window.location.origin; + + return server_url; +} + +/** + * Shows or hide connection infoMessage. + * + * @param {bool} conn + * @param {string} msg + */ +function showConnectionMessage(conn = true, msg = "") { + var data = {}; + if (conn) { + $("div#message_dialog_connection") + .closest(".ui-dialog-content") + .dialog("close"); + } else { + data.title = "Connection with server has been lost"; + data.text = "Connection status: " + msg; + + infoMessage(data, "message_dialog_connection"); + } +} + +function infoMessage(data, idMsg) { + var title = data.title; + var err_messge = data.text; + + if (idMsg == null) { + idMsg = uniqId(); + } + + if ($("#" + idMsg).length === 0) { + $("body").append('
'); + $("#" + idMsg).empty(); + } + + $("#err_msg").empty(); + $("#err_msg").html("\n\n" + err_messge); + + $("#" + idMsg) + .dialog({ + height: 250, + width: 528, + opacity: 1, + modal: true, + position: { + my: "center", + at: "center", + of: window, + collision: "fit" + }, + title: data.title, + buttons: [ + { + class: + "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", + text: "Retry", + click: function(e) { + handleConnection(); + } + }, + { + class: + "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-cancel", + text: "Close", + click: function() { + $(this).dialog("close"); + } + } + ], + + open: function(event, ui) { + $(".ui-widget-overlay").addClass("error-modal-opened"); + }, + close: function(event, ui) { + $(".ui-widget-overlay").removeClass("error-modal-opened"); + } + }) + .show(); +} diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index e7f007a425..04a8f5336e 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -1930,120 +1930,3 @@ function ajaxRequest(id, settings) { } }); } - -/** - * ------------------------------------- - * Connection Check - * -------------------------------------- - */ - -checkConnection(1); - -/** - * Performs connection tests every minutes and add connection listeners - * @param {integer} time in minutes - */ - -function checkConnection(minutes) { - var cicle = minutes * 60 * 1000; - var checkConnection = setInterval(handleConnection, cicle); - - // Connection listeters. - window.addEventListener("online", handleConnection); - window.addEventListener("offline", handleConnection); -} - -/** - * Handle connection status test. - * - * Test conectivity with server and shows modal message. - */ -function handleConnection() { - var connected; - var msg = "online"; - - if (navigator.onLine) { - isReachable(getServerUrl()) - .then(function(online) { - if (online) { - // handle online status - connected = true; - showConnectionMessage(connected, msg); - } else { - connected = false; - msg = "No connectivity with server"; - showConnectionMessage(connected, msg); - } - }) - .catch(function(err) { - connected = false; - msg = err; - showConnectionMessage(connected, msg); - }); - } else { - // handle offline status - connected = false; - msg = "Connection offline"; - showConnectionMessage(connected, msg); - } -} - -/** - * Test server reachibilty and get response. - * - * @param {String} url - * - * Return {promise} - */ -function isReachable(url) { - /** - * Note: fetch() still "succeeds" for 404s on subdirectories, - * which is ok when only testing for domain reachability. - * - * Example: - * https://google.com/noexist does not throw - * https://noexist.com/noexist does throw - */ - return fetch(url, { method: "HEAD", mode: "no-cors" }) - .then(function(resp) { - return resp && (resp.ok || resp.type === "opaque"); - }) - .catch(function(error) { - console.warn("[conn test failure]:", error); - }); -} - -/** - * Gets server origin url - */ -function getServerUrl() { - var server_url; - - try { - server_url = get_php_value("homeurl"); - } catch (SyntaxError) { - console.warn("Pandora homeurl cannot be found."); - server_url = $("#hidden-homeurl").val(); - } - return server_url; -} - -/** - * Shows or hide connection infoMessage. - * - * @param {bool} conn - * @param {string} msg - */ -function showConnectionMessage(conn = true, msg = "") { - var data = {}; - if (conn) { - $("div#message_dialog_connection") - .closest(".ui-dialog-content") - .dialog("close"); - } else { - data.title = "Connection with server has been lost"; - data.text = "Connection status: " + msg; - - infoMessage(data, "message_dialog_connection"); - } -} diff --git a/pandora_console/include/javascript/pandora_ui.js b/pandora_console/include/javascript/pandora_ui.js index 2445473591..15b7f83217 100644 --- a/pandora_console/include/javascript/pandora_ui.js +++ b/pandora_console/include/javascript/pandora_ui.js @@ -494,61 +494,3 @@ function generalShowMsg(data, idMsg) { ] }); } - -function infoMessage(data, idMsg) { - var title = data.title; - var err_messge = data.text; - - if (idMsg == null) { - idMsg = uniqId(); - } - - if ($("#" + idMsg).length === 0) { - $("body").append('
'); - $("#" + idMsg).empty(); - } - - $("#err_msg").empty(); - $("#err_msg").html("\n\n" + err_messge); - - $("#" + idMsg) - .dialog({ - height: 250, - width: 528, - opacity: 1, - modal: true, - position: { - my: "center", - at: "center", - of: window, - collision: "fit" - }, - title: data.title, - buttons: [ - { - class: - "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", - text: "Retry", - click: function(e) { - handleConnection(); - } - }, - { - class: - "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-cancel", - text: "Close", - click: function() { - $(this).dialog("close"); - } - } - ], - - open: function(event, ui) { - $(".ui-widget-overlay").addClass("error-modal-opened"); - }, - close: function(event, ui) { - $(".ui-widget-overlay").removeClass("error-modal-opened"); - } - }) - .show(); -} diff --git a/pandora_console/index.php b/pandora_console/index.php index 599e013c12..f7f3d6b207 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1255,8 +1255,8 @@ echo ''; echo '
'; echo '
'; - // Connection lost alert. +ui_require_javascript_file('connection_check'); $conn_title = __('Connection with server has been lost'); $conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.'); ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png'); diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index d5e22eb06b..a75e30e269 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -86,6 +86,7 @@ ui_require_css_file('register', 'include/styles/', true); // Connection lost alert. $conn_title = __('Connection with server has been lost'); $conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.'); +ui_require_javascript_file('connection_check'); ui_print_message_dialog( $conn_title, $conn_text, diff --git a/pandora_console/operation/events/sound_events.php b/pandora_console/operation/events/sound_events.php index 5037e63b22..7434c18eaf 100644 --- a/pandora_console/operation/events/sound_events.php +++ b/pandora_console/operation/events/sound_events.php @@ -61,6 +61,13 @@ echo ''; echo ""; echo "

".__('Sound console').'

'; +// Connection lost alert. +ui_require_css_file('register', 'include/styles/', true); +$conn_title = __('Connection with server has been lost'); +$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.'); +ui_require_javascript_file('connection_check'); +ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png'); + $table = new StdClass; $table->width = '100%'; $table->styleTable = 'padding-left:16px; padding-right:16px; padding-top:16px;'; diff --git a/pandora_console/operation/gis_maps/public_console.php b/pandora_console/operation/gis_maps/public_console.php index ba5b99633c..a756d04c0c 100755 --- a/pandora_console/operation/gis_maps/public_console.php +++ b/pandora_console/operation/gis_maps/public_console.php @@ -273,8 +273,10 @@ if ($layers != false) { gis_activate_ajax_refresh($layers, $timestampLastOperation, 1, $idMap); // Connection lost alert. + ui_require_css_file('register', 'include/styles/', true); $conn_title = __('Connection with server has been lost'); $conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.'); + ui_require_javascript_file('connection_check'); ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png'); } diff --git a/pandora_console/operation/visual_console/legacy_public_view.php b/pandora_console/operation/visual_console/legacy_public_view.php index 4df0a6db28..609447800e 100644 --- a/pandora_console/operation/visual_console/legacy_public_view.php +++ b/pandora_console/operation/visual_console/legacy_public_view.php @@ -48,6 +48,7 @@ html_print_input_hidden('homeurl', $config['homeurl']); $url_css_modal = ui_get_full_url('include/styles/register.css', false, false, false); echo ''; // Connection lost alert. +ui_require_javascript_file('connection_check', 'include/javascript/', true); $conn_title = __('Connection with server has been lost'); $conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.'); ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png'); @@ -157,10 +158,6 @@ echo ''; echo ''; -// Connection lost alert. -$conn_title = __('Connection with server has been lost'); -$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.'); -ui_print_message_alert($conn_title, $conn_text, 'connection', '/images/error_1.png'); ui_require_jquery_file('countdown', 'include/javascript/', true); ui_require_javascript_file('wz_jsgraphics', 'include/javascript/', true); diff --git a/pandora_console/operation/visual_console/public_view.php b/pandora_console/operation/visual_console/public_view.php index 301ec3ca9c..6cc9f817a1 100644 --- a/pandora_console/operation/visual_console/public_view.php +++ b/pandora_console/operation/visual_console/public_view.php @@ -29,11 +29,10 @@ if (file_exists(ENTERPRISE_DIR.'/include/functions_login.php')) { require_once $config['homedir'].'/vendor/autoload.php'; ui_require_css_file('visual_maps'); -ui_require_css_file('register'); - -html_print_input_hidden('homeurl', $config['homeurl']); +ui_require_css_file('register', 'include/styles/', true); // Connection lost alert. +ui_require_javascript_file('connection_check', 'include/javascript/', true); $conn_title = __('Connection with server has been lost'); $conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.'); ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png'); @@ -140,10 +139,6 @@ echo ''; echo ''; -// Connection lost alert. -$conn_title = __('Connection with server has been lost'); -$conn_text = __('Connection to the server has been lost. Please check your internet connection or contact with administrator.'); -ui_print_message_dialog($conn_title, $conn_text, 'connection', '/images/error_1.png'); // Check groups can access user. $aclUserGroups = [];