Skip to content

Commit

Permalink
Devices view spinner #509🔃
Browse files Browse the repository at this point in the history
  • Loading branch information
jokob-sk committed Dec 16, 2023
1 parent 57e6a33 commit 90322c4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
52 changes: 24 additions & 28 deletions front/deviceDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -1459,13 +1459,35 @@ function setDeviceData (direction='', refreshCallback='') {
window.onbeforeunload = null;
somethingChanged = false;

// refresh API
updateApi()

// Callback fuction
if (typeof refreshCallback == 'function') {
refreshCallback(direction);
}
});
}

// --------------------------------------------------------
// 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
Expand Down Expand Up @@ -1632,37 +1654,11 @@ function deleteDevice () {

// Deactivate controls
$('#panDetails :input').attr('disabled', true);
}
// -----------------------------------------------------------------------------
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');
// refresh API
updateApi()
}


// -----------------------------------------------------------------------------
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 () {
// Check MAC in url
Expand Down
28 changes: 19 additions & 9 deletions front/devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,12 @@ function main () {
initializeDatatable();

// query data
getDevicesTotals();
getDevicesTotals();

// check if dat outdated and show spinner if so
handleLoadingDialog()


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

})
})

}

Expand Down
1 change: 1 addition & 0 deletions front/php/templates/language/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions pialert/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 90322c4

Please sign in to comment.