add msg.property option to rbe, randon, smooth and base64 nodes

This commit is contained in:
Dave Conway-Jones
2018-01-30 21:42:14 +00:00
parent 4ed7ab590d
commit be79b6a1c6
17 changed files with 527 additions and 565 deletions

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-random",
"version" : "0.0.8",
"version" : "0.1.0",
"description" : "A Node-RED node that when triggered generates a random number between two values.",
"dependencies" : {
},

View File

@@ -1,27 +1,31 @@
<script type="text/x-red" data-template-name="random">
<div class="form-row">
<label for="node-input-property"><i class="fa fa-ellipsis-h"></i> <span data-i18n="node-red:common.label.property"></span></label>
<input type="text" id="node-input-property" style="width:70%;"/>
</div>
<div class="form-row">
<label for="node-input-inte"><i class="fa fa-random"></i> Generate</label>
<select type="text" id="node-input-inte" style="width: 300px;">
<select type="text" id="node-input-inte" style="width:70%;">
<option value="true">a whole number - integer</option>
<option value="false">a real number - floating point</option>
</select>
</div>
<div class="form-row">
<label for="node-input-low"><i class="fa fa-arrow-down"></i> From</label>
<input type="text" id="node-input-low" placeholder="lowest number" style="width: 300px;">
<input type="text" id="node-input-low" placeholder="lowest number" style="width:70%;">
</div>
<div class="form-row">
<label for="node-input-high"><i class="fa fa-arrow-up"></i> To</label>
<input type="text" id="node-input-high" placeholder="highest number" style="width: 300px;">
<input type="text" id="node-input-high" placeholder="highest number" style="width:70%;">
</div>
<br/>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" style="width: 300px;">
<input type="text" id="node-input-name" placeholder="Name" style="width:70%;">
</div>
</script>
70%
<script type="text/x-red" data-help-name="random">
<p>Generates a random number between a low and high value.</p>
<p>If you return an integer it can <i>include</i> both the low and high values.</p>
@@ -36,7 +40,8 @@
name: {value:""},
low: {value:"1"},
high: {value:"10"},
inte: {value:"true"}
inte: {value:"true"},
property: {value:"payload",required:true}
},
inputs:1,
outputs:1,
@@ -46,6 +51,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>

View File

@@ -6,14 +6,17 @@ module.exports = function(RED) {
this.low = Number(n.low || 1);
this.high = Number(n.high || 10);
this.inte = n.inte || false;
this.property = n.property||"payload";
var node = this;
this.on("input", function(msg) {
var value;
if (node.inte == "true" || node.inte === true) {
msg.payload = Math.round(Number(Math.random()) * (node.high - node.low + 1) + node.low - 0.5);
value = Math.round(Number(Math.random()) * (node.high - node.low + 1) + node.low - 0.5);
}
else {
msg.payload = Number(Math.random()) * (node.high - node.low) + node.low;
value = Number(Math.random()) * (node.high - node.low) + node.low;
}
RED.util.setMessageProperty(msg,node.property,value);
node.send(msg);
});
}