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" } } }