From 8924ac278351a7ed2046113fb963b26eb72a8d58 Mon Sep 17 00:00:00 2001 From: Rafael Muynarsk Date: Sat, 23 Apr 2022 20:18:51 -0300 Subject: [PATCH 1/3] implementing message count on the debug node --- .../@node-red/nodes/core/common/21-debug.html | 16 +++- .../@node-red/nodes/core/common/21-debug.js | 84 ++++++++++++------- 2 files changed, 65 insertions(+), 35 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/common/21-debug.html b/packages/node_modules/@node-red/nodes/core/common/21-debug.html index 49387c860..001d62b03 100644 --- a/packages/node_modules/@node-red/nodes/core/common/21-debug.html +++ b/packages/node_modules/@node-red/nodes/core/common/21-debug.html @@ -453,9 +453,16 @@ label: RED._("node-red:debug.autostatus"), hasValue: false }; + + var counter = { + value: "counter", + label: "message count", + hasValue: false + }; + $("#node-input-typed-status").typedInput({ default: "auto", - types:[autoType, "msg", "jsonata"], + types:[autoType, "msg", "jsonata", counter], typeField: $("#node-input-statusType") }); var that = this; @@ -492,7 +499,7 @@ types:['msg', fullType, "jsonata"], typeField: $("#node-input-targetType") }); - if (this.targetType === "jsonata") { + if (this.targetType === "jsonata") { var property = this.complete || ""; $("#node-input-typed-complete").typedInput('type','jsonata'); $("#node-input-typed-complete").typedInput('value',property); @@ -514,12 +521,13 @@ $("#node-input-tostatus").on('change',function() { if ($(this).is(":checked")) { - if (!that.hasOwnProperty("statusVal") || that.statusVal === "") { + if (!that.hasOwnProperty("statusVal") || that.statusVal !== "") { var type = $("#node-input-typed-complete").typedInput('type'); var comp = "payload"; if (type !== 'full') { comp = $("#node-input-typed-complete").typedInput('value'); } + console.log('hihi') that.statusType = "auto"; that.statusVal = comp; } @@ -550,4 +558,4 @@ } }); })(); - + \ No newline at end of file diff --git a/packages/node_modules/@node-red/nodes/core/common/21-debug.js b/packages/node_modules/@node-red/nodes/core/common/21-debug.js index c4b7c436f..b01d5ccf2 100644 --- a/packages/node_modules/@node-red/nodes/core/common/21-debug.js +++ b/packages/node_modules/@node-red/nodes/core/common/21-debug.js @@ -21,6 +21,9 @@ module.exports = function(RED) { this.statusType = n.statusType || "auto"; this.statusVal = n.statusVal || this.complete; this.tosidebar = n.tosidebar; + this.counter = 0; + this.lastTime = new Date().getTime(); + this.timeout = null; if (this.tosidebar === undefined) { this.tosidebar = true; } this.active = (n.active === null || typeof n.active === "undefined") || n.active; if (this.tostatus) { @@ -32,6 +35,11 @@ module.exports = function(RED) { var statExpression = hasStatExpression ? n.statusVal : null; var node = this; + if ( node.statusType === "counter" ){ + node.status({fill:"blue", shape:"ring", text: node.counter}); + } else { + node.status({fill:"", shape:"", text: ""}); + } var preparedEditExpression = null; var preparedStatExpression = null; if (editExpression) { @@ -108,43 +116,57 @@ module.exports = function(RED) { } }) this.on("input", function(msg, send, done) { - if (hasOwnProperty.call(msg, "status") && msg.status && - hasOwnProperty.call(msg.status, "source") && msg.status.source && - hasOwnProperty.call(msg.status.source, "id") && (msg.status.source.id === node.id)) { + if (hasOwnProperty.call(msg, "status") && hasOwnProperty.call(msg.status, "source") && hasOwnProperty.call(msg.status.source, "id") && (msg.status.source.id === node.id)) { done(); return; } if (node.tostatus === true) { prepareStatus(msg, function(err,debugMsg) { if (err) { node.error(err); return; } - var output = debugMsg.msg; - var st = (typeof output === 'string') ? output : util.inspect(output); - var fill = "grey"; - var shape = "dot"; - if (typeof output === 'object' && hasOwnProperty.call(output, "fill") && hasOwnProperty.call(output, "shape") && hasOwnProperty.call(output, "text")) { - fill = output.fill; - shape = output.shape; - st = output.text; - } - if (node.statusType === "auto") { - if (hasOwnProperty.call(msg, "error")) { - fill = "red"; - st = msg.error.message; - } - if (hasOwnProperty.call(msg, "status") && - msg.status) { - fill = msg.status.fill || "grey"; - shape = msg.status.shape || "ring"; - st = msg.status.text || ""; - } - } - if (st.length > 32) { st = st.substr(0,32) + "..."; } - var newStatus = {fill:fill, shape:shape, text:st}; - if (JSON.stringify(newStatus) !== node.oldState) { // only send if we have to - node.status(newStatus); - node.oldState = JSON.stringify(newStatus); - } + if ( node.statusType === "counter" ){ + const differenceOfTime = ((new Date()).getTime() - node.lastTime); + node.lastTime = new Date().getTime(); + node.counter++; + if ( differenceOfTime > 100 ){ + node.status({fill:"blue", shape:"ring", text: node.counter}); + } else { + if (node.timeout) { clearTimeout(node.timeout) } + node.timeout = setTimeout(() => { + node.status({fill:"blue", shape:"ring", text: node.counter}) + }, 200) + } + } else { + var output = debugMsg.msg; + var st = (typeof output === 'string') ? output : util.inspect(output); + var fill = "grey"; + var shape = "dot"; + if (typeof output === 'object' && hasOwnProperty.call(output, "fill") && hasOwnProperty.call(output, "shape") && hasOwnProperty.call(output, "text")) { + fill = output.fill; + shape = output.shape; + st = output.text; + } + if (node.statusType === "auto") { + if (hasOwnProperty.call(msg, "error")) { + fill = "red"; + st = msg.error.message; + } + if (hasOwnProperty.call(msg, "status")) { + fill = msg.status.fill || "grey"; + shape = msg.status.shape || "ring"; + st = msg.status.text || ""; + } + } + + if (st.length > 32) { st = st.substr(0,32) + "..."; } + + var newStatus = {fill:fill, shape:shape, text:st}; + if (JSON.stringify(newStatus) !== node.oldState) { // only send if we have to + node.status(newStatus); + node.oldState = JSON.stringify(newStatus); + } + } + }); } @@ -298,4 +320,4 @@ module.exports = function(RED) { res.sendStatus(404); } }); -}; +}; \ No newline at end of file From a63dfc4650e4d8bde47330a25f6a8c983615bd93 Mon Sep 17 00:00:00 2001 From: Rafael Muynarsk Date: Sun, 24 Apr 2022 17:13:53 -0300 Subject: [PATCH 2/3] Added condition that.statusType === "counter" in the debug.html file --- .../@node-red/nodes/core/common/21-debug.html | 5 ++++- .../@node-red/nodes/core/common/21-debug.js | 15 ++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/common/21-debug.html b/packages/node_modules/@node-red/nodes/core/common/21-debug.html index 001d62b03..49ee1b0f1 100644 --- a/packages/node_modules/@node-red/nodes/core/common/21-debug.html +++ b/packages/node_modules/@node-red/nodes/core/common/21-debug.html @@ -521,7 +521,10 @@ $("#node-input-tostatus").on('change',function() { if ($(this).is(":checked")) { - if (!that.hasOwnProperty("statusVal") || that.statusVal !== "") { + if (that.statusType === "counter") { + that.statusVal = ""; + } + else if (!that.hasOwnProperty("statusVal") || that.statusVal === "") { var type = $("#node-input-typed-complete").typedInput('type'); var comp = "payload"; if (type !== 'full') { diff --git a/packages/node_modules/@node-red/nodes/core/common/21-debug.js b/packages/node_modules/@node-red/nodes/core/common/21-debug.js index b01d5ccf2..302367b1e 100644 --- a/packages/node_modules/@node-red/nodes/core/common/21-debug.js +++ b/packages/node_modules/@node-red/nodes/core/common/21-debug.js @@ -37,7 +37,8 @@ module.exports = function(RED) { var node = this; if ( node.statusType === "counter" ){ node.status({fill:"blue", shape:"ring", text: node.counter}); - } else { + } + else { node.status({fill:"", shape:"", text: ""}); } var preparedEditExpression = null; @@ -125,18 +126,22 @@ module.exports = function(RED) { if (err) { node.error(err); return; } if ( node.statusType === "counter" ){ - const differenceOfTime = ((new Date()).getTime() - node.lastTime); + const differenceOfTime = (new Date().getTime() - node.lastTime); node.lastTime = new Date().getTime(); node.counter++; if ( differenceOfTime > 100 ){ node.status({fill:"blue", shape:"ring", text: node.counter}); - } else { - if (node.timeout) { clearTimeout(node.timeout) } + } + else { + if (node.timeout) { + clearTimeout(node.timeout) + } node.timeout = setTimeout(() => { node.status({fill:"blue", shape:"ring", text: node.counter}) }, 200) } - } else { + } + else { var output = debugMsg.msg; var st = (typeof output === 'string') ? output : util.inspect(output); var fill = "grey"; From 973b31521e27a705b60c1242d3a5e563457b5c46 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 26 Apr 2022 16:04:09 +0100 Subject: [PATCH 3/3] Tidy up debug message status count --- .../@node-red/nodes/core/common/21-debug.html | 4 +- .../@node-red/nodes/core/common/21-debug.js | 100 +++++++++--------- .../nodes/locales/en-US/messages.json | 1 + 3 files changed, 53 insertions(+), 52 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/common/21-debug.html b/packages/node_modules/@node-red/nodes/core/common/21-debug.html index 49ee1b0f1..0946809ea 100644 --- a/packages/node_modules/@node-red/nodes/core/common/21-debug.html +++ b/packages/node_modules/@node-red/nodes/core/common/21-debug.html @@ -456,7 +456,7 @@ var counter = { value: "counter", - label: "message count", + label: RED._("node-red:debug.messageCount"), hasValue: false }; @@ -561,4 +561,4 @@ } }); })(); - \ No newline at end of file + diff --git a/packages/node_modules/@node-red/nodes/core/common/21-debug.js b/packages/node_modules/@node-red/nodes/core/common/21-debug.js index 302367b1e..5a22194ad 100644 --- a/packages/node_modules/@node-red/nodes/core/common/21-debug.js +++ b/packages/node_modules/@node-red/nodes/core/common/21-debug.js @@ -35,12 +35,12 @@ module.exports = function(RED) { var statExpression = hasStatExpression ? n.statusVal : null; var node = this; - if ( node.statusType === "counter" ){ - node.status({fill:"blue", shape:"ring", text: node.counter}); - } + if ( node.statusType === "counter" ){ + node.status({fill:"blue", shape:"ring", text: node.counter}); + } else { - node.status({fill:"", shape:"", text: ""}); - } + node.status({fill:"", shape:"", text: ""}); + } var preparedEditExpression = null; var preparedStatExpression = null; if (editExpression) { @@ -115,6 +115,9 @@ module.exports = function(RED) { if (this.oldState) { this.status({}); } + if (this.timeout) { + clearTimeout(this.timeout) + } }) this.on("input", function(msg, send, done) { if (hasOwnProperty.call(msg, "status") && hasOwnProperty.call(msg.status, "source") && hasOwnProperty.call(msg.status.source, "id") && (msg.status.source.id === node.id)) { @@ -122,57 +125,54 @@ module.exports = function(RED) { return; } if (node.tostatus === true) { - prepareStatus(msg, function(err,debugMsg) { - if (err) { node.error(err); return; } - - if ( node.statusType === "counter" ){ - const differenceOfTime = (new Date().getTime() - node.lastTime); - node.lastTime = new Date().getTime(); - node.counter++; - if ( differenceOfTime > 100 ){ - node.status({fill:"blue", shape:"ring", text: node.counter}); - } - else { - if (node.timeout) { - clearTimeout(node.timeout) - } - node.timeout = setTimeout(() => { - node.status({fill:"blue", shape:"ring", text: node.counter}) - }, 200) - } - } + if ( node.statusType === "counter" ){ + const differenceOfTime = (new Date().getTime() - node.lastTime); + node.lastTime = new Date().getTime(); + node.counter++; + if ( differenceOfTime > 100 ){ + node.status({fill:"blue", shape:"ring", text: node.counter}); + } else { - var output = debugMsg.msg; - var st = (typeof output === 'string') ? output : util.inspect(output); - var fill = "grey"; - var shape = "dot"; - if (typeof output === 'object' && hasOwnProperty.call(output, "fill") && hasOwnProperty.call(output, "shape") && hasOwnProperty.call(output, "text")) { - fill = output.fill; - shape = output.shape; - st = output.text; - } - if (node.statusType === "auto") { - if (hasOwnProperty.call(msg, "error")) { - fill = "red"; - st = msg.error.message; - } - if (hasOwnProperty.call(msg, "status")) { - fill = msg.status.fill || "grey"; - shape = msg.status.shape || "ring"; - st = msg.status.text || ""; - } - } + if (node.timeout) { + clearTimeout(node.timeout) + } + node.timeout = setTimeout(() => { + node.status({fill:"blue", shape:"ring", text: node.counter}) + }, 200) + } + } else { + prepareStatus(msg, function(err,debugMsg) { + if (err) { node.error(err); return; } + var output = debugMsg.msg; + var st = (typeof output === 'string') ? output : util.inspect(output); + var fill = "grey"; + var shape = "dot"; + if (typeof output === 'object' && hasOwnProperty.call(output, "fill") && hasOwnProperty.call(output, "shape") && hasOwnProperty.call(output, "text")) { + fill = output.fill; + shape = output.shape; + st = output.text; + } + if (node.statusType === "auto") { + if (hasOwnProperty.call(msg, "error")) { + fill = "red"; + st = msg.error.message; + } + if (hasOwnProperty.call(msg, "status")) { + fill = msg.status.fill || "grey"; + shape = msg.status.shape || "ring"; + st = msg.status.text || ""; + } + } - if (st.length > 32) { st = st.substr(0,32) + "..."; } + if (st.length > 32) { st = st.substr(0,32) + "..."; } var newStatus = {fill:fill, shape:shape, text:st}; if (JSON.stringify(newStatus) !== node.oldState) { // only send if we have to node.status(newStatus); node.oldState = JSON.stringify(newStatus); } - } - - }); + }); + } } if (this.complete === "true") { @@ -315,7 +315,7 @@ module.exports = function(RED) { res.sendFile( req.params[0], options, - err => { + err => { if (err) { res.sendStatus(404); } @@ -325,4 +325,4 @@ module.exports = function(RED) { res.sendStatus(404); } }); -}; \ No newline at end of file +}; diff --git a/packages/node_modules/@node-red/nodes/locales/en-US/messages.json b/packages/node_modules/@node-red/nodes/locales/en-US/messages.json index bf6501977..59a18925f 100755 --- a/packages/node_modules/@node-red/nodes/locales/en-US/messages.json +++ b/packages/node_modules/@node-red/nodes/locales/en-US/messages.json @@ -125,6 +125,7 @@ "msgprop": "message property", "msgobj": "complete msg object", "autostatus": "same as debug output", + "messageCount": "message count", "to": "To", "debtab": "debug tab", "tabcon": "debug tab and console",