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

Merge pull request #2564 from node-red/debugStatus

Let debug node show status indpendent of main output
This commit is contained in:
Nick O'Leary 2020-05-19 14:41:52 +01:00 committed by GitHub
commit 03b64bc493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 131 additions and 55 deletions

View File

@ -6,24 +6,29 @@
<input id="node-input-complete" type="hidden"> <input id="node-input-complete" type="hidden">
<input id="node-input-targetType" type="hidden"> <input id="node-input-targetType" type="hidden">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-tosidebar"><i class="fa fa-random"></i> <span data-i18n="debug.to"></span></label> <label for="node-input-tosidebar"><i class="fa fa-random"></i> <span data-i18n="debug.to"></span></label>
<label for="node-input-tosidebar" style="width:70%"> <label for="node-input-tosidebar" style="width:70%">
<input type="checkbox" id="node-input-tosidebar" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="debug.toSidebar"></span> <input type="checkbox" id="node-input-tosidebar" style="display:inline-block; width:22px; vertical-align:top;"><span data-i18n="debug.toSidebar"></span>
</label> </label>
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-console"> </label> <label for="node-input-console"> </label>
<label for="node-input-console" style="width:70%"> <label for="node-input-console" style="width:70%">
<input type="checkbox" id="node-input-console" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="debug.toConsole"></span> <input type="checkbox" id="node-input-console" style="display:inline-block; width:22px; vertical-align:top;"><span data-i18n="debug.toConsole"></span>
</label>
</div>
<div class="form-row">
<label for="node-input-tostatus"> </label>
<label for="node-input-tostatus" style="width:70%">
<input type="checkbox" id="node-input-tostatus" style="display:inline-block; width:22px; vertical-align:top;"><span data-i18n="debug.toStatus"></span>
</label> </label>
</div> </div>
<div class="form-row" id="node-tostatus-line"> <div class="form-row" id="node-tostatus-line">
<label for="node-input-tostatus"> </label> <label for="node-input-typed-status"><i class="fa fa-ellipsis-h"></i> <span data-i18n="debug.status"></span></label>
<label for="node-input-tostatus" style="width:70%"> <input id="node-input-typed-status" type="text" style="width: 70%">
<input type="checkbox" id="node-input-tostatus" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="debug.toStatus"></span> <input id="node-input-statusVal" type="hidden">
</label> <input id="node-input-statusType" type="hidden">
</div> </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>
@ -45,7 +50,9 @@
console: {value:false}, console: {value:false},
tostatus: {value:false}, tostatus: {value:false},
complete: {value:"false", required:true}, complete: {value:"false", required:true},
targetType: {value:undefined} targetType: {value:undefined},
statusVal: {value:""},
statusType: {value:"auto"}
}, },
label: function() { label: function() {
var suffix = ""; var suffix = "";
@ -308,10 +315,20 @@
window.removeEventListener("message",this.handleWindowMessage); window.removeEventListener("message",this.handleWindowMessage);
RED.actions.remove("core:show-debug-tab"); RED.actions.remove("core:show-debug-tab");
RED.actions.remove("core:clear-debug-messages"); RED.actions.remove("core:clear-debug-messages");
delete RED._debug; delete RED._debug;
}, },
oneditprepare: function() { oneditprepare: function() {
var autoType = {
value: "auto",
label: RED._("node-red:debug.autostatus"),
hasValue: false
};
$("#node-input-typed-status").typedInput({
default: "auto",
types:[autoType, "msg", "jsonata"],
typeField: $("#node-input-statusType")
});
var that = this;
var none = { var none = {
value: "none", value: "none",
label: RED._("node-red:debug.none"), label: RED._("node-red:debug.none"),
@ -321,6 +338,14 @@
this.tosidebar = true; this.tosidebar = true;
$("#node-input-tosidebar").prop('checked', 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 || "auto");
}
if (typeof this.console === "string") { if (typeof this.console === "string") {
this.console = (this.console == 'true'); this.console = (this.console == 'true');
$("#node-input-console").prop('checked', this.console); $("#node-input-console").prop('checked', this.console);
@ -331,6 +356,7 @@
label: RED._("node-red:debug.msgobj"), label: RED._("node-red:debug.msgobj"),
hasValue: false hasValue: false
}; };
$("#node-input-typed-complete").typedInput({ $("#node-input-typed-complete").typedInput({
default: "msg", default: "msg",
types:['msg', fullType, "jsonata"], types:['msg', fullType, "jsonata"],
@ -354,17 +380,29 @@
) { ) {
$("#node-input-typed-complete").typedInput('value','payload'); $("#node-input-typed-complete").typedInput('value','payload');
} }
if ($("#node-input-typed-complete").typedInput('type') === 'full') { });
$("#node-tostatus-line").hide();
} else { $("#node-input-tostatus").on('change',function() {
if ($(this).is(":checked")) {
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');
}
that.statusType = "auto";
that.statusVal = comp;
}
$("#node-input-typed-status").typedInput('type',that.statusType);
$("#node-input-typed-status").typedInput('value',that.statusVal);
$("#node-tostatus-line").show(); $("#node-tostatus-line").show();
} }
}); else {
$("#node-input-complete").on('change',function() {
if ($("#node-input-typed-complete").typedInput('type') === 'full') {
$("#node-tostatus-line").hide(); $("#node-tostatus-line").hide();
} else { that.statusType = "auto";
$("#node-tostatus-line").show(); that.statusVal = "";
$("#node-input-typed-status").typedInput('type',that.statusType);
$("#node-input-typed-status").typedInput('value',that.statusVal);
} }
}); });
}, },
@ -375,6 +413,7 @@
} else { } else {
$("#node-input-complete").val($("#node-input-typed-complete").typedInput('value')); $("#node-input-complete").val($("#node-input-typed-complete").typedInput('value'));
} }
$("#node-input-statusVal").val($("#node-input-typed-status").typedInput('value'));
} }
}); });
})(); })();

View File

@ -2,7 +2,7 @@ module.exports = function(RED) {
"use strict"; "use strict";
var util = require("util"); var util = require("util");
var events = require("events"); var events = require("events");
var path = require("path"); //var path = require("path");
var debuglength = RED.settings.debugMaxLength || 1000; var debuglength = RED.settings.debugMaxLength || 1000;
var useColors = RED.settings.debugUseColors || false; var useColors = RED.settings.debugUseColors || false;
util.inspect.styles.boolean = "red"; util.inspect.styles.boolean = "red";
@ -15,36 +15,20 @@ module.exports = function(RED) {
this.complete = hasEditExpression ? null : (n.complete||"payload").toString(); this.complete = hasEditExpression ? null : (n.complete||"payload").toString();
if (this.complete === "false") { this.complete = "payload"; } if (this.complete === "false") { this.complete = "payload"; }
this.console = ""+(n.console || false); 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; this.tosidebar = n.tosidebar;
if (this.tosidebar === undefined) { this.tosidebar = true; } if (this.tosidebar === undefined) { this.tosidebar = true; }
this.severity = n.severity || 40;
this.active = (n.active === null || typeof n.active === "undefined") || n.active; this.active = (n.active === null || typeof n.active === "undefined") || n.active;
if (this.tostatus) { this.status({fill:"grey", shape:"ring"}); } if (this.tostatus) { this.status({fill:"grey", shape:"ring"}); }
else { this.status({}); } else { this.status({}); }
var hasStatExpression = (n.statusType === "jsonata");
var statExpression = hasStatExpression ? n.statusVal : null;
var node = this; 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 preparedEditExpression = null;
var preparedStatExpression = null;
if (editExpression) { if (editExpression) {
try { try {
preparedEditExpression = RED.util.prepareJSONataExpression(editExpression, this); preparedEditExpression = RED.util.prepareJSONataExpression(editExpression, this);
@ -54,16 +38,22 @@ module.exports = function(RED) {
return; 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) { function prepareValue(msg, done) {
// Either apply the jsonata expression or... // Either apply the jsonata expression or...
if (preparedEditExpression) { if (preparedEditExpression) {
RED.util.evaluateJSONataExpression(preparedEditExpression, msg, (err, value) => { RED.util.evaluateJSONataExpression(preparedEditExpression, msg, (err, value) => {
if (err) { if (err) { done(RED._("debug.invalid-exp", {error: editExpression})); }
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 {
done(null,{id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:value});
}
}); });
} else { } else {
// Extract the required message property // Extract the required message property
@ -71,17 +61,67 @@ module.exports = function(RED) {
var output = msg[property]; var output = msg[property];
if (node.complete !== "false" && typeof node.complete !== "undefined") { if (node.complete !== "false" && typeof node.complete !== "undefined") {
property = node.complete; property = node.complete;
try { try { output = RED.util.getMessageProperty(msg,node.complete); }
output = RED.util.getMessageProperty(msg,node.complete); catch(err) { output = undefined; }
} 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}); 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) {
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});
}
}
}
this.on("input", function(msg, send, done) { 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 fill = "grey";
var shape = "dot";
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; }
}
}
if (st.length > 32) { st = st.substr(0,32) + "..."; }
node.status({fill:fill, shape:shape, text:st});
});
}
if (this.complete === "true") { if (this.complete === "true") {
// debug complete msg object // debug complete msg object
if (this.console === "true") { if (this.console === "true") {
@ -91,7 +131,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}); sendDebug({id:node.id, z:node.z, _alias: node._alias, path:node._flow.path, name:node.name, topic:msg.topic, msg:msg});
} }
done(); done();
} else { }
else {
prepareValue(msg,function(err,debugMsg) { prepareValue(msg,function(err,debugMsg) {
if (err) { if (err) {
node.error(err); node.error(err);
@ -107,12 +148,6 @@ module.exports = function(RED) {
node.log(util.inspect(output, {colors:useColors})); 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.active) {
if (node.tosidebar == true) { if (node.tosidebar == true) {
sendDebug(debugMsg); sendDebug(debugMsg);

View File

@ -118,10 +118,12 @@
}, },
"debug": { "debug": {
"output": "Output", "output": "Output",
"status": "status",
"none": "None", "none": "None",
"invalid-exp": "Invalid JSONata expression: __error__", "invalid-exp": "Invalid JSONata expression: __error__",
"msgprop": "message property", "msgprop": "message property",
"msgobj": "complete msg object", "msgobj": "complete msg object",
"autostatus": "automatic",
"to": "To", "to": "To",
"debtab": "debug tab", "debtab": "debug tab",
"tabcon": "debug tab and console", "tabcon": "debug tab and console",