mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
implementing message count on the debug node
This commit is contained in:
parent
d802ce1484
commit
8924ac2783
@ -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: "message count",
|
||||||
|
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;
|
||||||
@ -514,12 +521,13 @@
|
|||||||
|
|
||||||
$("#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.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;
|
||||||
}
|
}
|
||||||
|
@ -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,11 @@ 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) {
|
||||||
@ -108,15 +116,27 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
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) {
|
prepareStatus(msg, function(err,debugMsg) {
|
||||||
if (err) { node.error(err); return; }
|
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)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
var output = debugMsg.msg;
|
var output = debugMsg.msg;
|
||||||
var st = (typeof output === 'string') ? output : util.inspect(output);
|
var st = (typeof output === 'string') ? output : util.inspect(output);
|
||||||
var fill = "grey";
|
var fill = "grey";
|
||||||
@ -131,8 +151,7 @@ module.exports = function(RED) {
|
|||||||
fill = "red";
|
fill = "red";
|
||||||
st = msg.error.message;
|
st = msg.error.message;
|
||||||
}
|
}
|
||||||
if (hasOwnProperty.call(msg, "status") &&
|
if (hasOwnProperty.call(msg, "status")) {
|
||||||
msg.status) {
|
|
||||||
fill = msg.status.fill || "grey";
|
fill = msg.status.fill || "grey";
|
||||||
shape = msg.status.shape || "ring";
|
shape = msg.status.shape || "ring";
|
||||||
st = msg.status.text || "";
|
st = msg.status.text || "";
|
||||||
@ -140,11 +159,14 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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};
|
var newStatus = {fill:fill, shape:shape, text:st};
|
||||||
if (JSON.stringify(newStatus) !== node.oldState) { // only send if we have to
|
if (JSON.stringify(newStatus) !== node.oldState) { // only send if we have to
|
||||||
node.status(newStatus);
|
node.status(newStatus);
|
||||||
node.oldState = JSON.stringify(newStatus);
|
node.oldState = JSON.stringify(newStatus);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user