mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
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
This commit is contained in:
parent
e87c7947a8
commit
78972a68ab
@ -27,6 +27,12 @@
|
||||
<script type="text/x-red" data-help-name="tail">
|
||||
<p>Tails (watches for things to be added) to the configured file.</p>
|
||||
<p>Note: On Windows you may need to close the file between writes for any updates to be registered.</p>
|
||||
<h3>Input</h3>
|
||||
<dl class="message-properties">
|
||||
<dt class="optional">filename <span class="property-type">string</span></dt>
|
||||
<dd>If not configured in the node, this optional property sets the name of the file to be tailed.
|
||||
If an empty string <code>""</code> is received, the tailing will stop.</dd>
|
||||
</dl>
|
||||
<h3>Outputs</h3>
|
||||
<ul>
|
||||
<li>Text (UTF-8) files will be returned as strings.</li>
|
||||
@ -41,10 +47,11 @@
|
||||
name: {value:""},
|
||||
filetype: {value:"text"},
|
||||
split: {value:"[\\r]{0,1}\\n"},
|
||||
filename: {value:"",required:true}
|
||||
filename: {value:""},
|
||||
inputs: {value:1}
|
||||
},
|
||||
color:"BurlyWood",
|
||||
inputs:0,
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
icon: "file.png",
|
||||
label: function() {
|
||||
@ -58,6 +65,14 @@
|
||||
if (this.value === "text") { $("#node-tail-split").show(); }
|
||||
else { $("#node-tail-split").hide(); }
|
||||
});
|
||||
},
|
||||
oneditsave: function() {
|
||||
var that = this;
|
||||
if($("#node-input-filename").val()===""){
|
||||
that.inputs = 1;
|
||||
} else {
|
||||
that.inputs = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
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 */
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user