Merge pull request #3551 from node-red/pr_3544

Add message count option to Debug status
This commit is contained in:
Nick O'Leary 2022-04-26 16:25:01 +01:00 committed by GitHub
commit e8f20285af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 34 deletions

View File

@ -453,9 +453,16 @@
label: RED._("node-red:debug.autostatus"), label: RED._("node-red:debug.autostatus"),
hasValue: false hasValue: false
}; };
var counter = {
value: "counter",
label: RED._("node-red:debug.messageCount"),
hasValue: false
};
$("#node-input-typed-status").typedInput({ $("#node-input-typed-status").typedInput({
default: "auto", default: "auto",
types:[autoType, "msg", "jsonata"], types:[autoType, "msg", "jsonata", counter],
typeField: $("#node-input-statusType") typeField: $("#node-input-statusType")
}); });
var that = this; var that = this;
@ -492,7 +499,7 @@
types:['msg', fullType, "jsonata"], types:['msg', fullType, "jsonata"],
typeField: $("#node-input-targetType") typeField: $("#node-input-targetType")
}); });
if (this.targetType === "jsonata") { if (this.targetType === "jsonata") {
var property = this.complete || ""; var property = this.complete || "";
$("#node-input-typed-complete").typedInput('type','jsonata'); $("#node-input-typed-complete").typedInput('type','jsonata');
$("#node-input-typed-complete").typedInput('value',property); $("#node-input-typed-complete").typedInput('value',property);
@ -514,12 +521,16 @@
$("#node-input-tostatus").on('change',function() { $("#node-input-tostatus").on('change',function() {
if ($(this).is(":checked")) { 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 type = $("#node-input-typed-complete").typedInput('type');
var comp = "payload"; var comp = "payload";
if (type !== 'full') { if (type !== 'full') {
comp = $("#node-input-typed-complete").typedInput('value'); comp = $("#node-input-typed-complete").typedInput('value');
} }
console.log('hihi')
that.statusType = "auto"; that.statusType = "auto";
that.statusVal = comp; that.statusVal = comp;
} }

View File

@ -21,6 +21,9 @@ module.exports = function(RED) {
this.statusType = n.statusType || "auto"; this.statusType = n.statusType || "auto";
this.statusVal = n.statusVal || this.complete; this.statusVal = n.statusVal || this.complete;
this.tosidebar = n.tosidebar; this.tosidebar = n.tosidebar;
this.counter = 0;
this.lastTime = new Date().getTime();
this.timeout = null;
if (this.tosidebar === undefined) { this.tosidebar = true; } if (this.tosidebar === undefined) { this.tosidebar = true; }
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) { if (this.tostatus) {
@ -32,6 +35,12 @@ module.exports = function(RED) {
var statExpression = hasStatExpression ? n.statusVal : null; var statExpression = hasStatExpression ? n.statusVal : null;
var node = this; 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 preparedEditExpression = null;
var preparedStatExpression = null; var preparedStatExpression = null;
if (editExpression) { if (editExpression) {
@ -106,46 +115,64 @@ module.exports = function(RED) {
if (this.oldState) { if (this.oldState) {
this.status({}); this.status({});
} }
if (this.timeout) {
clearTimeout(this.timeout)
}
}) })
this.on("input", function(msg, send, done) { this.on("input", function(msg, send, done) {
if (hasOwnProperty.call(msg, "status") && msg.status && if (hasOwnProperty.call(msg, "status") && hasOwnProperty.call(msg.status, "source") && hasOwnProperty.call(msg.status.source, "id") && (msg.status.source.id === node.id)) {
hasOwnProperty.call(msg.status, "source") && msg.status.source &&
hasOwnProperty.call(msg.status.source, "id") && (msg.status.source.id === node.id)) {
done(); done();
return; return;
} }
if (node.tostatus === true) { if (node.tostatus === true) {
prepareStatus(msg, function(err,debugMsg) { if ( node.statusType === "counter" ){
if (err) { node.error(err); return; } const differenceOfTime = (new Date().getTime() - node.lastTime);
var output = debugMsg.msg; node.lastTime = new Date().getTime();
var st = (typeof output === 'string') ? output : util.inspect(output); node.counter++;
var fill = "grey"; if ( differenceOfTime > 100 ){
var shape = "dot"; node.status({fill:"blue", shape:"ring", text: node.counter});
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") { else {
if (hasOwnProperty.call(msg, "error")) { if (node.timeout) {
fill = "red"; clearTimeout(node.timeout)
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 || "";
} }
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 var newStatus = {fill:fill, shape:shape, text:st};
node.status(newStatus); if (JSON.stringify(newStatus) !== node.oldState) { // only send if we have to
node.oldState = JSON.stringify(newStatus); node.status(newStatus);
} node.oldState = JSON.stringify(newStatus);
}); }
});
}
} }
if (this.complete === "true") { if (this.complete === "true") {
@ -288,7 +315,7 @@ module.exports = function(RED) {
res.sendFile( res.sendFile(
req.params[0], req.params[0],
options, options,
err => { err => {
if (err) { if (err) {
res.sendStatus(404); res.sendStatus(404);
} }

View File

@ -129,6 +129,7 @@
"msgprop": "message property", "msgprop": "message property",
"msgobj": "complete msg object", "msgobj": "complete msg object",
"autostatus": "same as debug output", "autostatus": "same as debug output",
"messageCount": "message count",
"to": "To", "to": "To",
"debtab": "debug tab", "debtab": "debug tab",
"tabcon": "debug tab and console", "tabcon": "debug tab and console",