Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit 52baeb9

Browse files
maakbaasbenklop
andauthored
Add optionLabels (#120)
* Add requestHandler (fixes #119) (#125) * Add optionLabels (#120) * Updated generated HTML and docs * Bump version Co-authored-by: benklop <[email protected]>
1 parent 7d033c2 commit 52baeb9

File tree

5 files changed

+142
-131
lines changed

5 files changed

+142
-131
lines changed

docs/dashboard.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Supported data types are: bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, in
109109

110110
there are a few other specific fields. the `direction` field is mandatory, and `display` will show the items in the live dashboard whereas `control` will put the items as control inputs in the dashboard. For `display` items, `"display": "graph",` will turn them into a live graph, with the x-axis length in seconds defined by `"xaxis": 20`. For displayed floats, the field `digits` can be used to limit the number of digits shown.
111111

112-
For `control` items, `"control": "select",` will turn them into a drop down menu, with the options defined as `"options": [1, 2, 3]`.
112+
For `control` items, `"control": "select",` will turn them into a drop down menu, with the options defined as `"options": [1, 2, 3]`. In addition, you can specify `"optionLabels": ['one', 'two', 'three']` if you want the GUI to show more user-friendly labels in your drop down menu.
113113

114114
For this example, the pre-build python script `preBuildDash.py` will generate the files `dash.h` containing the type definition. This should be fairly self explanatory and show how the JSON file is translated into a C struct.
115115

gui/js/comp/ControlItem.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ export function ControlItem(props) {
9797
for (let i = 0; i < props.conditionalAttributes.options.length; i++) {
9898
if (data == props.conditionalAttributes.options[i]) {
9999
isOption = true;
100-
}
101-
options = <>{options}<option value={props.conditionalAttributes.options[i]}>{props.conditionalAttributes.options[i]}</option></>;
100+
}
101+
let optionLabel = props.conditionalAttributes.options[i];
102+
if (typeof props.conditionalAttributes.optionLabels[i] !== "undefined") {
103+
optionLabel = props.conditionalAttributes.optionLabels[i];
104+
}
105+
106+
options = <>{options}<option value={props.conditionalAttributes.options[i]}>{optionLabel}</option></>;
102107
}
103108

104109
if (!isOption) {

gui/js/comp/DashboardItems.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export function DashboardItems(props) {
175175

176176
case "select":
177177
conditionalAttributes.options = props.items[i].options;
178+
conditionalAttributes.optionLabels = props.items[i].optionLabels;
178179
break;
179180
}
180181

@@ -213,8 +214,12 @@ export function DashboardItems(props) {
213214
case "config":
214215
if (inputType == "select") {
215216
let options;
216-
for (let i = 0; i < conditionalAttributes.options.length; i++) {
217-
options = <>{options}<option value={conditionalAttributes.options[i]}>{conditionalAttributes.options[i]}</option></>;
217+
for (let i = 0; i < conditionalAttributes.options.length; i++) {
218+
let label = conditionalAttributes.options[i];
219+
if (typeof conditionalAttributes.optionLabels[i] !== "undefined") {
220+
label = conditionalAttributes.optionLabels[i];
221+
}
222+
options = <>{options}<option value={conditionalAttributes.options[i]}>{label}</option></>;
218223
}
219224
confItems = <>{confItems}
220225
<p>

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ESP8266 IoT Framework",
3-
"version": "1.8.1",
3+
"version": "1.9.0",
44
"description": "Framework for IoT projects implementing HTTPS requests, a React web interface, WiFi manager, configuration manager, file manager and OTA updates.",
55
"keywords": "esp8266,react,ota-updates,wifi-manager,https,file-manager",
66
"frameworks": "arduino",

0 commit comments

Comments
 (0)