From 78972a68abbe47ab38d377ac6164b6d1d7bf4392 Mon Sep 17 00:00:00 2001 From: zinen Date: Thu, 15 Aug 2019 23:03:13 +0200 Subject: [PATCH] Tail node add input filename (#557) * Allow input Added input point, removed requirement for data on data point 'filename' and added help text for new input parameter. * Added filename parameter as an input Handling of input msg add for parameter 'filename'. Monitoring will stop if no filename is defined either at the node level or as an input. * Added 'state' to locale Messages for node state added for en_US language * Replaced messages with pointers to locale file * Typo fixed * Made inputs dynamic Input bullet only available if filename is empty --- storage/tail/28-tail.html | 21 ++++++++++++++++--- storage/tail/28-tail.js | 27 +++++++++++++++++++++++-- storage/tail/locales/en-US/28-tail.json | 5 +++++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/storage/tail/28-tail.html b/storage/tail/28-tail.html index 08a5014c..80c50fb0 100644 --- a/storage/tail/28-tail.html +++ b/storage/tail/28-tail.html @@ -27,6 +27,12 @@ diff --git a/storage/tail/28-tail.js b/storage/tail/28-tail.js index 959b9457..d1c4ba7d 100644 --- a/storage/tail/28-tail.js +++ b/storage/tail/28-tail.js @@ -7,7 +7,7 @@ module.exports = function(RED) { function TailNode(n) { RED.nodes.createNode(this,n); - this.filename = n.filename; + this.filename = n.filename || ""; this.filetype = n.filetype || "text"; this.split = new RegExp(n.split.replace(/\\r/g,'\r').replace(/\\n/g,'\n').replace(/\\t/g,'\t') || "[\r]{0,1}\n"); var node = this; @@ -37,6 +37,7 @@ module.exports = function(RED) { }); node.tail.on("error", function(err) { + node.status({ fill: "red",shape:"ring", text: "node-red:common.status.error" }); node.error(err.toString()); }); } @@ -46,7 +47,29 @@ module.exports = function(RED) { } } - fileTail(); + if (node.filename !== "") { + node.status({}); + fileTail(); + } else { + node.status({ fill: "grey", text: "tail.state.stopped" }); + node.on('input', function (msg) { + if (!msg.hasOwnProperty("filename")) { + node.error(RED._("tail.state.nofilename")); + }else if (msg.filename === node.filename) { + node.warn(RED._("tail.state.nofilechange")); + } else if (msg.filename === "") { + node.filename = ""; + if (node.tail) { node.tail.unwatch(); } + if (node.tout) { clearTimeout(node.tout); } + node.status({ fill: "grey", text: "tail.state.stopped" }); + } else { + node.filename = msg.filename; + if (node.tail) { node.tail.unwatch(); } + if (!node.tout) { fileTail(); } + node.status({ fill: "green", text: node.filename }); + } + }); + } node.on("close", function() { /* istanbul ignore else */ diff --git a/storage/tail/locales/en-US/28-tail.json b/storage/tail/locales/en-US/28-tail.json index dd2da852..6146a650 100644 --- a/storage/tail/locales/en-US/28-tail.json +++ b/storage/tail/locales/en-US/28-tail.json @@ -15,6 +15,11 @@ "errors": { "windowsnotsupport": "Not currently supported on Windows.", "filenotfound": "File not found" + }, + "state":{ + "stopped": "stopped", + "nofilename":"Missing filename on input", + "nofilechange":"No change of filename input" } } }