Add retain option to slider widget
parent
8fc0e2175d
commit
0f158886ef
|
@ -133,9 +133,10 @@ function updateScroll() {
|
||||||
element.scrollTop = element.scrollHeight;
|
element.scrollTop = element.scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
function publish(topic, value) {
|
function publish(topic, value, retain=false) {
|
||||||
var message = new Paho.MQTT.Message(value);
|
var message = new Paho.MQTT.Message(value);
|
||||||
message.destinationName = topic;
|
message.destinationName = topic;
|
||||||
|
message.retained = retain;
|
||||||
client.send(message);
|
client.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +160,8 @@ function init(brokerUri) {
|
||||||
slider.oninput = function() {
|
slider.oninput = function() {
|
||||||
this.onchange()
|
this.onchange()
|
||||||
var topic = this.getAttribute('data-pub-topic');
|
var topic = this.getAttribute('data-pub-topic');
|
||||||
publish(topic, this.value);
|
var retain = Boolean(this.getAttribute('data-retain'));
|
||||||
|
publish(topic, this.value, retain);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,8 @@ def slider_widget(label,
|
||||||
unit='',
|
unit='',
|
||||||
min_val=0,
|
min_val=0,
|
||||||
max_val=255,
|
max_val=255,
|
||||||
step=1):
|
step=1,
|
||||||
|
retain=False):
|
||||||
id_ = make_id()
|
id_ = make_id()
|
||||||
sub_topic = sub_topic or topic
|
sub_topic = sub_topic or topic
|
||||||
template = '''
|
template = '''
|
||||||
|
@ -58,6 +59,7 @@ def slider_widget(label,
|
||||||
<input id="{{id_}}"
|
<input id="{{id_}}"
|
||||||
class="slider update-policy-update-value {{sub_topic}}-value"
|
class="slider update-policy-update-value {{sub_topic}}-value"
|
||||||
data-pub-topic="{{topic}}"
|
data-pub-topic="{{topic}}"
|
||||||
|
data-retain="{{retain | string | lower}}"
|
||||||
{% if value_path %} data-value-path="{{value_path}}" {% endif %}
|
{% if value_path %} data-value-path="{{value_path}}" {% endif %}
|
||||||
min="{{min_val}}" type="range" max="{{max_val}}" step="{{step}}"
|
min="{{min_val}}" type="range" max="{{max_val}}" step="{{step}}"
|
||||||
value="{{min_val}}"/>
|
value="{{min_val}}"/>
|
||||||
|
@ -76,6 +78,7 @@ def slider_widget(label,
|
||||||
value_path=value_path,
|
value_path=value_path,
|
||||||
topic=topic,
|
topic=topic,
|
||||||
unit=unit,
|
unit=unit,
|
||||||
|
retain=retain,
|
||||||
id_=id_)
|
id_=id_)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue