mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02: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:
parent
543a2b9dc7
commit
a11a279c00
@ -5,7 +5,8 @@
|
|||||||
"topic": "Topic",
|
"topic": "Topic",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"username": "Username",
|
"username": "Username",
|
||||||
"password": "Password"
|
"password": "Password",
|
||||||
|
"property": "Property"
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"connected": "connected",
|
"connected": "connected",
|
||||||
@ -602,7 +603,7 @@
|
|||||||
"maxout": "e.g. 255"
|
"maxout": "e.g. 255"
|
||||||
},
|
},
|
||||||
"scale": {
|
"scale": {
|
||||||
"payload": "Scale msg.payload",
|
"payload": "Scale the message property",
|
||||||
"limit": "Scale and limit to the target range",
|
"limit": "Scale and limit to the target range",
|
||||||
"wrap": "Scale and wrap within the target range"
|
"wrap": "Scale and wrap within the target range"
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-template-name="range">
|
<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">
|
<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>
|
<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%;">
|
<select id="node-input-action" style="width:70%;">
|
||||||
@ -65,6 +69,7 @@
|
|||||||
maxout: {value:"",required:true,validate:RED.validators.number()},
|
maxout: {value:"",required:true,validate:RED.validators.number()},
|
||||||
action: {value:"scale"},
|
action: {value:"scale"},
|
||||||
round: {value:false},
|
round: {value:false},
|
||||||
|
property: {value:"payload",required:true},
|
||||||
name: {value:""}
|
name: {value:""}
|
||||||
},
|
},
|
||||||
inputs: 1,
|
inputs: 1,
|
||||||
@ -75,6 +80,12 @@
|
|||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return this.name ? "node_label_italic" : "";
|
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>
|
</script>
|
||||||
|
@ -24,11 +24,13 @@ module.exports = function(RED) {
|
|||||||
this.maxin = Number(n.maxin);
|
this.maxin = Number(n.maxin);
|
||||||
this.minout = Number(n.minout);
|
this.minout = Number(n.minout);
|
||||||
this.maxout = Number(n.maxout);
|
this.maxout = Number(n.maxout);
|
||||||
|
this.property = n.property||"payload";
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.on('input', function (msg) {
|
this.on('input', function (msg) {
|
||||||
if (msg.hasOwnProperty("payload")) {
|
var value = RED.util.getMessageProperty(msg,node.property);
|
||||||
var n = Number(msg.payload);
|
if (value !== undefined) {
|
||||||
|
var n = Number(value);
|
||||||
if (!isNaN(n)) {
|
if (!isNaN(n)) {
|
||||||
if (node.action == "clamp") {
|
if (node.action == "clamp") {
|
||||||
if (n < node.minin) { n = node.minin; }
|
if (n < node.minin) { n = node.minin; }
|
||||||
@ -38,11 +40,12 @@ module.exports = function(RED) {
|
|||||||
var divisor = node.maxin - node.minin;
|
var divisor = node.maxin - node.minin;
|
||||||
n = ((n - node.minin) % divisor + divisor) % divisor + 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;
|
value = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
|
||||||
if (node.round) { msg.payload = Math.round(msg.payload); }
|
if (node.round) { value = Math.round(value); }
|
||||||
|
RED.util.setMessageProperty(msg,node.property,value);
|
||||||
node.send(msg);
|
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.
|
else { node.send(msg); } // If no payload - just pass it on.
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-template-name="json">
|
<script type="text/x-red" data-template-name="json">
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-action"><span data-i18n="json.label.action"></span></label>
|
<label for="node-input-action"><span data-i18n="json.label.action"></span></label>
|
||||||
<select style="width:70%" id="node-input-action">
|
<select style="width:70%" id="node-input-action">
|
||||||
@ -14,11 +10,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label data-i18n="json.label.property"></label>
|
<label data-i18n="json.label.property"></label>
|
||||||
<input type="text" id="node-input-property" style="width: 70%"/>
|
<input type="text" id="node-input-property" style="width:70%;"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr align="middle"/>
|
<hr align="middle"/>
|
||||||
|
|
||||||
<div class="form-row node-json-to-json-options">
|
<div class="form-row node-json-to-json-options">
|
||||||
<label style="width:100%; border-bottom: 1px solid #eee;"><span data-i18n="json.label.o2j"></span></label>
|
<label style="width:100%; border-bottom: 1px solid #eee;"><span data-i18n="json.label.o2j"></span></label>
|
||||||
</div>
|
</div>
|
||||||
@ -55,7 +53,6 @@
|
|||||||
receives a String, no further checks will be made of the property. It will
|
receives a String, no further checks will be made of the property. It will
|
||||||
not check the String is valid JSON nor will it reformat it if the format option
|
not check the String is valid JSON nor will it reformat it if the format option
|
||||||
is selected.</p>
|
is selected.</p>
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -64,8 +61,8 @@
|
|||||||
color:"#DEBD5C",
|
color:"#DEBD5C",
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
property: { value:"payload" },
|
property: {value:"payload",required:true},
|
||||||
action: { value:"" },
|
action: {value:""},
|
||||||
pretty: {value:false}
|
pretty: {value:false}
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-template-name="yaml">
|
<script type="text/x-red" data-template-name="yaml">
|
||||||
|
<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">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
@ -30,6 +34,7 @@
|
|||||||
category: 'function',
|
category: 'function',
|
||||||
color:"#DEBD5C",
|
color:"#DEBD5C",
|
||||||
defaults: {
|
defaults: {
|
||||||
|
property: {value:"payload",required:true},
|
||||||
name: {value:""}
|
name: {value:""}
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
@ -40,6 +45,12 @@
|
|||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return this.name?"node_label_italic":"";
|
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>
|
</script>
|
||||||
|
@ -4,20 +4,24 @@ module.exports = function(RED) {
|
|||||||
var yaml = require('js-yaml');
|
var yaml = require('js-yaml');
|
||||||
function YAMLNode(n) {
|
function YAMLNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
this.property = n.property||"payload";
|
||||||
var node = this;
|
var node = this;
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
if (msg.hasOwnProperty("payload")) {
|
var value = RED.util.getMessageProperty(msg,node.property);
|
||||||
if (typeof msg.payload === "string") {
|
if (value !== undefined) {
|
||||||
|
if (typeof value === "string") {
|
||||||
try {
|
try {
|
||||||
msg.payload = yaml.load(msg.payload);
|
value = yaml.load(value);
|
||||||
|
RED.util.setMessageProperty(msg,node.property,value);
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
catch(e) { node.error(e.message,msg); }
|
catch(e) { node.error(e.message,msg); }
|
||||||
}
|
}
|
||||||
else if (typeof msg.payload === "object") {
|
else if (typeof value === "object") {
|
||||||
if (!Buffer.isBuffer(msg.payload)) {
|
if (!Buffer.isBuffer(value)) {
|
||||||
try {
|
try {
|
||||||
msg.payload = yaml.dump(msg.payload);
|
value = yaml.dump(value);
|
||||||
|
RED.util.setMessageProperty(msg,node.property,value);
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user