mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
This commit is contained in:
@@ -3,14 +3,14 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Read data and place intotarget location, callback processies the results
|
||||
function readData(sqlQuery, processDataCallback, valuesArray, targetLocation, targetField) {
|
||||
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);
|
||||
var htmlResult = processDataCallback(data, valuesArray, targetField, nameTransformer);
|
||||
|
||||
// Place the resulting HTML into the specified placeholder div
|
||||
$("#" + targetLocation).replaceWith(htmlResult);
|
||||
|
||||
@@ -628,10 +628,19 @@ function stopTimerRefreshData () {
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function newTimerRefreshData (refeshFunction) {
|
||||
function newTimerRefreshData (refeshFunction, timeToRefresh) {
|
||||
|
||||
if(timeToRefresh && (timeToRefresh != 0 || timeToRefresh != ""))
|
||||
{
|
||||
time = parseInt(timeToRefresh)
|
||||
} else
|
||||
{
|
||||
time = 60000
|
||||
}
|
||||
|
||||
timerRefreshData = setTimeout (function() {
|
||||
refeshFunction();
|
||||
}, 60000);
|
||||
}, time);
|
||||
}
|
||||
|
||||
|
||||
@@ -1247,6 +1256,16 @@ const onAllCallsComplete = () => {
|
||||
|
||||
// Call the function to execute the code
|
||||
executeOnce();
|
||||
|
||||
// Set timer for page refresh if configured
|
||||
setTimeout(() => {
|
||||
const refreshTime = getSetting("UI_REFRESH");
|
||||
if (refreshTime && refreshTime !== "0" && refreshTime !== "") {
|
||||
newTimerRefreshData(clearCache, refreshTime);
|
||||
}
|
||||
}, 10000);
|
||||
|
||||
|
||||
console.log("init pialert_common.js");
|
||||
|
||||
|
||||
|
||||
@@ -117,7 +117,8 @@ function initSettingDropdown(settingKey, // Identifier for the setting
|
||||
valuesArray, // Array of values to be pre-selected in the dropdown
|
||||
targetLocation, // ID of the HTML element where dropdown should be rendered (will be replaced)
|
||||
callbackToGenerateEntries, // Callback function to generate entries based on options
|
||||
targetField) // Target field or element where selected value should be applied or updated
|
||||
targetField, // Target field or element where selected value should be applied or updated
|
||||
nameTransformer) // callback to transform the name (e.g. base64)
|
||||
{
|
||||
|
||||
var optionsHtml = ""
|
||||
@@ -127,7 +128,7 @@ function initSettingDropdown(settingKey, // Identifier for the setting
|
||||
// check if the result is a SQL query
|
||||
if(isSQLQuery(optionsArray[0]))
|
||||
{
|
||||
readData(optionsArray[0], callbackToGenerateEntries, valuesArray, targetLocation, targetField);
|
||||
readData(optionsArray[0], callbackToGenerateEntries, valuesArray, targetLocation, targetField, nameTransformer);
|
||||
|
||||
} else // this should be already an array, e.g. from a setting or pre-defined
|
||||
{
|
||||
@@ -212,8 +213,8 @@ function generateList(data, valuesArray) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Processor to generate a list
|
||||
function genDevDetailsList(data, valuesArray, targetField) {
|
||||
// Processor to generate a list in teh deviceDetails page
|
||||
function genDevDetailsList(data, valuesArray, targetField, nameTransformer) {
|
||||
|
||||
var listHtml = "";
|
||||
|
||||
@@ -222,12 +223,17 @@ function genDevDetailsList(data, valuesArray, targetField) {
|
||||
|
||||
let selected = valuesArray.includes(item.id) ? 'selected' : '';
|
||||
|
||||
|
||||
console.log(item);
|
||||
|
||||
// listHtml += `<li ${selected}>${item.name}</li>`;
|
||||
labelName = item.name
|
||||
|
||||
if(nameTransformer && labelName != '❌None')
|
||||
{
|
||||
labelName = nameTransformer(labelName)
|
||||
}
|
||||
|
||||
listHtml += `<li ${selected}>
|
||||
<a href="javascript:void(0)" onclick="setTextValue('${targetField}','${item.id}')">${item.name}</a>
|
||||
<a href="javascript:void(0)" onclick="setTextValue('${targetField}','${item.id}')">${labelName}</a>
|
||||
</li>`;
|
||||
|
||||
});
|
||||
@@ -236,6 +242,8 @@ function genDevDetailsList(data, valuesArray, targetField) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// initialize
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user