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

Commit ec38ec8

Browse files
committed
Add slider (Implements #134)
1 parent 08fd042 commit ec38ec8

File tree

6 files changed

+121
-82
lines changed

6 files changed

+121
-82
lines changed

docs/config-manager.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ Supported data types are: bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, in
132132

133133
Adding the field `"control": "select",` will turn the item into a drop down menu, with the options defined as `"options": [1, 2, 3]`.
134134

135+
Adding the field `"control": "slider",` will turn the itemm into a slider, the `min`, `max` and `step` properties will also apply to the slider. This is only valid for numeric types.
136+
135137
There are a few unique parameters:
136138

137139
* The configuration parameter `projectName` is unique in this framework. You can remove it, but if you use a parameter with this name, it will be shown as the header title in the web interface :).

docs/dashboard.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ there are a few other specific fields. the `direction` field is mandatory, and `
111111

112112
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

114+
For `control` items, `"control": "slider",` will turn them into a slider, the `min`, `max` and `step` properties will also apply to the slider. This is only valid for numeric types.
115+
114116
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.
115117

116118
**Important:** After you have changed the JSON file, you also need to regenerate the web interface to reflect the latest changes by enabling the REBUILD_HTML build flag, otherwise the web interface will show the old dashboard data. Refer to [this section](https://github.com/maakbaas/esp8266-iot-framework/blob/master/docs/getting-started.md#editing-the-web-interface) for more details.

gui/js/comp/ControlItem.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export function ControlItem(props) {
113113
return <select id={props.name} name={props.name} value={data} onChange={(e) => { setTarget(e.target.value); save(); }}>
114114
{options}
115115
</select>;
116+
} else if (props.type == "slider") {
117+
return <>
118+
<input type="range" onChange={() => {save();}} id={props.name} name={props.name} value={data} {...props.conditionalAttributes} onInput={(e) => setTarget(e.target.value)} />
119+
<output>{data}</output>
120+
</>;
116121
} else if (checkbox) {
117122
return <input onClick={(e) => { setTarget(e.target.checked); save(); }} type={props.type} id={props.name} name={props.name} value={data} {...props.conditionalAttributes} />;
118123
} else if (props.type == "color") {

gui/js/comp/DashboardItems.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function DashboardItems(props) {
141141

142142
} else { value = ""; }
143143

144-
//const configInputAttributes = DefaultTypeAttributes[props.items[i].type] || {};
144+
const configInputAttributes = DefaultTypeAttributes[props.items[i].type] || {};
145145
let inputType;
146146
if (typeof props.items[i].control !== "undefined") {
147147
inputType = props.items[i].control;
@@ -173,6 +173,12 @@ export function DashboardItems(props) {
173173
}
174174
break;
175175

176+
case "slider":
177+
conditionalAttributes.min = props.items[i].min || configInputAttributes.min;
178+
conditionalAttributes.max = props.items[i].max || configInputAttributes.max;
179+
conditionalAttributes.step = props.items[i].step || configInputAttributes.step;
180+
break;
181+
176182
case "select":
177183
conditionalAttributes.options = props.items[i].options;
178184
conditionalAttributes.optionLabels = props.items[i].options;
@@ -232,6 +238,17 @@ export function DashboardItems(props) {
232238
</select>
233239
</p>
234240
</>;
241+
} else if (inputType == "slider") {
242+
243+
const [rangeval, setRangeval] = useState(null);
244+
245+
confItems = <>{confItems}
246+
<p>
247+
<label htmlFor={props.items[i].name}><b>{props.items[i].label || props.items[i].name}</b>:</label>
248+
<input type="range" id={props.items[i].name} name={props.items[i].name} value={rangeval || value} {...conditionalAttributes} disabled={props.items[i].disabled} onInput={(event) => setRangeval(event.target.value)} />
249+
<output>{rangeval || value}</output>
250+
</p>
251+
</>;
235252
} else {
236253
confItems = <>{confItems}
237254
<p>

gui/js/comp/UiComponents.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ export const Form = styled.form`
314314
max-width:100%;
315315
}
316316
317+
input[type=range] {
318+
width:380px;
319+
padding: 0.3em 0em;
320+
max-width:calc(100% - 70px);
321+
}
322+
323+
input[type=range] + * {
324+
vertical-align:top;
325+
display:inline-block;
326+
width:70px;
327+
text-align:right;
328+
}
329+
317330
input[type=color]
318331
{
319332
display:inline-block;

0 commit comments

Comments
 (0)