mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
🔄Cache + Settings work
This commit is contained in:
@@ -1149,7 +1149,7 @@ function initializeCalendar () {
|
|||||||
} else {
|
} else {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
updateIconPreview('#txtIcon')
|
updateIconPreview('#txtIcon')
|
||||||
}, 100);
|
}, 500);
|
||||||
|
|
||||||
hideSpinner()
|
hideSpinner()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,9 +143,23 @@
|
|||||||
var tableOrder = [[3,'desc'], [0,'asc']];
|
var tableOrder = [[3,'desc'], [0,'asc']];
|
||||||
|
|
||||||
var tableColumnHide = [];
|
var tableColumnHide = [];
|
||||||
|
var tableColumnOrder = [];
|
||||||
|
var tableColumnVisible = [];
|
||||||
|
|
||||||
//initialize the table headers in the correct order
|
|
||||||
var headersDefaultOrder = [
|
|
||||||
|
|
||||||
|
// Read parameters & Initialize components
|
||||||
|
callAfterAppInitialized(main)
|
||||||
|
showSpinner();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
function main () {
|
||||||
|
|
||||||
|
//initialize the table headers in the correct order
|
||||||
|
var headersDefaultOrder = [
|
||||||
getString('Device_TableHead_Name'),
|
getString('Device_TableHead_Name'),
|
||||||
getString('Device_TableHead_Owner'),
|
getString('Device_TableHead_Owner'),
|
||||||
getString('Device_TableHead_Type'),
|
getString('Device_TableHead_Type'),
|
||||||
@@ -173,16 +187,8 @@
|
|||||||
|
|
||||||
// generate default order lists of given length
|
// generate default order lists of given length
|
||||||
var columnsStr = JSON.stringify(Array.from({ length: headersDefaultOrder.length }, (_, i) => i));
|
var columnsStr = JSON.stringify(Array.from({ length: headersDefaultOrder.length }, (_, i) => i));
|
||||||
var tableColumnOrder = Array.from({ length: headersDefaultOrder.length }, (_, i) => i);
|
tableColumnOrder = Array.from({ length: headersDefaultOrder.length }, (_, i) => i);
|
||||||
var tableColumnVisible = tableColumnOrder;
|
tableColumnVisible = tableColumnOrder;
|
||||||
|
|
||||||
// Read parameters & Initialize components
|
|
||||||
showSpinner();
|
|
||||||
main();
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
function main () {
|
|
||||||
|
|
||||||
handleLoadingDialog()
|
handleLoadingDialog()
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,10 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
var timerRefreshData = ''
|
var timerRefreshData = ''
|
||||||
|
|
||||||
var emptyArr = ['undefined', "", undefined, null, 'null'];
|
var emptyArr = ['undefined', "", undefined, null, 'null'];
|
||||||
var UI_LANG = "English";
|
var UI_LANG = "English";
|
||||||
var settingsJSON = {}
|
const allLanguages = ["en_us", "es_es", "de_de", "fr_fr", "it_it", "ru_ru", "nb_no", "pl_pl", "zh_cn"]; // needs to be same as in lang.php
|
||||||
|
var settingsJSON = {}
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -207,98 +208,123 @@ function getSetting (key) {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Get language string
|
// Get language string
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
function cacheStrings()
|
function cacheStrings() {
|
||||||
{
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if(!getCache('completedCalls').includes('cacheStrings'))
|
|
||||||
{
|
// Create a promise for each language
|
||||||
// handle core strings and translations
|
const languagePromises = allLanguages.map((language_code) => {
|
||||||
var allLanguages = ["en_us", "es_es", "de_de", "fr_fr", "it_it", "ru_ru", "nb_no", "pl_pl", "zh_cn"]; // needs to be same as in lang.php
|
return new Promise((resolveLang, rejectLang) => {
|
||||||
|
// Fetch core strings and translations
|
||||||
allLanguages.forEach(function (language_code) {
|
|
||||||
$.get(`php/templates/language/${language_code}.json?nocache=${Date.now()}`, function (res) {
|
|
||||||
// Iterate over each language
|
|
||||||
Object.entries(res).forEach(([key, value]) => {
|
|
||||||
// Store translations for each key-value pair
|
|
||||||
setCache(`pia_lang_${key}_${language_code}`, value)
|
|
||||||
});
|
|
||||||
|
|
||||||
// handle strings and translations from plugins
|
|
||||||
$.get(`api/table_plugins_language_strings.json?nocache=${Date.now()}`, function(res) {
|
|
||||||
|
|
||||||
data = res["data"];
|
|
||||||
|
|
||||||
data.forEach((langString) => {
|
|
||||||
setCache(`pia_lang_${langString.String_Key}_${langString.Language_Code}`, langString.String_Value)
|
|
||||||
});
|
|
||||||
}).then(() => handleSuccess('cacheStrings', resolve())).catch(() => handleFailure('cacheStrings', reject("cacheStrings already completed"))); // handle AJAX synchronization
|
|
||||||
|
|
||||||
|
$.get(`php/templates/language/${language_code}.json?nocache=${Date.now()}`)
|
||||||
|
.done((res) => {
|
||||||
|
// Iterate over each key-value pair and store the translations
|
||||||
|
Object.entries(res).forEach(([key, value]) => {
|
||||||
|
setCache(`pia_lang_${key}_${language_code}`, value);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fetch strings and translations from plugins
|
||||||
|
$.get(`api/table_plugins_language_strings.json?nocache=${Date.now()}`)
|
||||||
|
.done((pluginRes) => {
|
||||||
|
const data = pluginRes["data"];
|
||||||
|
|
||||||
|
// Store plugin translations
|
||||||
|
data.forEach((langString) => {
|
||||||
|
setCache(`pia_lang_${langString.String_Key}_${langString.Language_Code}`, langString.String_Value);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle successful completion of language processing
|
||||||
|
handleSuccess(`cacheStrings[${language_code}]`, resolveLang);
|
||||||
|
})
|
||||||
|
.fail((pluginError) => {
|
||||||
|
// Handle failure in plugin strings fetching
|
||||||
|
rejectLang(pluginError);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail((error) => {
|
||||||
|
// Handle failure in core strings fetching
|
||||||
|
rejectLang(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
// Wait for all language promises to complete
|
||||||
|
Promise.all(languagePromises)
|
||||||
|
.then(() => {
|
||||||
|
// All languages processed successfully
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
// Handle failure in any of the language processing
|
||||||
|
handleFailure('cacheStrings', reject);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
// Get translated language string
|
// Get translated language string
|
||||||
function getString (key) {
|
function getString(key) {
|
||||||
|
|
||||||
// handle initial load to make sure everything is set-up and cached
|
function fetchString(key) {
|
||||||
handleFirstLoad(getString)
|
UI_LANG = getSetting("UI_LANG");
|
||||||
|
|
||||||
UI_LANG = getSetting("UI_LANG");
|
|
||||||
|
|
||||||
lang_code = 'en_us';
|
let lang_code = 'en_us';
|
||||||
|
|
||||||
switch(UI_LANG)
|
switch (UI_LANG) {
|
||||||
{
|
case 'English':
|
||||||
case 'English':
|
lang_code = 'en_us';
|
||||||
lang_code = 'en_us';
|
break;
|
||||||
break;
|
case 'Spanish':
|
||||||
case 'Spanish':
|
lang_code = 'es_es';
|
||||||
lang_code = 'es_es';
|
break;
|
||||||
break;
|
case 'German':
|
||||||
case 'German':
|
lang_code = 'de_de';
|
||||||
lang_code = 'de_de';
|
break;
|
||||||
break;
|
case 'French':
|
||||||
case 'French':
|
lang_code = 'fr_fr';
|
||||||
lang_code = 'fr_fr';
|
break;
|
||||||
break;
|
case 'Norwegian':
|
||||||
case 'Norwegian':
|
lang_code = 'nb_no';
|
||||||
lang_code = 'nb_no';
|
break;
|
||||||
break;
|
case 'Polish (pl_pl)':
|
||||||
case 'Polish (pl_pl)':
|
lang_code = 'pl_pl';
|
||||||
lang_code = 'pl_pl';
|
break;
|
||||||
break;
|
case 'Portuguese (pt_br)':
|
||||||
case 'Portuguese (pt_br)':
|
lang_code = 'pt_br';
|
||||||
lang_code = 'pt_br';
|
break;
|
||||||
break;
|
case 'Turkish (tr_tr)':
|
||||||
case 'Turkish (tr_tr)':
|
lang_code = 'tr_tr';
|
||||||
lang_code = 'tr_tr';
|
break;
|
||||||
break;
|
case 'Italian (it_it)':
|
||||||
case 'Italian (it_it)':
|
lang_code = 'it_it';
|
||||||
lang_code = 'it_it';
|
break;
|
||||||
break;
|
case 'Russian':
|
||||||
case 'Russian':
|
lang_code = 'ru_ru';
|
||||||
lang_code = 'ru_ru';
|
break;
|
||||||
break;
|
case 'Chinese (zh_cn)':
|
||||||
case 'Chinese (zh_cn)':
|
lang_code = 'zh_cn';
|
||||||
lang_code = 'zh_cn';
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
result = getCache(`pia_lang_${key}_${lang_code}`, true);
|
|
||||||
|
|
||||||
|
let result = getCache(`pia_lang_${key}_${lang_code}`, true);
|
||||||
|
|
||||||
if(isEmpty(result))
|
if (isEmpty(result)) {
|
||||||
{
|
result = getCache(`pia_lang_${key}_en_us`, true);
|
||||||
result = getCache(`pia_lang_${key}_en_us`, true);
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
if (isAppInitialized()) {
|
||||||
|
return fetchString(key);
|
||||||
|
} else {
|
||||||
|
callAfterAppInitialized(() => fetchString(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// String utilities
|
// String utilities
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -334,6 +360,15 @@ function isValidBase64(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function isValidJSON(jsonString) {
|
||||||
|
try {
|
||||||
|
JSON.parse(jsonString);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// General utilities
|
// General utilities
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -835,7 +870,7 @@ function getDeviceDataByMac(macAddress, dbColumn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Cache teh devices as one JSON
|
// Cache the devices as one JSON
|
||||||
function cacheDevices()
|
function cacheDevices()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -918,6 +953,8 @@ function showSpinner(stringKey='Loading')
|
|||||||
text = getString(stringKey)
|
text = getString(stringKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
text = isEmpty(text) ? "Loading" : text;
|
||||||
|
|
||||||
if($("#loadingSpinner").length)
|
if($("#loadingSpinner").length)
|
||||||
{
|
{
|
||||||
$("#loadingSpinner").show();
|
$("#loadingSpinner").show();
|
||||||
@@ -1102,6 +1139,8 @@ function arraysContainSameValues(arr1, arr2) {
|
|||||||
const sessionStorageKey = "myScriptExecuted_common_js";
|
const sessionStorageKey = "myScriptExecuted_common_js";
|
||||||
var completedCalls = []
|
var completedCalls = []
|
||||||
var completedCalls_final = ['cacheSettings', 'cacheStrings', 'cacheDevices'];
|
var completedCalls_final = ['cacheSettings', 'cacheStrings', 'cacheDevices'];
|
||||||
|
var completedCallsCount = 0;
|
||||||
|
var completedCallsCount_final = allLanguages.length + 2; // number of language files + cacheDevices + cacheSettings
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Clearing all the caches
|
// Clearing all the caches
|
||||||
@@ -1139,10 +1178,24 @@ async function handleFirstLoad(callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Execute callback once app initialized
|
||||||
|
function callAfterAppInitialized(callback) {
|
||||||
|
if (!isAppInitialized()) {
|
||||||
|
setTimeout(() => {
|
||||||
|
callAfterAppInitialized(callback)
|
||||||
|
}, 500);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Check if the code has been executed before by checking sessionStorage
|
// Check if the code has been executed before by checking sessionStorage
|
||||||
function isAppInitialized() {
|
function isAppInitialized() {
|
||||||
return arraysContainSameValues(getCache("completedCalls").split(',').filter(Boolean), completedCalls_final);
|
// return arraysContainSameValues(getCache("completedCalls").split(',').filter(Boolean), completedCalls_final);
|
||||||
|
return (parseInt(getCache("completedCallsCount")) == completedCallsCount_final);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define a function that will execute the code only once
|
// Define a function that will execute the code only once
|
||||||
@@ -1151,9 +1204,10 @@ async function executeOnce() {
|
|||||||
|
|
||||||
if (!isAppInitialized()) {
|
if (!isAppInitialized()) {
|
||||||
try {
|
try {
|
||||||
await cacheStrings();
|
|
||||||
await cacheSettings();
|
|
||||||
await cacheDevices();
|
await cacheDevices();
|
||||||
|
await cacheSettings();
|
||||||
|
await cacheStrings();
|
||||||
|
|
||||||
console.log("✅ All AJAX callbacks have completed");
|
console.log("✅ All AJAX callbacks have completed");
|
||||||
onAllCallsComplete();
|
onAllCallsComplete();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1166,8 +1220,20 @@ async function executeOnce() {
|
|||||||
// Function to handle successful completion of an AJAX call
|
// Function to handle successful completion of an AJAX call
|
||||||
const handleSuccess = (callName) => {
|
const handleSuccess = (callName) => {
|
||||||
console.log(`AJAX call successful: ${callName}`);
|
console.log(`AJAX call successful: ${callName}`);
|
||||||
completedCalls.push(callName);
|
// completedCalls.push(callName);
|
||||||
setCache('completedCalls', mergeUniqueArrays(getCache('completedCalls').split(','), [callName]));
|
// setCache('completedCalls', mergeUniqueArrays(getCache('completedCalls').split(','), [callName]));
|
||||||
|
|
||||||
|
val = getCache('completedCallsCount');
|
||||||
|
|
||||||
|
if(val == "")
|
||||||
|
{
|
||||||
|
val = 0;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
val = parseInt(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
setCache('completedCallsCount', val + 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -1190,6 +1256,10 @@ const onAllCallsComplete = () => {
|
|||||||
sessionStorage.setItem(sessionStorageKey + '_time', millisecondsNow);
|
sessionStorage.setItem(sessionStorageKey + '_time', millisecondsNow);
|
||||||
|
|
||||||
console.log('✔ Cache initialized');
|
console.log('✔ Cache initialized');
|
||||||
|
// setTimeout(() => {
|
||||||
|
// location.reload()
|
||||||
|
// }, 10);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// If not all strings are initialized, retry initialization
|
// If not all strings are initialized, retry initialization
|
||||||
console.log('❌ Not all strings are initialized. Retrying...');
|
console.log('❌ Not all strings are initialized. Retrying...');
|
||||||
@@ -1199,14 +1269,13 @@ const onAllCallsComplete = () => {
|
|||||||
|
|
||||||
// Call any other initialization functions here if needed
|
// Call any other initialization functions here if needed
|
||||||
|
|
||||||
// No need for location.reload() here
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to check if all necessary strings are initialized
|
// Function to check if all necessary strings are initialized
|
||||||
const areAllStringsInitialized = () => {
|
const areAllStringsInitialized = () => {
|
||||||
// Implement logic to check if all necessary strings are initialized
|
// Implement logic to check if all necessary strings are initialized
|
||||||
// Return true if all strings are initialized, false otherwise
|
// Return true if all strings are initialized, false otherwise
|
||||||
return getString('UI_LANG') != ""
|
return getString('UI_LANG_name') != ""
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call the function to execute the code
|
// Call the function to execute the code
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ function checkDbLock() {
|
|||||||
type: "GET",
|
type: "GET",
|
||||||
|
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
console.log(response);
|
// console.log(response);
|
||||||
if (response == 0) {
|
if (response == 0) {
|
||||||
// console.log('Database is not locked');
|
// console.log('Database is not locked');
|
||||||
$(".header-status-locked-db").hide();
|
$(".header-status-locked-db").hide();
|
||||||
|
|||||||
@@ -259,7 +259,8 @@ function addList(element, clearInput = true) {
|
|||||||
.attr("value", input)
|
.attr("value", input)
|
||||||
.text(input);
|
.text(input);
|
||||||
|
|
||||||
const el = $(`#${toId}`).append(newOption);
|
// add new option
|
||||||
|
$(`#${toId}`).append(newOption);
|
||||||
|
|
||||||
// clear input
|
// clear input
|
||||||
if (clearInput) {
|
if (clearInput) {
|
||||||
@@ -269,6 +270,7 @@ function addList(element, clearInput = true) {
|
|||||||
// Initialize interaction options only for the newly added option
|
// Initialize interaction options only for the newly added option
|
||||||
initListInteractionOptions(newOption);
|
initListInteractionOptions(newOption);
|
||||||
|
|
||||||
|
// flag something changes to prevent navigating from page
|
||||||
settingsChanged();
|
settingsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,31 +281,6 @@ function removeFromList(element) {
|
|||||||
.find("option:last")
|
.find("option:last")
|
||||||
.remove();
|
.remove();
|
||||||
}
|
}
|
||||||
// ---------------------------------------------------------
|
|
||||||
function addInterface() {
|
|
||||||
ipMask = $("#ipMask").val();
|
|
||||||
ipInterface = $("#ipInterface").val();
|
|
||||||
|
|
||||||
full = ipMask + " --interface=" + ipInterface;
|
|
||||||
|
|
||||||
console.log(full);
|
|
||||||
|
|
||||||
if (ipMask == "" || ipInterface == "") {
|
|
||||||
showModalOk(
|
|
||||||
"Validation error",
|
|
||||||
"Specify both, the network mask and the interface"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$("#SCAN_SUBNETS").append(
|
|
||||||
$("<option disabled></option>").attr("value", full).text(full)
|
|
||||||
);
|
|
||||||
|
|
||||||
$("#ipMask").val("");
|
|
||||||
$("#ipInterface").val("");
|
|
||||||
|
|
||||||
settingsChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Function to remove an item from the select element
|
// Function to remove an item from the select element
|
||||||
@@ -555,7 +532,7 @@ function generateOptionsOrSetOptions(
|
|||||||
transformers = [] // Transformers to be applied to the values
|
transformers = [] // Transformers to be applied to the values
|
||||||
) {
|
) {
|
||||||
|
|
||||||
console.log(codeName);
|
// console.log(codeName);
|
||||||
|
|
||||||
// NOTE {value} options to replace with a setting or SQL value are handled in the cacheSettings() function
|
// NOTE {value} options to replace with a setting or SQL value are handled in the cacheSettings() function
|
||||||
options = arrayToObject(createArray(getSettingOptions(codeName)))
|
options = arrayToObject(createArray(getSettingOptions(codeName)))
|
||||||
|
|||||||
@@ -11,16 +11,7 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Initialize device selectors / pickers fields
|
// Initialize device selectors / pickers fields
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
function initDeviceSelectors() {
|
function initDeviceSelectors(devicesListAll_JSON) {
|
||||||
|
|
||||||
// console.log(devicesList)
|
|
||||||
// Retrieve device list from session variable
|
|
||||||
var devicesListAll_JSON = getCache('devicesListAll_JSON');
|
|
||||||
|
|
||||||
var devicesList = JSON.parse(devicesListAll_JSON);
|
|
||||||
|
|
||||||
// console.log(devicesList);
|
|
||||||
|
|
||||||
|
|
||||||
// Check if both device list exists
|
// Check if both device list exists
|
||||||
if (devicesListAll_JSON) {
|
if (devicesListAll_JSON) {
|
||||||
@@ -78,52 +69,6 @@ function initDeviceSelectors() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // -----------------------------------------------------------------------------
|
|
||||||
// // (ASYNC) Initiate dropdown
|
|
||||||
// function generateSetOptions(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
|
|
||||||
// nameTransformer) // callback to transform the name (e.g. base64)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// var optionsHtml = ""
|
|
||||||
|
|
||||||
// // NOTE {value} options to replace with a setting or SQL value are handled in the cacheSettings() function
|
|
||||||
// optionsArray = createArray(getSettingOptions(settingKey))
|
|
||||||
|
|
||||||
|
|
||||||
// // check if the result is a SQL query
|
|
||||||
// if(optionsArray.length > 0 && isSQLQuery(optionsArray[0]))
|
|
||||||
// {
|
|
||||||
|
|
||||||
// if (settingKey == "NEWDEV_dev_Network_Node_MAC_ADDR") {
|
|
||||||
// console.log("isSQLQuery in generateSetOptions");
|
|
||||||
|
|
||||||
// }
|
|
||||||
// readData(optionsArray[0], callbackToGenerateEntries, valuesArray, targetLocation, targetField, nameTransformer);
|
|
||||||
|
|
||||||
// } else // this should be already an array, e.g. from a setting or pre-defined
|
|
||||||
// {
|
|
||||||
// optionsArray.forEach(option => {
|
|
||||||
// let selected = valuesArray.includes(option) ? 'selected' : '';
|
|
||||||
// optionsHtml += `<option value="${option}" ${selected}>${option}</option>`;
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // Replace the specified placeholder div with the resulting HTML
|
|
||||||
// setTimeout(() => {
|
|
||||||
|
|
||||||
// $("#" + targetLocation).replaceWith(optionsHtml);
|
|
||||||
|
|
||||||
// }, 50);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Hide elements on the page based on the supplied setting
|
// Hide elements on the page based on the supplied setting
|
||||||
function hideUIelements(settingKey) {
|
function hideUIelements(settingKey) {
|
||||||
@@ -290,42 +235,57 @@ function getCellValue(row, index) {
|
|||||||
// initialize
|
// initialize
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function initSelect2() {
|
||||||
|
|
||||||
setTimeout(() => {
|
// Retrieve device list from session variable
|
||||||
|
var devicesListAll_JSON = getCache('devicesListAll_JSON');
|
||||||
|
|
||||||
initDeviceSelectors();
|
// check if cache ready
|
||||||
|
if(isValidJSON(devicesListAll_JSON))
|
||||||
|
{
|
||||||
|
// prepare HTML DOM before initializing the frotend
|
||||||
|
initDeviceSelectors(devicesListAll_JSON)
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
//Initialize Select2 Elements and make them sortable
|
//Initialize Select2 Elements and make them sortable
|
||||||
|
$(function () {
|
||||||
$(function () {
|
// Iterate over each Select2 dropdown
|
||||||
// Iterate over each Select2 dropdown
|
$('.select2').each(function() {
|
||||||
$('.select2').each(function() {
|
var selectEl = $(this).select2();
|
||||||
var selectEl = $(this).select2();
|
|
||||||
|
// Apply sortable functionality to the dropdown's dropdown-container
|
||||||
// Apply sortable functionality to the dropdown's dropdown-container
|
selectEl.next().children().children().children().sortable({
|
||||||
selectEl.next().children().children().children().sortable({
|
containment: 'parent',
|
||||||
containment: 'parent',
|
update: function () {
|
||||||
update: function () {
|
var sortedValues = $(this).children().map(function() {
|
||||||
var sortedValues = $(this).children().map(function() {
|
return $(this).attr('title');
|
||||||
return $(this).attr('title');
|
}).get();
|
||||||
}).get();
|
|
||||||
|
var sortedOptions = selectEl.find('option').sort(function(a, b) {
|
||||||
var sortedOptions = selectEl.find('option').sort(function(a, b) {
|
return sortedValues.indexOf($(a).text()) - sortedValues.indexOf($(b).text());
|
||||||
return sortedValues.indexOf($(a).text()) - sortedValues.indexOf($(b).text());
|
});
|
||||||
});
|
|
||||||
|
// Replace all options in selectEl
|
||||||
// Replace all options in selectEl
|
selectEl.empty().append(sortedOptions);
|
||||||
selectEl.empty().append(sortedOptions);
|
|
||||||
|
// Trigger change event on Select2
|
||||||
// Trigger change event on Select2
|
selectEl.trigger('change');
|
||||||
selectEl.trigger('change');
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
} else // cache not ready try later
|
||||||
|
{
|
||||||
|
setTimeout(() => {
|
||||||
|
initSelect2()
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to initialize select2
|
||||||
|
setTimeout(() => {
|
||||||
|
initSelect2()
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -101,10 +101,19 @@
|
|||||||
for (let j = i * elementsPerColumn; j < Math.min((i + 1) * elementsPerColumn, columns.length); j++) {
|
for (let j = i * elementsPerColumn; j < Math.min((i + 1) * elementsPerColumn, columns.length); j++) {
|
||||||
|
|
||||||
const setTypeObject = JSON.parse(columns[j].Type.replace(/'/g, '"'));
|
const setTypeObject = JSON.parse(columns[j].Type.replace(/'/g, '"'));
|
||||||
// console.log(setTypeObject);
|
// console.log(setTypeObject); 🔽
|
||||||
const lastElementObj = setTypeObject.elements[setTypeObject.elements.length - 1]
|
// const lastElementObj = setTypeObject.elements[setTypeObject.elements.length - 1]
|
||||||
|
|
||||||
const { elementType, elementOptions = [], transformers = [] } = lastElementObj;
|
// get the element with the input value(s)
|
||||||
|
let elementsWithInputValue = setTypeObject.elements.filter(element => element.elementHasInputValue === 1);
|
||||||
|
|
||||||
|
// if none found, take last
|
||||||
|
if(elementsWithInputValue.length == 0)
|
||||||
|
{
|
||||||
|
elementsWithInputValue = setTypeObject.elements[setTypeObject.elements.length - 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
const { elementType, elementOptions = [], transformers = [] } = elementsWithInputValue;
|
||||||
const {
|
const {
|
||||||
inputType,
|
inputType,
|
||||||
readOnly,
|
readOnly,
|
||||||
@@ -123,8 +132,8 @@
|
|||||||
// console.log(setTypeObject);
|
// console.log(setTypeObject);
|
||||||
// console.log(inputType);
|
// console.log(inputType);
|
||||||
|
|
||||||
// render based on element type
|
// render based on element type
|
||||||
if (lastElementObj.elementType === 'select') {
|
if (elementsWithInputValue.elementType === 'select') {
|
||||||
|
|
||||||
targetLocation = columns[j].Code_Name + "_generateSetOptions"
|
targetLocation = columns[j].Code_Name + "_generateSetOptions"
|
||||||
|
|
||||||
@@ -154,7 +163,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (lastElementObj.elementType === 'input'){
|
} else if (elementsWithInputValue.elementType === 'input'){
|
||||||
|
|
||||||
// Add classes specifically for checkboxes
|
// Add classes specifically for checkboxes
|
||||||
inputType === 'checkbox' ? inputClass = 'checkbox' : inputClass = 'form-control';
|
inputType === 'checkbox' ? inputClass = 'checkbox' : inputClass = 'form-control';
|
||||||
|
|||||||
@@ -173,6 +173,16 @@
|
|||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -194,15 +204,6 @@
|
|||||||
{ "getStringKey": "Gen_Remove_Last" }
|
{ "getStringKey": "Gen_Remove_Last" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -525,6 +525,16 @@
|
|||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -546,15 +556,6 @@
|
|||||||
{ "getStringKey": "Gen_Remove_Last" }
|
{ "getStringKey": "Gen_Remove_Last" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -52,6 +52,16 @@
|
|||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -73,15 +83,6 @@
|
|||||||
{ "getStringKey": "Gen_Remove_Last" }
|
{ "getStringKey": "Gen_Remove_Last" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -127,6 +128,16 @@
|
|||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -148,15 +159,6 @@
|
|||||||
{ "getStringKey": "Gen_Remove_Last" }
|
{ "getStringKey": "Gen_Remove_Last" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -194,14 +196,24 @@
|
|||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
{ "sourceSuffixes": [] },
|
{ "sourceSuffixes": ["_in"] },
|
||||||
{ "separator": "" },
|
{ "separator": "" },
|
||||||
{ "cssClasses": "col-sm-3" },
|
{ "cssClasses": "col-sm-2" },
|
||||||
{ "onClick": "removeAllOptions(this)" },
|
{ "onClick": "addList(this, false)" },
|
||||||
{ "getStringKey": "Gen_Remove_All" }
|
{ "getStringKey": "Gen_Add" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": ["base64"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -216,22 +228,13 @@
|
|||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
{ "sourceSuffixes": ["_in"] },
|
{ "sourceSuffixes": [] },
|
||||||
{ "separator": "" },
|
{ "separator": "" },
|
||||||
{ "cssClasses": "col-sm-2" },
|
{ "cssClasses": "col-sm-3" },
|
||||||
{ "onClick": "addList(this, false)" },
|
{ "onClick": "removeAllOptions(this)" },
|
||||||
{ "getStringKey": "Gen_Add" }
|
{ "getStringKey": "Gen_Remove_All" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": ["base64"]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -155,6 +155,16 @@
|
|||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -176,15 +186,6 @@
|
|||||||
{ "getStringKey": "Gen_Remove_Last" }
|
{ "getStringKey": "Gen_Remove_Last" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -434,6 +434,16 @@
|
|||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -455,15 +465,6 @@
|
|||||||
{ "getStringKey": "Gen_Remove_Last" }
|
{ "getStringKey": "Gen_Remove_Last" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -301,6 +301,16 @@
|
|||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -322,15 +332,6 @@
|
|||||||
{ "getStringKey": "Gen_Remove_Last" }
|
{ "getStringKey": "Gen_Remove_Last" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -271,6 +271,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"column": "Watched_Value3",
|
"column": "Watched_Value3",
|
||||||
|
"mapped_to_column": "cur_Type",
|
||||||
"css_classes": "col-sm-2",
|
"css_classes": "col-sm-2",
|
||||||
"default_value": "",
|
"default_value": "",
|
||||||
"localized": ["name"],
|
"localized": ["name"],
|
||||||
@@ -776,6 +777,16 @@
|
|||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -797,15 +808,6 @@
|
|||||||
{ "getStringKey": "Gen_Remove_Last" }
|
{ "getStringKey": "Gen_Remove_Last" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -624,6 +624,16 @@
|
|||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"elementType": "select",
|
||||||
|
"elementHasInputValue": 1,
|
||||||
|
"elementOptions": [
|
||||||
|
{ "multiple": "true" },
|
||||||
|
{ "readonly": "true" },
|
||||||
|
{ "editable": "true" }
|
||||||
|
],
|
||||||
|
"transformers": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"elementType": "button",
|
"elementType": "button",
|
||||||
"elementOptions": [
|
"elementOptions": [
|
||||||
@@ -645,15 +655,6 @@
|
|||||||
{ "getStringKey": "Gen_Remove_Last" }
|
{ "getStringKey": "Gen_Remove_Last" }
|
||||||
],
|
],
|
||||||
"transformers": []
|
"transformers": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"elementType": "select",
|
|
||||||
"elementOptions": [
|
|
||||||
{ "multiple": "true" },
|
|
||||||
{ "readonly": "true" },
|
|
||||||
{ "editable": "true" }
|
|
||||||
],
|
|
||||||
"transformers": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const isMetadata = codeName.includes('__metadata');
|
const isMetadata = codeName.includes('__metadata');
|
||||||
// is this isn't a metadata entry, get corresponding metadata object from the dummy setting
|
// if this isn't a metadata entry, get corresponding metadata object from the dummy setting
|
||||||
const setObj = isMetadata ? {} : JSON.parse(getSetting(`${codeName}__metadata`));
|
const setObj = isMetadata ? {} : JSON.parse(getSetting(`${codeName}__metadata`));
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -459,6 +459,8 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
}
|
}
|
||||||
|
|
||||||
// INPUT
|
// INPUT
|
||||||
|
|
||||||
|
console.log(codeName);
|
||||||
|
|
||||||
// Parse the setType JSON string into an object
|
// Parse the setType JSON string into an object
|
||||||
let inputHtml = '';
|
let inputHtml = '';
|
||||||
@@ -614,8 +616,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
clearCache()
|
clearCache()
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
var settingsArray = [];
|
var settingsArray = [];
|
||||||
|
|
||||||
// collect values for each of the different input form controls
|
// collect values for each of the different input form controls
|
||||||
@@ -628,12 +629,18 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
setType = set["Type"]
|
setType = set["Type"]
|
||||||
setCodeName = set["Code_Name"]
|
setCodeName = set["Code_Name"]
|
||||||
|
|
||||||
|
console.log(prefix);
|
||||||
|
|
||||||
const setTypeObject = JSON.parse(setType.replace(/'/g, '"'));
|
const setTypeObject = JSON.parse(setType.replace(/'/g, '"'));
|
||||||
// console.log(setTypeObject);
|
// console.log(setTypeObject);
|
||||||
|
|
||||||
const dataType = setTypeObject.dataType;
|
const dataType = setTypeObject.dataType;
|
||||||
const lastElementObj = setTypeObject.elements[setTypeObject.elements.length - 1];
|
// const lastElementObj = setTypeObject.elements[setTypeObject.elements.length - 1]; //🔽
|
||||||
const { elementType, elementOptions = [], transformers = [] } = lastElementObj;
|
|
||||||
|
// get the element with the input value(s)
|
||||||
|
const elementsWithInputValue = setTypeObject.elements.filter(element => element.elementHasInputValue === 1);
|
||||||
|
|
||||||
|
const { elementType, elementOptions = [], transformers = [] } = elementsWithInputValue;
|
||||||
const {
|
const {
|
||||||
inputType,
|
inputType,
|
||||||
readOnly,
|
readOnly,
|
||||||
@@ -714,13 +721,15 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
success: function(data, textStatus) {
|
success: function(data, textStatus) {
|
||||||
|
|
||||||
if(data == "OK")
|
if(data == "OK")
|
||||||
{
|
{
|
||||||
showMessage (getString("settings_saved"), 5000, "modal_grey");
|
// showMessage (getString("settings_saved"), 5000, "modal_grey");
|
||||||
// Remove navigation prompt "Are you sure you want to leave..."
|
// Remove navigation prompt "Are you sure you want to leave..."
|
||||||
window.onbeforeunload = null;
|
window.onbeforeunload = null;
|
||||||
|
|
||||||
// Reloads the current page
|
// Reloads the current page
|
||||||
setTimeout("clearCache()", 5000);
|
// setTimeout("clearCache()", 5000);
|
||||||
|
|
||||||
|
clearCache()
|
||||||
} else{
|
} else{
|
||||||
// something went wrong
|
// something went wrong
|
||||||
// write_notification(data, 'interrupt')
|
// write_notification(data, 'interrupt')
|
||||||
@@ -746,7 +755,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
<!-- INIT THE PAGE -->
|
<!-- INIT THE PAGE -->
|
||||||
<script defer>
|
<script defer>
|
||||||
|
|
||||||
function handleLoadingDialog()
|
function handleLoadingDialog()
|
||||||
{
|
{
|
||||||
|
|
||||||
// check if config file has been updated
|
// check if config file has been updated
|
||||||
@@ -779,7 +788,7 @@ function handleLoadingDialog()
|
|||||||
getData()
|
getData()
|
||||||
|
|
||||||
// reload page if outdated information might be displayed
|
// reload page if outdated information might be displayed
|
||||||
if(secondsSincePageLoad() > 3)
|
if(secondsSincePageLoad() > 5)
|
||||||
{
|
{
|
||||||
clearCache()
|
clearCache()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ def importConfigs (db, all_plugins):
|
|||||||
# ccd(key, default, config_dir, name, inputtype, options, group, events=[], desc = "", regex = "", setJsonMetadata = {}, overrideTemplate = {})
|
# ccd(key, default, config_dir, name, inputtype, options, group, events=[], desc = "", regex = "", setJsonMetadata = {}, overrideTemplate = {})
|
||||||
|
|
||||||
conf.LOADED_PLUGINS = ccd('LOADED_PLUGINS', [] , c_d, 'Loaded plugins', '{"dataType":"array", "elements": [{"elementType" : "select", "elementOptions" : [{"multiple":"true"}] ,"transformers": []}]}', '[]', 'General')
|
conf.LOADED_PLUGINS = ccd('LOADED_PLUGINS', [] , c_d, 'Loaded plugins', '{"dataType":"array", "elements": [{"elementType" : "select", "elementOptions" : [{"multiple":"true"}] ,"transformers": []}]}', '[]', 'General')
|
||||||
conf.SCAN_SUBNETS = ccd('SCAN_SUBNETS', ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0'] , c_d, 'Subnets to scan', '{"dataType": "array","elements": [ {"elementType": "input","elementOptions": [{ "placeholder": "192.168.1.0/24 --interface=eth1" },{ "suffix": "_in" },{ "cssClasses": "col-sm-10" },{ "prefillValue": "null" }],"transformers": [] }, {"elementType": "button","elementOptions": [{ "sourceSuffixes": ["_in"] },{ "separator": "" },{ "cssClasses": "col-xs-12" },{ "onClick": "addList(this, false)" },{ "getStringKey": "Gen_Add" }],"transformers": [] }, {"elementType": "button","elementOptions": [{ "sourceSuffixes": [] },{ "separator": "" },{ "cssClasses": "col-xs-6" },{ "onClick": "removeAllOptions(this)" },{ "getStringKey": "Gen_Remove_All" }],"transformers": []},{"elementType": "button","elementOptions": [{ "sourceSuffixes": [] },{ "separator": "" },{ "cssClasses": "col-xs-6" },{ "onClick": "removeFromList(this)" },{ "getStringKey": "Gen_Remove_Last" }],"transformers": []}, {"elementType": "select","elementOptions": [{ "multiple": "true" },{ "readonly": "true" },{ "editable": "true" }],"transformers": [] }]}', '[]', 'General')
|
conf.SCAN_SUBNETS = ccd('SCAN_SUBNETS', ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0'] , c_d, 'Subnets to scan', '{"dataType": "array","elements": [{"elementType": "input","elementOptions": [{"placeholder": "192.168.1.0/24 --interface=eth1"},{"suffix": "_in"},{"cssClasses": "col-sm-10"},{"prefillValue": "null"}],"transformers": []},{"elementType": "button","elementOptions": [{"sourceSuffixes": ["_in"]},{"separator": ""},{"cssClasses": "col-xs-12"},{"onClick": "addList(this, false)"},{"getStringKey": "Gen_Add"}],"transformers": []},{"elementType": "select","elementHasInputValue": 1,"elementOptions": [{"multiple": "true"},{"readonly": "true"},{"editable": "true"}],"transformers": []},{"elementType": "button","elementOptions": [{"sourceSuffixes": []},{"separator": ""},{"cssClasses": "col-xs-6"},{"onClick": "removeAllOptions(this)"},{"getStringKey": "Gen_Remove_All"}],"transformers": []},{"elementType": "button","elementOptions": [{"sourceSuffixes": []},{"separator": ""},{"cssClasses": "col-xs-6"},{"onClick": "removeFromList(this)"},{"getStringKey": "Gen_Remove_Last"}],"transformers": []}]}', '[]', 'General')
|
||||||
conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', '{"dataType":"string", "elements": [{"elementType" : "select", "elementOptions" : [] ,"transformers": []}]}', "['none', 'minimal', 'verbose', 'debug', 'trace']", 'General')
|
conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', '{"dataType":"string", "elements": [{"elementType" : "select", "elementOptions" : [] ,"transformers": []}]}', "['none', 'minimal', 'verbose', 'debug', 'trace']", 'General')
|
||||||
conf.TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General')
|
conf.TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General')
|
||||||
conf.PLUGINS_KEEP_HIST = ccd('PLUGINS_KEEP_HIST', 250 , c_d, 'Keep history entries', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', '[]', 'General')
|
conf.PLUGINS_KEEP_HIST = ccd('PLUGINS_KEEP_HIST', 250 , c_d, 'Keep history entries', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', '[]', 'General')
|
||||||
@@ -140,7 +140,7 @@ def importConfigs (db, all_plugins):
|
|||||||
conf.DAYS_TO_KEEP_EVENTS = ccd('DAYS_TO_KEEP_EVENTS', 90 , c_d, 'Delete events days', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', '[]', 'General')
|
conf.DAYS_TO_KEEP_EVENTS = ccd('DAYS_TO_KEEP_EVENTS', 90 , c_d, 'Delete events days', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', '[]', 'General')
|
||||||
conf.HRS_TO_KEEP_NEWDEV = ccd('HRS_TO_KEEP_NEWDEV', 0 , c_d, 'Keep new devices for', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', "[]", 'General')
|
conf.HRS_TO_KEEP_NEWDEV = ccd('HRS_TO_KEEP_NEWDEV', 0 , c_d, 'Keep new devices for', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', "[]", 'General')
|
||||||
conf.API_CUSTOM_SQL = ccd('API_CUSTOM_SQL', 'SELECT * FROM Devices WHERE dev_PresentLastScan = 0' , c_d, 'Custom endpoint', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General')
|
conf.API_CUSTOM_SQL = ccd('API_CUSTOM_SQL', 'SELECT * FROM Devices WHERE dev_PresentLastScan = 0' , c_d, 'Custom endpoint', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General')
|
||||||
conf.NETWORK_DEVICE_TYPES = ccd('NETWORK_DEVICE_TYPES', ['AP', 'Gateway', 'Firewall', 'Hypervisor', 'Powerline', 'Switch', 'WLAN', 'PLC', 'Router','USB LAN Adapter', 'USB WIFI Adapter', 'Internet'] , c_d, 'Network device types', '{"dataType": "array","elements": [ {"elementType": "input","elementOptions": [{ "placeholder": "Enter value" },{ "suffix": "_in" },{ "cssClasses": "col-sm-10" },{ "prefillValue": "null" }],"transformers": [] }, {"elementType": "button","elementOptions": [{ "sourceSuffixes": ["_in"] },{ "separator": "" },{ "cssClasses": "col-xs-12" },{ "onClick": "addList(this, false)" },{ "getStringKey": "Gen_Add" }],"transformers": [] }, {"elementType": "button","elementOptions": [{ "sourceSuffixes": [] },{ "separator": "" },{ "cssClasses": "col-xs-6" },{ "onClick": "removeAllOptions(this)" },{ "getStringKey": "Gen_Remove_All" }],"transformers": []},{"elementType": "button","elementOptions": [{ "sourceSuffixes": [] },{ "separator": "" },{ "cssClasses": "col-xs-6" },{ "onClick": "removeFromList(this)" },{ "getStringKey": "Gen_Remove_Last" }],"transformers": []}, {"elementType": "select","elementOptions": [{ "multiple": "true" },{ "readonly": "true" },{ "editable": "true" }],"transformers": [] }]}', '[]', 'General')
|
conf.NETWORK_DEVICE_TYPES = ccd('NETWORK_DEVICE_TYPES', ['AP', 'Gateway', 'Firewall', 'Hypervisor', 'Powerline', 'Switch', 'WLAN', 'PLC', 'Router','USB LAN Adapter', 'USB WIFI Adapter', 'Internet'] , c_d, 'Network device types', '{"dataType":"array","elements":[{"elementType":"input","elementOptions":[{"placeholder":"Entervalue"},{"suffix":"_in"},{"cssClasses":"col-sm-10"},{"prefillValue":"null"}],"transformers":[]},{"elementType":"button","elementOptions":[{"sourceSuffixes":["_in"]},{"separator":""},{"cssClasses":"col-xs-12"},{"onClick":"addList(this,false)"},{"getStringKey":"Gen_Add"}],"transformers":[]},{"elementType":"select", "elementHasInputValue":1,"elementOptions":[{"multiple":"true"},{"readonly":"true"},{"editable":"true"}],"transformers":[]},{"elementType":"button","elementOptions":[{"sourceSuffixes":[]},{"separator":""},{"cssClasses":"col-xs-6"},{"onClick":"removeAllOptions(this)"},{"getStringKey":"Gen_Remove_All"}],"transformers":[]},{"elementType":"button","elementOptions":[{"sourceSuffixes":[]},{"separator":""},{"cssClasses":"col-xs-6"},{"onClick":"removeFromList(this)"},{"getStringKey":"Gen_Remove_Last"}],"transformers":[]}]}', '[]', 'General')
|
||||||
|
|
||||||
# UI
|
# UI
|
||||||
conf.UI_LANG = ccd('UI_LANG', 'English' , c_d, 'Language Interface', '{"dataType":"string", "elements": [{"elementType" : "select", "elementOptions" : [] ,"transformers": []}]}', "['English', 'French', 'German', 'Norwegian', 'Russian', 'Spanish', 'Italian (it_it)', 'Portuguese (pt_br)', 'Polish (pl_pl)', 'Turkish (tr_tr)', 'Chinese (zh_cn)' ]", 'UI')
|
conf.UI_LANG = ccd('UI_LANG', 'English' , c_d, 'Language Interface', '{"dataType":"string", "elements": [{"elementType" : "select", "elementOptions" : [] ,"transformers": []}]}', "['English', 'French', 'German', 'Norwegian', 'Russian', 'Spanish', 'Italian (it_it)', 'Portuguese (pt_br)', 'Polish (pl_pl)', 'Turkish (tr_tr)', 'Chinese (zh_cn)' ]", 'UI')
|
||||||
|
|||||||
Reference in New Issue
Block a user