mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
add msg. select to range and yaml nodes,
re-order son node (name to bottom) add common.label.property to messages list
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
|
||||
<script type="text/x-red" data-template-name="range">
|
||||
<div class="form-row">
|
||||
<label for="node-input-property"><i class="fa fa-ellipsis-h"></i> <span data-i18n="common.label.property"></span></label>
|
||||
<input type="text" id="node-input-property" style="width:calc(70% - 1px)"/>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-action"><i class="fa fa-dot-circle-o"></i> <span data-i18n="range.label.action"></span></label>
|
||||
<select id="node-input-action" style="width:70%;">
|
||||
@@ -65,6 +69,7 @@
|
||||
maxout: {value:"",required:true,validate:RED.validators.number()},
|
||||
action: {value:"scale"},
|
||||
round: {value:false},
|
||||
property: {value:"payload",required:true},
|
||||
name: {value:""}
|
||||
},
|
||||
inputs: 1,
|
||||
@@ -75,6 +80,12 @@
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name ? "node_label_italic" : "";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
if (this.property === undefined) {
|
||||
$("#node-input-property").val("payload");
|
||||
}
|
||||
$("#node-input-property").typedInput({default:'msg',types:['msg']});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@@ -24,11 +24,13 @@ module.exports = function(RED) {
|
||||
this.maxin = Number(n.maxin);
|
||||
this.minout = Number(n.minout);
|
||||
this.maxout = Number(n.maxout);
|
||||
this.property = n.property||"payload";
|
||||
var node = this;
|
||||
|
||||
this.on('input', function (msg) {
|
||||
if (msg.hasOwnProperty("payload")) {
|
||||
var n = Number(msg.payload);
|
||||
var value = RED.util.getMessageProperty(msg,node.property);
|
||||
if (value !== undefined) {
|
||||
var n = Number(value);
|
||||
if (!isNaN(n)) {
|
||||
if (node.action == "clamp") {
|
||||
if (n < node.minin) { n = node.minin; }
|
||||
@@ -38,11 +40,12 @@ module.exports = function(RED) {
|
||||
var divisor = node.maxin - node.minin;
|
||||
n = ((n - node.minin) % divisor + divisor) % divisor + node.minin;
|
||||
}
|
||||
msg.payload = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
|
||||
if (node.round) { msg.payload = Math.round(msg.payload); }
|
||||
value = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
|
||||
if (node.round) { value = Math.round(value); }
|
||||
RED.util.setMessageProperty(msg,node.property,value);
|
||||
node.send(msg);
|
||||
}
|
||||
else { node.log(RED._("range.errors.notnumber")+": "+msg.payload); }
|
||||
else { node.log(RED._("range.errors.notnumber")+": "+value); }
|
||||
}
|
||||
else { node.send(msg); } // If no payload - just pass it on.
|
||||
});
|
||||
|
Reference in New Issue
Block a user