From 90322c4747605587108ab7813cb089b1a26a6cb3 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sat, 16 Dec 2023 16:33:01 +1100 Subject: [PATCH] =?UTF-8?q?Devices=20view=20spinner=20#509=F0=9F=94=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/deviceDetails.php | 54 ++++++++++++------------- front/devices.php | 28 ++++++++----- front/php/templates/language/en_us.json | 1 + pialert/plugin.py | 3 ++ 4 files changed, 48 insertions(+), 38 deletions(-) diff --git a/front/deviceDetails.php b/front/deviceDetails.php index 8d77e17c..b0c89e0d 100755 --- a/front/deviceDetails.php +++ b/front/deviceDetails.php @@ -1459,6 +1459,9 @@ function setDeviceData (direction='', refreshCallback='') { window.onbeforeunload = null; somethingChanged = false; + // refresh API + updateApi() + // Callback fuction if (typeof refreshCallback == 'function') { refreshCallback(direction); @@ -1466,6 +1469,25 @@ function setDeviceData (direction='', refreshCallback='') { }); } +// -------------------------------------------------------- +// Calls a backend function to add a front-end event to an execution queue +function updateApi() +{ + + // value has to be in format event|param. e.g. run|ARPSCAN + action = `update_api|devices` + + $.ajax({ + method: "POST", + url: "php/server/util.php", + data: { function: "addToExecutionQueue", action: action }, + success: function(data, textStatus) { + console.log(data) + } + }) +} + + // ----------------------------------------------------------------------------- function askSkipNotifications () { // Check MAC @@ -1632,36 +1654,10 @@ function deleteDevice () { // Deactivate controls $('#panDetails :input').attr('disabled', true); + + // refresh API + updateApi() } -// ----------------------------------------------------------------------------- -function askDeleteDevice () { - // Check MAC - if (mac == '') { - return; - } - - // Ask delete device - showModalWarning ('Delete Device', 'Are you sure you want to delete this device?
(maybe you prefer to archive it)', - '', '', 'deleteDevice'); -} - - -// ----------------------------------------------------------------------------- -function deleteDevice () { - // Check MAC - if (mac == '') { - return; - } - - // Delete device - $.get('php/server/devices.php?action=deleteDevice&mac='+ mac, function(msg) { - showMessage (msg); - }); - - // Deactivate controls - $('#panDetails :input').attr('disabled', true); -} - // ----------------------------------------------------------------------------- function getSessionsPresenceEvents () { diff --git a/front/devices.php b/front/devices.php index fa910ffb..026a770a 100755 --- a/front/devices.php +++ b/front/devices.php @@ -288,7 +288,12 @@ function main () { initializeDatatable(); // query data - getDevicesTotals(); + getDevicesTotals(); + + // check if dat outdated and show spinner if so + handleLoadingDialog() + + }); }); }); @@ -390,7 +395,7 @@ function initializeDatatable (status) { } } - $.get('api/table_devices.json', function(result) { + $.get('api/table_devices.json?nocache=' + Date.now(), function(result) { // Filter the data based on deviceStatus var filteredData = filterDataByStatus(result.data, deviceStatus); @@ -641,21 +646,26 @@ function getDevicesTotals () { // ----------------------------------------------------------------------------- function handleLoadingDialog() { - $.get('api/app_state.json?nocache=' + Date.now(), function(appState) { + $.get('log/execution_queue.log?nocache=' + Date.now(), function(data) { - console.log(appState["showSpinner"]) - if(appState["showSpinner"]) + + console.log(data) + console.log("hree") + + if(data.includes("update_api|devices")) { - showSpinner("settings_old") + spinnerShown = true; + showSpinner("devices_old") setTimeout("handleLoadingDialog()", 1000); - } else + } else if ($("#loadingSpinner").is(":visible")) { - hideSpinner() + hideSpinner(); + location.reload(); } - }) + }) } diff --git a/front/php/templates/language/en_us.json b/front/php/templates/language/en_us.json index 83059c5c..bfd5855f 100755 --- a/front/php/templates/language/en_us.json +++ b/front/php/templates/language/en_us.json @@ -471,6 +471,7 @@ "settings_missing" : "Not all settings loaded, refresh the page! This is probably caused by a high load on the database or app startup sequence.", "settings_missing_block" : "You can not save your settings without specifying all setting keys. Refresh the page. This is probably caused by a high load on the database.", "settings_old" : "Importing settings and re-initializing...", + "devices_old" : "Refreshing...", "settings_saved" : "
Settings saved to the pialert.conf file.

A time-stamped backup of the previous file created.

Reloading...
", "settings_system_label" : "System", "settings_core_label" : "Core", diff --git a/pialert/plugin.py b/pialert/plugin.py index ca837cf3..dbfa41f2 100755 --- a/pialert/plugin.py +++ b/pialert/plugin.py @@ -750,6 +750,9 @@ def check_and_run_user_event(db, pluginsState): pluginsState = handle_test(param, db, pluginsState) if event == 'run': pluginsState = handle_run(param, db, pluginsState) + if event == 'update_api': + # update API endpoints + update_api(db, False, param.split(',')) # Clear the log file open(logFile, "w").close()