mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
53 lines
1.8 KiB
JavaScript
Executable File
53 lines
1.8 KiB
JavaScript
Executable File
// -----------------------------------------------------------------------------
|
|
// General utilities to interact with the database
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
// --------------------------------------------------
|
|
// Read data and place intotarget location, callback processies the results
|
|
function readData(sqlQuery, processDataCallback, valuesArray, targetLocation, targetField, nameTransformer) {
|
|
var apiUrl = `php/server/dbHelper.php?action=read&rawSql=${encodeURIComponent(sqlQuery)}`;
|
|
$.get(apiUrl, function(data) {
|
|
// Process the JSON data using the provided callback function
|
|
|
|
data = JSON.parse(data)
|
|
|
|
var htmlResult = processDataCallback(data, valuesArray, targetField, nameTransformer);
|
|
|
|
// Place the resulting HTML into the specified placeholder div
|
|
$("#" + targetLocation).replaceWith(htmlResult);
|
|
});
|
|
}
|
|
|
|
// --------------------------------------------------
|
|
// Check if database is locked
|
|
function checkDbLock() {
|
|
$.ajax({
|
|
url: 'log/db_is_locked.log', // Replace with the actual path to your PHP file
|
|
type: 'GET',
|
|
|
|
success: function(response) {
|
|
// console.log(response);
|
|
if (response == 0) {
|
|
// console.log('Database is not locked');
|
|
$(".header-status-locked-db").hide()
|
|
|
|
} else {
|
|
console.log('🟥 Database is locked:');
|
|
console.log(response);
|
|
$(".header-status-locked-db").show()
|
|
}
|
|
},
|
|
error: function() {
|
|
console.log('🟥 Error checking database lock status');
|
|
$(".header-status-locked-db").show()
|
|
}
|
|
});
|
|
}
|
|
|
|
setInterval(checkDbLock(), 1000);
|
|
|
|
|
|
|
|
|