From 1d71fb3554c52902e40ac5dc3b042d8dac15123d Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Thu, 14 May 2020 15:38:48 +0100 Subject: [PATCH 1/6] Let debug node show status indpendent of main output --- .../@node-red/nodes/core/common/21-debug.html | 51 +++++++++----- .../@node-red/nodes/core/common/21-debug.js | 66 ++++++++++++++----- .../nodes/locales/en-US/messages.json | 1 + 3 files changed, 85 insertions(+), 33 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 6a87cbf21..20772c0de 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 @@ -6,25 +6,30 @@ -
-
+
+
+ + + + +
@@ -45,7 +50,9 @@ console: {value:false}, tostatus: {value:false}, complete: {value:"false", required:true}, - targetType: {value:undefined} + targetType: {value:undefined}, + statusVal: {value:""}, + statusType: {value:"msg"} }, label: function() { var suffix = ""; @@ -308,7 +315,6 @@ window.removeEventListener("message",this.handleWindowMessage); RED.actions.remove("core:show-debug-tab"); RED.actions.remove("core:clear-debug-messages"); - delete RED._debug; }, oneditprepare: function() { @@ -331,6 +337,7 @@ label: RED._("node-red:debug.msgobj"), hasValue: false }; + $("#node-input-typed-complete").typedInput({ default: "msg", types:['msg', fullType, "jsonata"], @@ -354,17 +361,30 @@ ) { $("#node-input-typed-complete").typedInput('value','payload'); } - if ($("#node-input-typed-complete").typedInput('type') === 'full') { - $("#node-tostatus-line").hide(); - } else { + }); + + $("#node-input-typed-status").typedInput({ + default: "msg", + types:['msg',"jsonata"], + typeField: $("#node-input-statusType") + }); + var that = this; + $("#node-input-tostatus").on('change',function() { + if ($(this).is(":checked")) { + if (!that.hasOwnProperty("statusVal") || that.statusVal === "") { + that.statusType = "msg"; + that.statusVal = (that.complete === "false") ? "payload" : ((that.complete === "true") ? "payload" : that.complete+""); + } + $("#node-input-typed-status").typedInput('type',that.statusType); + $("#node-input-typed-status").typedInput('value',that.statusVal); $("#node-tostatus-line").show(); } - }); - $("#node-input-complete").on('change',function() { - if ($("#node-input-typed-complete").typedInput('type') === 'full') { + else { $("#node-tostatus-line").hide(); - } else { - $("#node-tostatus-line").show(); + that.statusType = "msg"; + that.statusVal = ""; + $("#node-input-typed-status").typedInput('type',that.statusType); + $("#node-input-typed-status").typedInput('value',that.statusVal); } }); }, @@ -375,6 +395,7 @@ } else { $("#node-input-complete").val($("#node-input-typed-complete").typedInput('value')); } + $("#node-input-statusVal").val($("#node-input-typed-status").typedInput('value')); } }); })(); 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 b00371bbd..07d75378e 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 @@ -15,13 +15,17 @@ module.exports = function(RED) { this.complete = hasEditExpression ? null : (n.complete||"payload").toString(); if (this.complete === "false") { this.complete = "payload"; } this.console = ""+(n.console || false); - this.tostatus = (this.complete !== "true") && (n.tostatus || false); + this.tostatus = n.tostatus || false; + this.statusType = n.statusType || "msg"; + this.statusVal = n.statusVal || this.complete; this.tosidebar = n.tosidebar; if (this.tosidebar === undefined) { this.tosidebar = true; } this.severity = n.severity || 40; this.active = (n.active === null || typeof n.active === "undefined") || n.active; if (this.tostatus) { this.status({fill:"grey", shape:"ring"}); } else { this.status({}); } + var hasStatExpression = (n.statusType === "jsonata"); + var statExpression = hasStatExpression ? n.statusVal : null; var node = this; var levels = { @@ -45,6 +49,7 @@ module.exports = function(RED) { "60": "blue" }; var preparedEditExpression = null; + var preparedStatExpression = null; if (editExpression) { try { preparedEditExpression = RED.util.prepareJSONataExpression(editExpression, this); @@ -54,16 +59,22 @@ module.exports = function(RED) { return; } } + if (statExpression) { + try { + preparedStatExpression = RED.util.prepareJSONataExpression(statExpression, this); + } + catch (e) { + node.error(RED._("debug.invalid-exp", {error: editExpression})); + return; + } + } function prepareValue(msg, done) { // Either apply the jsonata expression or... if (preparedEditExpression) { RED.util.evaluateJSONataExpression(preparedEditExpression, msg, (err, value) => { - if (err) { - done(RED._("debug.invalid-exp", {error: editExpression})); - } else { - done(null,{id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:value}); - } + if (err) { done(RED._("debug.invalid-exp", {error: editExpression})); } + else { done(null,{id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:value}); } }); } else { // Extract the required message property @@ -71,17 +82,41 @@ module.exports = function(RED) { var output = msg[property]; if (node.complete !== "false" && typeof node.complete !== "undefined") { property = node.complete; - try { - output = RED.util.getMessageProperty(msg,node.complete); - } catch(err) { - output = undefined; - } + try { output = RED.util.getMessageProperty(msg,node.complete); } + catch(err) { output = undefined; } } done(null,{id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, property:property, msg:output}); } } + function prepareStatus(msg, done) { + // Either apply the jsonata expression or... + if (preparedStatExpression) { + RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => { + if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); } + else { done(null,{msg:value}); } + }); + } else { + // Extract the required message property + var output; + try { output = RED.util.getMessageProperty(msg,node.statusVal); } + catch(err) { output = undefined; } + done(null,{msg:output}); + } + } + this.on("input", function(msg, send, done) { + 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 severity = msg.errorlevel || node.severity; + if (st.length > 32) { st = st.substr(0,32) + "..."; } + node.status({fill:colors[severity] || "grey", shape:"dot", text:st}); + }); + } + if (this.complete === "true") { // debug complete msg object if (this.console === "true") { @@ -91,7 +126,8 @@ module.exports = function(RED) { sendDebug({id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:msg}); } done(); - } else { + } + else { prepareValue(msg,function(err,debugMsg) { if (err) { node.error(err); @@ -107,12 +143,6 @@ module.exports = function(RED) { node.log(util.inspect(output, {colors:useColors})); } } - if (node.tostatus === true) { - var st = (typeof output === 'string')?output:util.inspect(output); - var severity = node.severity; - if (st.length > 32) { st = st.substr(0,32) + "..."; } - node.status({fill:colors[severity], shape:"dot", text:st}); - } if (node.active) { if (node.tosidebar == true) { sendDebug(debugMsg); 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 73c09d0d1..76d1fcc3d 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 @@ -118,6 +118,7 @@ }, "debug": { "output": "Output", + "status": "status", "none": "None", "invalid-exp": "Invalid JSONata expression: __error__", "msgprop": "message property", From a849872c21be95f906a79fef4efc3b2d6e35ae78 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Thu, 14 May 2020 16:28:38 +0100 Subject: [PATCH 2/6] ensure old config work with new fields --- .../@node-red/nodes/core/common/21-debug.html | 21 +++++++++++++------ 1 file changed, 15 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 20772c0de..b1ff33baf 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 @@ -318,6 +318,12 @@ delete RED._debug; }, oneditprepare: function() { + $("#node-input-typed-status").typedInput({ + default: "msg", + types:['msg',"jsonata"], + typeField: $("#node-input-statusType") + }); + var that = this; var none = { value: "none", label: RED._("node-red:debug.none"), @@ -327,6 +333,14 @@ this.tosidebar = true; $("#node-input-tosidebar").prop('checked', true); } + if (this.statusVal === undefined) { + this.statusVal = (this.complete === "false") ? "payload" : ((this.complete === "true") ? "payload" : this.complete+""); + $("#node-input-typed-status").typedInput('value',this.statusVal || ""); + } + if (this.statusType === undefined) { + this.statusType = this.targetType; + $("#node-input-typed-status").typedInput('type',this.statusType || "msg"); + } if (typeof this.console === "string") { this.console = (this.console == 'true'); $("#node-input-console").prop('checked', this.console); @@ -363,12 +377,7 @@ } }); - $("#node-input-typed-status").typedInput({ - default: "msg", - types:['msg',"jsonata"], - typeField: $("#node-input-statusType") - }); - var that = this; + $("#node-input-tostatus").on('change',function() { if ($(this).is(":checked")) { if (!that.hasOwnProperty("statusVal") || that.statusVal === "") { From 184d928cf7a1af916b947472cb606e5a949a4d3a Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Thu, 14 May 2020 23:01:26 +0100 Subject: [PATCH 3/6] ensure debug status in sync with main option --- .../@node-red/nodes/core/common/21-debug.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 b1ff33baf..c4640c66a 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 @@ -377,12 +377,16 @@ } }); - $("#node-input-tostatus").on('change',function() { if ($(this).is(":checked")) { if (!that.hasOwnProperty("statusVal") || that.statusVal === "") { - that.statusType = "msg"; - that.statusVal = (that.complete === "false") ? "payload" : ((that.complete === "true") ? "payload" : that.complete+""); + var type = $("#node-input-typed-complete").typedInput('type'); + var comp = "payload"; + if (type !== 'full') { + comp = $("#node-input-typed-complete").typedInput('value'); + } + that.statusType = (type !== "jsonata") ? "msg" : "jsonata"; + that.statusVal = comp; } $("#node-input-typed-status").typedInput('type',that.statusType); $("#node-input-typed-status").typedInput('value',that.statusVal); From 88d4d306f38b438fe6ef962f9f65f4585f13ced5 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 15 May 2020 16:06:34 +0100 Subject: [PATCH 4/6] Add some colour smarts to debug status --- .../@node-red/nodes/core/common/21-debug.js | 35 ++++++------------- 1 file changed, 10 insertions(+), 25 deletions(-) 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 07d75378e..8de1a1307 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 @@ -2,7 +2,7 @@ module.exports = function(RED) { "use strict"; var util = require("util"); var events = require("events"); - var path = require("path"); + //var path = require("path"); var debuglength = RED.settings.debugMaxLength || 1000; var useColors = RED.settings.debugUseColors || false; util.inspect.styles.boolean = "red"; @@ -20,7 +20,6 @@ module.exports = function(RED) { this.statusVal = n.statusVal || this.complete; this.tosidebar = n.tosidebar; if (this.tosidebar === undefined) { this.tosidebar = true; } - this.severity = n.severity || 40; this.active = (n.active === null || typeof n.active === "undefined") || n.active; if (this.tostatus) { this.status({fill:"grey", shape:"ring"}); } else { this.status({}); } @@ -28,26 +27,6 @@ module.exports = function(RED) { var statExpression = hasStatExpression ? n.statusVal : null; var node = this; - var levels = { - off: 1, - fatal: 10, - error: 20, - warn: 30, - info: 40, - debug: 50, - trace: 60, - audit: 98, - metric: 99 - }; - var colors = { - "0": "grey", - "10": "grey", - "20": "red", - "30": "yellow", - "40": "grey", - "50": "green", - "60": "blue" - }; var preparedEditExpression = null; var preparedStatExpression = null; if (editExpression) { @@ -107,13 +86,19 @@ module.exports = function(RED) { this.on("input", function(msg, send, done) { if (node.tostatus === true) { - prepareStatus(msg,function(err,debugMsg) { + 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 severity = msg.errorlevel || node.severity; if (st.length > 32) { st = st.substr(0,32) + "..."; } - node.status({fill:colors[severity] || "grey", shape:"dot", text:st}); + var fill = "grey"; + var shape = "dot"; + if (node.statusVal === "error.message" && msg.hasOwnProperty("error")) { fill = "red"; } + if (node.statusVal === "status.text" && msg.hasOwnProperty("status")) { + if (msg.status.hasOwnProperty("fill")) { fill = msg.status.fill; } + if (msg.status.hasOwnProperty("shape")) { shape = msg.status.shape; } + } + node.status({fill:fill, shape:shape, text:st}); }); } From 1d36ce0fdf16f2de4d46ae67be1cd7d27a1d0e2c Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 15 May 2020 23:32:27 +0100 Subject: [PATCH 5/6] debug node: add auto handling of error and status msgs if set to show status --- .../@node-red/nodes/core/common/21-debug.html | 17 +++--- .../@node-red/nodes/core/common/21-debug.js | 52 +++++++++++++------ .../nodes/locales/en-US/messages.json | 1 + 3 files changed, 48 insertions(+), 22 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 c4640c66a..36ff0dc11 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 @@ -52,7 +52,7 @@ complete: {value:"false", required:true}, targetType: {value:undefined}, statusVal: {value:""}, - statusType: {value:"msg"} + statusType: {value:"auto"} }, label: function() { var suffix = ""; @@ -318,9 +318,14 @@ delete RED._debug; }, oneditprepare: function() { + var autoType = { + value: "auto", + label: RED._("node-red:debug.autostatus"), + hasValue: false + }; $("#node-input-typed-status").typedInput({ - default: "msg", - types:['msg',"jsonata"], + default: "auto", + types:[autoType, "msg", "jsonata"], typeField: $("#node-input-statusType") }); var that = this; @@ -339,7 +344,7 @@ } if (this.statusType === undefined) { this.statusType = this.targetType; - $("#node-input-typed-status").typedInput('type',this.statusType || "msg"); + $("#node-input-typed-status").typedInput('type',this.statusType || "auto"); } if (typeof this.console === "string") { this.console = (this.console == 'true'); @@ -385,7 +390,7 @@ if (type !== 'full') { comp = $("#node-input-typed-complete").typedInput('value'); } - that.statusType = (type !== "jsonata") ? "msg" : "jsonata"; + that.statusType = "auto"; that.statusVal = comp; } $("#node-input-typed-status").typedInput('type',that.statusType); @@ -394,7 +399,7 @@ } else { $("#node-tostatus-line").hide(); - that.statusType = "msg"; + that.statusType = "auto"; that.statusVal = ""; $("#node-input-typed-status").typedInput('type',that.statusType); $("#node-input-typed-status").typedInput('value',that.statusVal); 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 8de1a1307..397b3a30c 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 @@ -69,18 +69,32 @@ module.exports = function(RED) { } function prepareStatus(msg, done) { - // Either apply the jsonata expression or... - if (preparedStatExpression) { - RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => { - if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); } - else { done(null,{msg:value}); } - }); - } else { - // Extract the required message property - var output; - try { output = RED.util.getMessageProperty(msg,node.statusVal); } - catch(err) { output = undefined; } - done(null,{msg:output}); + if (node.statusType === "auto") { + if (node.complete === "true") { + done(null,{msg:msg.payload}); + } + else { + prepareValue(msg,function(err,debugMsg) { + if (err) { node.error(err); return; } + done(null,{msg:debugMsg.msg}); + }); + } + } + else { + // Either apply the jsonata expression or... + if (preparedStatExpression) { + RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => { + if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); } + else { done(null,{msg:value}); } + }); + } + else { + // Extract the required message property + var output; + try { output = RED.util.getMessageProperty(msg,node.statusVal); } + catch(err) { output = undefined; } + done(null,{msg:output}); + } } } @@ -93,10 +107,16 @@ module.exports = function(RED) { if (st.length > 32) { st = st.substr(0,32) + "..."; } var fill = "grey"; var shape = "dot"; - if (node.statusVal === "error.message" && msg.hasOwnProperty("error")) { fill = "red"; } - if (node.statusVal === "status.text" && msg.hasOwnProperty("status")) { - if (msg.status.hasOwnProperty("fill")) { fill = msg.status.fill; } - if (msg.status.hasOwnProperty("shape")) { shape = msg.status.shape; } + if (node.statusType === "auto") { + if (msg.hasOwnProperty("error")) { + fill = "red"; + st = msg.error.message; + } + if (msg.hasOwnProperty("status")) { + if (msg.status.hasOwnProperty("fill")) { fill = msg.status.fill; } + if (msg.status.hasOwnProperty("shape")) { shape = msg.status.shape; } + if (msg.status.hasOwnProperty("text")) { st = msg.status.text; } + } } node.status({fill:fill, shape:shape, text:st}); }); 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 76d1fcc3d..c2f85fcad 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 @@ -123,6 +123,7 @@ "invalid-exp": "Invalid JSONata expression: __error__", "msgprop": "message property", "msgobj": "complete msg object", + "autostatus": "automatic", "to": "To", "debtab": "debug tab", "tabcon": "debug tab and console", From a600feb5dea3ea5b2a8a827e8782118d3d718663 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 19 May 2020 10:57:33 +0100 Subject: [PATCH 6/6] Move debug status text length check to just before dsiplay. --- packages/node_modules/@node-red/nodes/core/common/21-debug.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 397b3a30c..c3566faa6 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 @@ -104,7 +104,6 @@ module.exports = function(RED) { if (err) { node.error(err); return; } var output = debugMsg.msg; var st = (typeof output === 'string') ? output : util.inspect(output); - if (st.length > 32) { st = st.substr(0,32) + "..."; } var fill = "grey"; var shape = "dot"; if (node.statusType === "auto") { @@ -118,6 +117,7 @@ module.exports = function(RED) { if (msg.status.hasOwnProperty("text")) { st = msg.status.text; } } } + if (st.length > 32) { st = st.substr(0,32) + "..."; } node.status({fill:fill, shape:shape, text:st}); }); }