provide a checkMinMax function for parameters
This commit is contained in:
parent
3e73f6b80c
commit
aba95db8f9
|
@ -106,7 +106,7 @@
|
||||||
"name": "stopApTime",
|
"name": "stopApTime",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "0",
|
"default": "0",
|
||||||
"check": "checkStopApTime",
|
"check": "checkMinMax",
|
||||||
"description": "stop the access point after that many minutes if not used",
|
"description": "stop the access point after that many minutes if not used",
|
||||||
"category": "system"
|
"category": "system"
|
||||||
},
|
},
|
||||||
|
@ -128,7 +128,8 @@
|
||||||
"label":"min XDR interval",
|
"label":"min XDR interval",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "100",
|
"default": "100",
|
||||||
"check": "checkMinXdrInterval",
|
"check": "checkMinMax",
|
||||||
|
"min": 10,
|
||||||
"description": "min interval in ms between 2 XDR records with the same transducer (> 10)",
|
"description": "min interval in ms between 2 XDR records with the same transducer (> 10)",
|
||||||
"category": "converter"
|
"category": "converter"
|
||||||
},
|
},
|
||||||
|
@ -137,7 +138,8 @@
|
||||||
"label":"min N2K interval",
|
"label":"min N2K interval",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "50",
|
"default": "50",
|
||||||
"check": "checkMin2KInterval",
|
"check": "checkMinMax",
|
||||||
|
"min": 5,
|
||||||
"description": "min interval in ms between 2 NMEA 2000 records with the same PGN (> 5)",
|
"description": "min interval in ms between 2 NMEA 2000 records with the same PGN (> 5)",
|
||||||
"category": "converter"
|
"category": "converter"
|
||||||
},
|
},
|
||||||
|
@ -363,7 +365,9 @@
|
||||||
"label": "max. TCP clients",
|
"label": "max. TCP clients",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "10",
|
"default": "10",
|
||||||
"check": "checkMaxClients",
|
"check": "checkMinMax",
|
||||||
|
"min": 0,
|
||||||
|
"max": 10,
|
||||||
"description": "the number of clients we allow to connect to us",
|
"description": "the number of clients we allow to connect to us",
|
||||||
"category": "TCP port"
|
"category": "TCP port"
|
||||||
},
|
},
|
||||||
|
|
37
web/index.js
37
web/index.js
|
@ -106,12 +106,17 @@ function resetForm(ev) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function checkMaxClients(v) {
|
function checkMinMax(v,allValues,def){
|
||||||
let parsed = parseInt(v);
|
let parsed=parseFloat(v);
|
||||||
if (isNaN(parsed)) return "not a valid number";
|
if (isNaN(parsed)) return "must be a number";
|
||||||
if (parsed < 0) return "must be >= 0";
|
if (def.min !== undefined){
|
||||||
if (parsed > 10) return "max is 10";
|
if (parsed < parseFloat(def.min)) return "must be >= "+def.min;
|
||||||
}
|
}
|
||||||
|
if (def.max !== undefined){
|
||||||
|
if (parsed > parseFloat(def.max)) return "must be <= "+def.max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function checkSystemName(v) {
|
function checkSystemName(v) {
|
||||||
//2...32 characters for ssid
|
//2...32 characters for ssid
|
||||||
let allowed = v.replace(/[^a-zA-Z0-9]*/g, '');
|
let allowed = v.replace(/[^a-zA-Z0-9]*/g, '');
|
||||||
|
@ -124,16 +129,7 @@ function checkApPass(v) {
|
||||||
return "password must be at least 8 characters";
|
return "password must be at least 8 characters";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function checkMinXdrInterval(v){
|
|
||||||
let vv=parseInt(v);
|
|
||||||
if (isNaN(vv)) return "is not a number";
|
|
||||||
if (vv < 10) return "must be >= 10";
|
|
||||||
}
|
|
||||||
function checkMin2KInterval(v){
|
|
||||||
let vv=parseInt(v);
|
|
||||||
if (isNaN(vv)) return "is not a number";
|
|
||||||
if (vv < 5) return "must be >= 5";
|
|
||||||
}
|
|
||||||
function checkXDR(v,allValues){
|
function checkXDR(v,allValues){
|
||||||
if (! v) return;
|
if (! v) return;
|
||||||
let parts=v.split(',');
|
let parts=v.split(',');
|
||||||
|
@ -175,7 +171,7 @@ function changeConfig() {
|
||||||
let check = v.getAttribute('data-check');
|
let check = v.getAttribute('data-check');
|
||||||
if (check) {
|
if (check) {
|
||||||
if (typeof (self[check]) === 'function') {
|
if (typeof (self[check]) === 'function') {
|
||||||
let res = self[check](v.value,allValues);
|
let res = self[check](v.value,allValues,getConfigDefition(name));
|
||||||
if (res) {
|
if (res) {
|
||||||
let value = v.value;
|
let value = v.value;
|
||||||
if (v.type === 'password') value = "******";
|
if (v.type === 'password') value = "******";
|
||||||
|
@ -301,8 +297,8 @@ let configDefinitions={};
|
||||||
let xdrConfig={};
|
let xdrConfig={};
|
||||||
//a map between the name of a config item and a list of dependend items
|
//a map between the name of a config item and a list of dependend items
|
||||||
let conditionRelations={};
|
let conditionRelations={};
|
||||||
function getConditions(name){
|
function getConfigDefition(name){
|
||||||
if (! name) return;
|
if (! name) return {};
|
||||||
let def;
|
let def;
|
||||||
for (let k in configDefinitions){
|
for (let k in configDefinitions){
|
||||||
if (configDefinitions[k].name === name){
|
if (configDefinitions[k].name === name){
|
||||||
|
@ -310,6 +306,11 @@ function getConditions(name){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (! def) return {};
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
function getConditions(name){
|
||||||
|
let def=getConfigDefition(name);
|
||||||
if (! def) return;
|
if (! def) return;
|
||||||
let condition=def.condition;
|
let condition=def.condition;
|
||||||
if (! condition) return;
|
if (! condition) return;
|
||||||
|
|
Loading…
Reference in New Issue