1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Let Join node accumulate top level properties

Last in is still most significant
This commit is contained in:
Dave Conway-Jones 2018-07-08 16:52:30 +01:00
parent 4bcf13cb58
commit f870e9ed3e
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4

View File

@ -280,8 +280,8 @@ module.exports = function(RED) {
msgs.sort(function(x,y) { msgs.sort(function(x,y) {
var ix = x.parts.index; var ix = x.parts.index;
var iy = y.parts.index; var iy = y.parts.index;
if (ix < iy) return -flag; if (ix < iy) { return -flag; }
if (ix > iy) return flag; if (ix > iy) { return flag; }
return 0; return 0;
}); });
for(var msg of msgs) { for(var msg of msgs) {
@ -437,7 +437,8 @@ module.exports = function(RED) {
newArray = newArray.concat(n); newArray = newArray.concat(n);
}) })
group.payload = newArray; group.payload = newArray;
} else if (group.type === 'buffer') { }
else if (group.type === 'buffer') {
var buffers = []; var buffers = [];
var bufferLen = 0; var bufferLen = 0;
if (group.joinChar !== undefined) { if (group.joinChar !== undefined) {
@ -450,7 +451,8 @@ module.exports = function(RED) {
buffers.push(group.payload[i]); buffers.push(group.payload[i]);
bufferLen += group.payload[i].length; bufferLen += group.payload[i].length;
} }
} else { }
else {
bufferLen = group.bufferLen; bufferLen = group.bufferLen;
buffers = group.payload; buffers = group.payload;
} }
@ -463,7 +465,8 @@ module.exports = function(RED) {
groupJoinChar = group.joinChar.toString(); groupJoinChar = group.joinChar.toString();
} }
RED.util.setMessageProperty(group.msg,node.property,group.payload.join(groupJoinChar)); RED.util.setMessageProperty(group.msg,node.property,group.payload.join(groupJoinChar));
} else { }
else {
if (node.propertyType === 'full') { if (node.propertyType === 'full') {
group.msg = RED.util.cloneMessage(group.msg); group.msg = RED.util.cloneMessage(group.msg);
} }
@ -471,7 +474,8 @@ module.exports = function(RED) {
} }
if (group.msg.hasOwnProperty('parts') && group.msg.parts.hasOwnProperty('parts')) { if (group.msg.hasOwnProperty('parts') && group.msg.parts.hasOwnProperty('parts')) {
group.msg.parts = group.msg.parts.parts; group.msg.parts = group.msg.parts.parts;
} else { }
else {
delete group.msg.parts; delete group.msg.parts;
} }
delete group.msg.complete; delete group.msg.complete;
@ -525,7 +529,7 @@ module.exports = function(RED) {
payloadType = node.build; payloadType = node.build;
targetCount = node.count; targetCount = node.count;
joinChar = node.joiner; joinChar = node.joiner;
if (targetCount === 0 && msg.hasOwnProperty('parts')) { if (n.count === "" && msg.hasOwnProperty('parts')) {
targetCount = msg.parts.count || 0; targetCount = msg.parts.count || 0;
} }
if (node.build === 'object') { if (node.build === 'object') {
@ -554,7 +558,7 @@ module.exports = function(RED) {
payload:{}, payload:{},
targetCount:targetCount, targetCount:targetCount,
type:"object", type:"object",
msg:msg msg:RED.util.cloneMessage(msg)
}; };
} }
else if (node.accumulate === true) { else if (node.accumulate === true) {
@ -564,7 +568,7 @@ module.exports = function(RED) {
payload:{}, payload:{},
targetCount:targetCount, targetCount:targetCount,
type:payloadType, type:payloadType,
msg:msg msg:RED.util.cloneMessage(msg)
} }
if (payloadType === 'string' || payloadType === 'array' || payloadType === 'buffer') { if (payloadType === 'string' || payloadType === 'array' || payloadType === 'buffer') {
inflight[partId].payload = []; inflight[partId].payload = [];
@ -576,7 +580,7 @@ module.exports = function(RED) {
payload:[], payload:[],
targetCount:targetCount, targetCount:targetCount,
type:payloadType, type:payloadType,
msg:msg msg:RED.util.cloneMessage(msg)
}; };
if (payloadType === 'string') { if (payloadType === 'string') {
inflight[partId].joinChar = joinChar; inflight[partId].joinChar = joinChar;
@ -624,14 +628,14 @@ module.exports = function(RED) {
} }
group.currentCount++; group.currentCount++;
} }
// TODO: currently reuse the last received - add option to pick first received group.msg = Object.assign(group.msg, msg);
group.msg = msg;
var tcnt = group.targetCount; var tcnt = group.targetCount;
if (msg.hasOwnProperty("parts")) { tcnt = group.targetCount || msg.parts.count; } if (msg.hasOwnProperty("parts")) { tcnt = group.targetCount || msg.parts.count; }
if ((tcnt > 0 && group.currentCount >= tcnt) || msg.hasOwnProperty('complete')) { if ((tcnt > 0 && group.currentCount >= tcnt) || msg.hasOwnProperty('complete')) {
completeSend(partId); completeSend(partId);
} }
} catch(err) { }
catch(err) {
console.log(err.stack); console.log(err.stack);
} }
}); });