From db8664236485d131cc8f5bfc68ed21bfa7ca0004 Mon Sep 17 00:00:00 2001 From: Pietro Brenna Date: Fri, 21 Feb 2020 13:45:44 +0100 Subject: [PATCH] Messaggio errore che esce dall'entry point --- command-parse.html | 11 +++++++---- command-parse.js | 14 ++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/command-parse.html b/command-parse.html index 31b7bd7..1bb136f 100644 --- a/command-parse.html +++ b/command-parse.html @@ -73,6 +73,9 @@ var label = ""; if (rule) { label = rule.v; + if (label == "") { + return "(empty)"; + } return label; } }, @@ -182,7 +185,7 @@ selectField.change(); var currentOutputs = JSON.parse(outputCount.val() || "{}"); - currentOutputs[opt.hasOwnProperty('i') ? opt.i : opt._i] = i + 1; + currentOutputs[opt.hasOwnProperty('i') ? opt.i : opt._i] = i; outputCount.val(JSON.stringify(currentOutputs)); }, removeItem: function (opt) { @@ -196,7 +199,7 @@ rules.each(function (i) { $(this).find(".node-input-rule-index").html(i + 1); var data = $(this).data('data'); - currentOutputs[data.hasOwnProperty('i') ? data.i : data._i] = i + 1; + currentOutputs[data.hasOwnProperty('i') ? data.i : data._i] = i; }); outputCount.val(JSON.stringify(currentOutputs)); }, @@ -263,7 +266,7 @@
- +
@@ -279,7 +282,7 @@ help_text: {value: ""} }, inputs: 1, - outputs: 1, + outputs: 2, label: function() { return this.name || "parser entry point"; } diff --git a/command-parse.js b/command-parse.js index 695242c..504245b 100644 --- a/command-parse.js +++ b/command-parse.js @@ -5,7 +5,7 @@ module.exports = function (RED) { function ParserEntryPoint(n) { RED.nodes.createNode(this, n); this.property = n.property; - this.help_message = n.help_message; + this.help_text = n.help_text; this.on("input", msg => { RED.util.evaluateNodeProperty(this.property, "msg", this, msg, (err, value) => { @@ -16,9 +16,13 @@ module.exports = function (RED) { msg.token_parser = { new_tokens: tokens, consumed_tokens: [], - help_message: this.help_message + help_message: this.help_text, + on_error: (maybe_error) => { + let err = maybe_error ? maybe_error : this.help_text; + this.send([undefined, err]); + } }; - this.send(msg); + this.send([msg, undefined]); }; }); }); @@ -56,7 +60,9 @@ module.exports = function (RED) { out.push(undefined); } } - //out.push(n_matches == 0 ? msg : undefined); + if (n_matches == 0) { + msg.token_parser.on_error(); + } this.send(out); }); }