mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
⚙ Settings rework 2
This commit is contained in:
@@ -5,49 +5,95 @@
|
||||
|
||||
// --------------------------------------------------
|
||||
// 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
|
||||
function renderList(
|
||||
options,
|
||||
processDataCallback,
|
||||
valuesArray,
|
||||
placeholder,
|
||||
targetField,
|
||||
transformers
|
||||
) {
|
||||
// Check if there are options provided
|
||||
if (options.length > 0) {
|
||||
// Determine if the first option's name is an SQL query
|
||||
const sqlQuery = isSQLQuery(options[0].name) ? options[0].name : "";
|
||||
|
||||
data = JSON.parse(data)
|
||||
// If there is an SQL query, fetch additional options
|
||||
if (sqlQuery) {
|
||||
// remove first item containing the SQL query
|
||||
options.shift();
|
||||
|
||||
var htmlResult = processDataCallback(data, valuesArray, targetField, nameTransformer);
|
||||
const apiUrl = `php/server/dbHelper.php?action=read&rawSql=${encodeURIComponent(sqlQuery)}`;
|
||||
|
||||
// Place the resulting HTML into the specified placeholder div
|
||||
$("#" + targetLocation).replaceWith(htmlResult);
|
||||
});
|
||||
$.get(apiUrl, function (sqlOptionsData) {
|
||||
|
||||
// Parse the returned SQL data
|
||||
const sqlOption = JSON.parse(sqlOptionsData);
|
||||
|
||||
// Concatenate options from SQL query with the supplied options
|
||||
options = options.concat(sqlOption);
|
||||
|
||||
// Process the combined options
|
||||
setTimeout(() => {
|
||||
processDataCallback(
|
||||
options,
|
||||
valuesArray,
|
||||
targetField,
|
||||
transformers,
|
||||
placeholder
|
||||
);
|
||||
}, 1);
|
||||
});
|
||||
} else {
|
||||
// No SQL query, directly process the supplied options
|
||||
setTimeout(() => {
|
||||
processDataCallback(
|
||||
options,
|
||||
valuesArray,
|
||||
targetField,
|
||||
transformers,
|
||||
placeholder
|
||||
);
|
||||
}, 1);
|
||||
}
|
||||
} else {
|
||||
// No options provided, directly process with empty options
|
||||
setTimeout(() => {
|
||||
processDataCallback(
|
||||
options,
|
||||
valuesArray,
|
||||
targetField,
|
||||
transformers,
|
||||
placeholder
|
||||
);
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
// 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()
|
||||
}
|
||||
});
|
||||
$.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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user