mirror of https://github.com/node-red/node-red.git
Optionally add msg.complete to split node output
so can trigger join even when in manual mode. to address #4781optionally-add-complete-to-split-node
parent
cb0c484579
commit
c264419dd9
|
@ -16,10 +16,18 @@
|
|||
|
||||
<script type="text/html" data-template-name="split">
|
||||
<!-- <div class="form-row"><span data-i18n="[html]split.intro"></span></div> -->
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
||||
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-property"><i class="fa fa-forward"></i> <span data-i18n="split.split"></span></label>
|
||||
<input type="text" id="node-input-property" style="width:70%;"/>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input type="checkbox" id="node-input-addcomplete" style="margin-left:10px; vertical-align:baseline; width:auto;">
|
||||
<label for="node-input-addcomplete" style="width:auto;" data-i18n="split.addcomplete"></label>
|
||||
</div>
|
||||
<div class="form-row"><span data-i18n="[html]split.strBuff"></span></div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-splt" style="padding-left:10px; margin-right:-10px;" data-i18n="split.splitUsing"></label>
|
||||
|
@ -43,10 +51,6 @@
|
|||
<label for="node-input-addname-cb" style="width:auto;" data-i18n="split.addname"></label>
|
||||
<input type="text" id="node-input-addname" style="width:70%">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
||||
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
@ -61,6 +65,7 @@
|
|||
arraySpltType: {value:"len"},
|
||||
stream: {value:false},
|
||||
addname: {value:"", validate: RED.validators.typedInput({ type: 'msg', allowBlank: true })},
|
||||
addcomplete: {value:false},
|
||||
property: {value:"payload",required:true}
|
||||
},
|
||||
inputs:1,
|
||||
|
|
|
@ -21,13 +21,17 @@ module.exports = function(RED) {
|
|||
for (var i = 0; i < array.length-1; i++) {
|
||||
RED.util.setMessageProperty(msg,node.property,array[i]);
|
||||
msg.parts.index = node.c++;
|
||||
if (node.stream !== true) { msg.parts.count = array.length; }
|
||||
if (node.stream !== true) {
|
||||
msg.parts.count = array.length;
|
||||
if (node.addcomplete === true) { msg.complete = true; }
|
||||
}
|
||||
send(RED.util.cloneMessage(msg));
|
||||
}
|
||||
if (node.stream !== true) {
|
||||
RED.util.setMessageProperty(msg,node.property,array[i]);
|
||||
msg.parts.index = node.c++;
|
||||
msg.parts.count = array.length;
|
||||
if (node.addcomplete === true) { msg.complete = true; }
|
||||
send(RED.util.cloneMessage(msg));
|
||||
node.c = 0;
|
||||
}
|
||||
|
@ -40,6 +44,7 @@ module.exports = function(RED) {
|
|||
node.stream = n.stream;
|
||||
node.spltType = n.spltType || "str";
|
||||
node.addname = n.addname || "";
|
||||
node.addcomplete = n.addcomplete || false;
|
||||
node.property = n.property||"payload";
|
||||
try {
|
||||
if (node.spltType === "str") {
|
||||
|
@ -111,6 +116,7 @@ module.exports = function(RED) {
|
|||
if ((node.stream !== true) || (node.remainder.length === node.splt)) {
|
||||
RED.util.setMessageProperty(msg,node.property,node.remainder);
|
||||
msg.parts.index = node.c++;
|
||||
if (node.addcomplete === true) { msg.complete = true; }
|
||||
send(RED.util.cloneMessage(msg));
|
||||
node.pendingDones.forEach(d => d());
|
||||
node.pendingDones = [];
|
||||
|
@ -153,6 +159,7 @@ module.exports = function(RED) {
|
|||
}
|
||||
RED.util.setMessageProperty(msg,node.property,m);
|
||||
msg.parts.index = i;
|
||||
if (i === count-1 && node.addcomplete === true) { msg.complete = true; }
|
||||
pos += node.arraySplt;
|
||||
send(RED.util.cloneMessage(msg));
|
||||
}
|
||||
|
@ -172,6 +179,7 @@ module.exports = function(RED) {
|
|||
msg.parts.key = p;
|
||||
msg.parts.index = j;
|
||||
msg.parts.count = l;
|
||||
if (j == l-1 && node.addcomplete === true) { msg.complete = true; }
|
||||
send(RED.util.cloneMessage(msg));
|
||||
j += 1;
|
||||
}
|
||||
|
@ -207,6 +215,7 @@ module.exports = function(RED) {
|
|||
if ((node.stream !== true) || (node.buffer.length === node.splt)) {
|
||||
RED.util.setMessageProperty(msg,node.property,node.buffer);
|
||||
msg.parts.index = node.c++;
|
||||
if (node.addcomplete === true) { msg.complete = true; }
|
||||
send(RED.util.cloneMessage(msg));
|
||||
node.pendingDones.forEach(d => d());
|
||||
node.pendingDones = [];
|
||||
|
@ -253,6 +262,7 @@ module.exports = function(RED) {
|
|||
RED.util.setMessageProperty(msg,node.property,buff.slice(p,buff.length));
|
||||
msg.parts.index = node.c++;
|
||||
msg.parts.count = node.c++;
|
||||
if (node.addcomplete === true) { msg.complete = true; }
|
||||
send(RED.util.cloneMessage(msg));
|
||||
node.pendingDones.forEach(d => d());
|
||||
node.pendingDones = [];
|
||||
|
|
|
@ -1020,7 +1020,8 @@
|
|||
"splitUsing": "Split using",
|
||||
"splitLength": "Fixed length of",
|
||||
"stream": "Handle as a stream of messages",
|
||||
"addname": " Copy key to "
|
||||
"addname": " Copy key to ",
|
||||
"addcomplete": " Add msg.complete to last element of split."
|
||||
},
|
||||
"join": {
|
||||
"join": "join",
|
||||
|
|
Loading…
Reference in New Issue