docs + template setting override work

This commit is contained in:
Jokob-sk
2023-08-05 15:05:10 +10:00
parent e68a04ee5b
commit 88301c97eb
7 changed files with 119 additions and 34 deletions

View File

@@ -698,6 +698,8 @@ height: 50px;
margin-top: 50px;
}
/* Settings */
.settings_content {
padding: 10px;
/* background-color: #272c30; */
@@ -720,6 +722,28 @@ height: 50px;
width: auto
}
.override{
padding: 5px;
}
.override .override-text
{
float:left;
width: 80%;
}
.override .override-check
{
float:left;
width: 20%;
}
#settingsPage input[readonly] {
/* Apply styles to the readonly input */
background-color: #646566;
color: #000;
cursor: not-allowed;
}
/* Devices */
.drp-edit

View File

@@ -312,7 +312,7 @@ function saveSettings()
$temp = '['.$temp.']'; // wrap brackets
$txt .= $settingKey . "=" . $temp . "\n";
} elseif ($settingType == 'json' || substr($settingType, -9) === ".template") {
} elseif ($settingType == 'json') {
$txt .= $settingKey . "=" . $settingValue . "\n";
}
}

View File

@@ -421,8 +421,8 @@
"settings_old" : "The settings in the DB (shown on this page) are outdated. This is probably caused by a running scan. The settings were saved in the <code>pialert.conf</code> file, but the background process didn not have time to import it yet to the DB. You can wait until the settings get refreshed so you do not overwrite your old values. Feel free to save your settings either way if you don not mind losing the settings between the last save and now. There are also backup files created if you need to compare your settings later.",
"settings_imported" : "Last time settings were imported from the pialert.conf file:",
"settings_expand_all" : "Expand all",
"Setting_Override" : "Override default",
"Setting_Override_Description" : "TBD",
"Setting_Override" : "Override value",
"Setting_Override_Description" : "Enabling this option will override an App supplied default value with the value specified above.",
"General_display_name" : "General",
"General_icon" : "<i class=\"fa fa-gears\"></i>",
"ENABLE_ARPSCAN_name" : "Enable ARP scan",

View File

@@ -384,7 +384,7 @@ Below are some general additional notes, when defining `params`:
#### ⚙ Setting object structure
> [!INFO]
> [!NOTE]
> The settings flow and when Plugin specific settings are applied is described under the [Settings system](/docs/SETTINGS_SYSTEM.md).
Required attributes are:

View File

@@ -168,13 +168,9 @@
},
{
"function": "dev_Name",
"type": "text.template",
"type": "readonly",
"maxLength": 50,
"default_value": "(unknown)",
"override_value": {
"value":"(unknown)",
"override": true
},
"options": [],
"localized": ["name", "description"],
"name": [
@@ -195,6 +191,9 @@
"type": "string",
"maxLength": 30,
"default_value": "House",
"override_value": {
"override": false
},
"options": [],
"localized": ["name", "description"],
"name": [
@@ -254,6 +253,9 @@
"function": "dev_Favorite",
"type": "integer.checkbox",
"default_value": 0,
"override_value": {
"override": false
},
"options": [],
"localized": ["name", "description"],
"name": [
@@ -274,6 +276,9 @@
"type": "string",
"maxLength": 10,
"default_value": "",
"override_value": {
"override": false
},
"options": [],
"localized": ["name", "description"],
"name": [
@@ -371,7 +376,10 @@
{
"function": "dev_StaticIP",
"type": "integer.checkbox",
"default_value": 0,
"default_value": 1,
"override_value": {
"override": true
},
"options": [],
"localized": ["name", "description"],
"name": [
@@ -391,6 +399,9 @@
"function": "dev_ScanCycle",
"type": "integer.checkbox",
"default_value": 1,
"override_value": {
"override": true
},
"options": [],
"localized": ["name", "description"],
"name": [
@@ -409,7 +420,10 @@
{
"function": "dev_LogEvents",
"type": "integer.checkbox",
"default_value": 1,
"default_value": 0,
"override_value": {
"override": false
},
"options": [],
"localized": ["name", "description"],
"name": [
@@ -427,7 +441,10 @@
{
"function": "dev_AlertEvents",
"type": "integer.checkbox",
"default_value": 1,
"default_value": 0,
"override_value": {
"override": true
},
"options": [],
"localized": ["name", "description"],
"name": [

View File

@@ -217,34 +217,36 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
//pre-check if this is a json object that needs value extraction
let overridable = false;
let override = false;
let overrideValue = val;
let overridable = false; // indicates if the setting is overridable
let override = false; // If the setting is set to be overriden by the user or by default
let readonly = ""; // helper variable to make text input readonly
let disabled = ""; // helper variable to make checkbox input readonly
// TODO finish
if ('override_value' in setObj) {
overridable = true;
const overrideObj = setObj["override_value"]
const override = overrideObj["override"];
overrideValue = overrideObj["value"];
overrideObj = setObj["override_value"]
override = overrideObj["override"];
console.log(isJsonObject(val))
console.log(setObj)
console.log(group)
}
// prepare override checkbox and HTML
if(overridable)
{
let checked = override;
overrideHtml = `<div class="override">
<span class="overrideText" title="${getString("Setting_Override_Description")}">
{
let checked = override ? 'checked' : '';
overrideHtml = `<div class="override col-xs-12">
<div class="override-check col-xs-1">
<input onChange="overrideToggle(this)" my-data-type="${setType}" my-input-toggle-readonly="${codeName}" class="checkbox" id="${codeName}_override" type="checkbox" ${checked} />
</div>
<div class="override-text col-xs-11" title="${getString("Setting_Override_Description")}">
${getString("Setting_Override")}
</span>
<span class="overrideCheck">
<input onChange="overrideToggle()" my-data-type="${setType}" class="checkbox" id="${codeName}_override" type="checkbox" ${checked} />
</span>
</div>`;
}
</div>
</div>`;
}
// INPUT
@@ -261,7 +263,14 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
{
inputHtml = generateInputOptions(set, inputHtml, isMultiSelect = true)
} else{
inputHtml = `<input class="form-control" onChange="settingsChanged()" my-data-type="${setType}" id="${codeName}" value="${val}"/>`;
// if it's overridable set readonly accordingly
if(overridable)
{
override ? readonly = "" : readonly = " readonly" ;
}
inputHtml = `<input class="form-control" onChange="settingsChanged()" my-data-type="${setType}" id="${codeName}" value="${val}" ${readonly}/>`;
}
} else if (setType === 'integer') {
inputHtml = `<input onChange="settingsChanged()" my-data-type="${setType}" class="form-control" id="${codeName}" type="number" value="${val}"/>`;
@@ -270,8 +279,15 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
} else if (setType === 'readonly') {
inputHtml = `<input class="form-control input" my-data-type="${setType}" id="${codeName}" value="${val}" readonly/>`;
} else if (setType === 'boolean' || setType === 'integer.checkbox') {
let checked = val === 'True' || val === '1' ? 'checked' : '';
inputHtml = `<input onChange="settingsChanged()" my-data-type="${setType}" class="checkbox" id="${codeName}" type="checkbox" value="${val}" ${checked} />`;
let checked = val === 'True' || val === '1' ? 'checked' : '';
// if it's overridable set readonly accordingly
if(overridable)
{
override ? disabled = "" : disabled = " disabled" ;
}
inputHtml = `<input onChange="settingsChanged()" my-data-type="${setType}" class="checkbox" id="${codeName}" type="checkbox" value="${val}" ${checked} ${disabled}/>`;
} else if (setType === 'integer.select') {
inputHtml = generateInputOptions(set, inputHtml)
@@ -388,6 +404,34 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
return input;
}
// ---------------------------------------------------------
// Helper methods
// ---------------------------------------------------------
// Toggle readonly mode of teh target element specified by the id in the "my-input-toggle-readonly" attribute
function overrideToggle(element) {
settingsChanged();
targetId = $(element).attr("my-input-toggle-readonly");
inputElement = $(`#${targetId}`)[0];
if (!inputElement) {
console.error("Input element not found!");
return;
}
if (inputElement.type === "text" || inputElement.type === "password") {
inputElement.readOnly = !inputElement.readOnly;
} else if (inputElement.type === "checkbox") {
inputElement.disabled = !inputElement.disabled;
} else {
console.warn("Unsupported input type. Only text, password, and checkbox inputs are supported.");
}
}
// ---------------------------------------------------------
// Generate an array object from a string representation of an array
function createArray(input) {