From de2f96a7ebdea848210c95af0218ec1abaad487a Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Tue, 30 Jul 2024 01:27:33 +0300 Subject: [PATCH] webui: disallow empty type[number] ...unless necessary, like with magnitude zero threshold --- code/html/src/panel-admin.html | 2 +- code/html/src/panel-dcz.html | 2 +- code/html/src/panel-general.html | 4 ++-- code/html/src/panel-idb.html | 2 +- code/html/src/panel-light.html | 6 +++--- code/html/src/panel-mqtt.html | 4 ++-- code/html/src/panel-relay.html | 2 +- code/html/src/panel-rfb.html | 2 +- code/html/src/panel-sch.html | 2 +- code/html/src/panel-sns.html | 4 ++-- code/html/src/panel-thermostat.html | 14 +++++++------- code/html/src/panel-wifi.html | 2 +- code/html/src/sensor.mjs | 23 +++++++++++++++-------- 13 files changed, 38 insertions(+), 31 deletions(-) diff --git a/code/html/src/panel-admin.html b/code/html/src/panel-admin.html index 6a88096f..93888aff 100644 --- a/code/html/src/panel-admin.html +++ b/code/html/src/panel-admin.html @@ -31,7 +31,7 @@
- + This is the port for the web interface and API requests. If different than 80 (standard HTTP port) you will have to add it explicitly to your requests: http://myip:myport/ diff --git a/code/html/src/panel-dcz.html b/code/html/src/panel-dcz.html index 0245abc6..5879a73c 100644 --- a/code/html/src/panel-dcz.html +++ b/code/html/src/panel-dcz.html @@ -36,7 +36,7 @@ Lights (IN messages only)
- +
diff --git a/code/html/src/panel-general.html b/code/html/src/panel-general.html index 4c70fa8c..f30789a3 100644 --- a/code/html/src/panel-general.html +++ b/code/html/src/panel-general.html @@ -34,7 +34,7 @@
- + Delay in milliseconds to detect a double or triple click (from 0 to 1000ms).
The lower this number the faster the device will respond to button clicks but the harder it will be to get the expected event. @@ -78,7 +78,7 @@
- + How often the heartbeat messages should be sent (number of seconds). diff --git a/code/html/src/panel-idb.html b/code/html/src/panel-idb.html index f8acb1a3..e957b712 100644 --- a/code/html/src/panel-idb.html +++ b/code/html/src/panel-idb.html @@ -29,7 +29,7 @@
- +
diff --git a/code/html/src/panel-light.html b/code/html/src/panel-light.html index 6fa4938f..c99ba396 100644 --- a/code/html/src/panel-light.html +++ b/code/html/src/panel-light.html @@ -20,7 +20,7 @@
- + (ms) @@ -82,7 +82,7 @@
- + (ms) @@ -93,7 +93,7 @@
- + (ms) diff --git a/code/html/src/panel-mqtt.html b/code/html/src/panel-mqtt.html index 22dcaa07..67554998 100644 --- a/code/html/src/panel-mqtt.html +++ b/code/html/src/panel-mqtt.html @@ -23,7 +23,7 @@
- +
@@ -50,7 +50,7 @@
- + (seconds) diff --git a/code/html/src/panel-relay.html b/code/html/src/panel-relay.html index 34f67b43..2ca7e6e1 100644 --- a/code/html/src/panel-relay.html +++ b/code/html/src/panel-relay.html @@ -28,7 +28,7 @@
- + (ms) Wait for the specified time before applying the relay status, when multiple relays change simultaneously. diff --git a/code/html/src/panel-rfb.html b/code/html/src/panel-rfb.html index a2375544..722ac10c 100644 --- a/code/html/src/panel-rfb.html +++ b/code/html/src/panel-rfb.html @@ -27,7 +27,7 @@
- + Number of times to repeat the outgoing transmission diff --git a/code/html/src/panel-sch.html b/code/html/src/panel-sch.html index ebf59901..4c17e6c2 100644 --- a/code/html/src/panel-sch.html +++ b/code/html/src/panel-sch.html @@ -27,7 +27,7 @@
- + Number of days to look back when restoring schedule. Set to zero to only check current day. diff --git a/code/html/src/panel-sns.html b/code/html/src/panel-sns.html index 2167898e..49099a81 100644 --- a/code/html/src/panel-sns.html +++ b/code/html/src/panel-sns.html @@ -38,7 +38,7 @@
- + second(s) @@ -140,7 +140,7 @@
Zero threshold - Report only when the value is above this threshold. Set to NaN (default) to disable. + Report only when the value is above this threshold. No threshold by default (empty value).
diff --git a/code/html/src/panel-thermostat.html b/code/html/src/panel-thermostat.html index d29968ad..b5f1ac76 100644 --- a/code/html/src/panel-thermostat.html +++ b/code/html/src/panel-thermostat.html @@ -34,14 +34,14 @@
- +
- +
@@ -66,7 +66,7 @@
- + (seconds) @@ -80,7 +80,7 @@
- + (minutes) @@ -88,7 +88,7 @@
- + (minutes) @@ -102,7 +102,7 @@
- + (minutes) @@ -110,7 +110,7 @@
- + (minutes) diff --git a/code/html/src/panel-wifi.html b/code/html/src/panel-wifi.html index 32504ccb..060b0b81 100644 --- a/code/html/src/panel-wifi.html +++ b/code/html/src/panel-wifi.html @@ -41,7 +41,7 @@
-
+
When scanning is enabled, also periodically check available networks when the currently connected network RSSI is below this value. diff --git a/code/html/src/sensor.mjs b/code/html/src/sensor.mjs index 8c53d82f..dd8cf257 100644 --- a/code/html/src/sensor.mjs +++ b/code/html/src/sensor.mjs @@ -324,13 +324,16 @@ function emonRatioInfo(id) { return magnitudeSettingInfo(id, "Ratio"); } +/** @typedef {{required?: boolean, min?: string, max?: string}} MagnitudeNumberOptions */ + /** * @param {string} containerId * @param {number} id * @param {string} keySuffix * @param {number} value + * @param {MagnitudeNumberOptions} options */ -function initMagnitudeNumberSetting(containerId, id, keySuffix, value) { +function initMagnitudeNumberSetting(containerId, id, keySuffix, value, {required = true, min = "", max = ""} = {}) { const container = document.getElementById(containerId); if (!container) { return; @@ -345,15 +348,19 @@ function initMagnitudeNumberSetting(containerId, id, keySuffix, value) { const template = new NumberInput(); mergeTemplate(container, template.with( - (label, input) => { + (label, input, span) => { label.textContent = info.name; - label.htmlFor = input.id; + label.htmlFor = info.key; input.id = info.key; - input.name = input.id; + input.name = info.key; + input.required = required; + input.min = min; + input.max = max; input.value = value.toString(); - setOriginalsFromValues([input]); + setOriginalFromValue(input); + listenEnumerableMagnitudeDescription(span, id); })); } @@ -478,19 +485,19 @@ function initMagnitudesSettings(values, schema) { if (typeof threshold === "number") { initMagnitudeNumberSetting( "magnitude-zero-thresholds", id, - "ZeroThreshold", threshold); + "ZeroThreshold", threshold, {required: false}); } if (typeof settings.MinDelta === "number") { initMagnitudeNumberSetting( "magnitude-min-deltas", id, - "MinDelta", settings.MinDelta); + "MinDelta", settings.MinDelta, {min: "0"}); } if (typeof settings.MaxDelta === "number") { initMagnitudeNumberSetting( "magnitude-max-deltas", id, - "MaxDelta", settings.MaxDelta); + "MaxDelta", settings.MaxDelta, {min: "0"}); } }); }