Devices view spinner #509🔃

This commit is contained in:
Jokob-sk
2023-12-16 16:33:01 +11:00
parent 57e6a330be
commit 90322c4747
4 changed files with 48 additions and 38 deletions

View File

@@ -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?<br>(maybe you prefer to archive it)',
'<?= lang('Gen_Cancel');?>', '<?= lang('Gen_Delete');?>', '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 () {

View File

@@ -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();
}
})
})
}

View File

@@ -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" : "<br/>Settings saved to the <code>pialert.conf</code> file.<br/><br/>A time-stamped backup of the previous file created. <br/><br/> Reloading...<br/>",
"settings_system_label" : "System",
"settings_core_label" : "Core",

View File

@@ -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()