From c2434814329429004d89bcb549393b4120910fa2 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 25 Jun 2018 10:38:34 +0100 Subject: [PATCH] Add sub options to Inject node --- editor/js/ui/common/typedInput.js | 34 +++++++++++++++++++++++++++++-- nodes/core/core/20-inject.html | 11 ++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/editor/js/ui/common/typedInput.js b/editor/js/ui/common/typedInput.js index 0f9e2a0d9..27c11e108 100644 --- a/editor/js/ui/common/typedInput.js +++ b/editor/js/ui/common/typedInput.js @@ -14,10 +14,40 @@ * limitations under the License. **/ (function($) { + var contextParse = function(v) { + var parts = {}; + var m = /^#:\((\S+?)\)::(.*)$/.exec(v); + if (m) { + parts.option = m[1]; + parts.value = m[2]; + } else { + parts.value = v; + } + return parts; + } + var contextExport = function(v,opt) { + return "#:("+((typeof opt === "string")?opt:opt.value)+")::"+v; + } var allOptions = { msg: {value:"msg",label:"msg.",validate:RED.utils.validatePropertyExpression}, - flow: {value:"flow",label:"flow.",validate:RED.utils.validatePropertyExpression}, - global: {value:"global",label:"global.",validate:RED.utils.validatePropertyExpression}, + flow: {value:"flow",label:"flow.",hasValue:true, + options:[ + {value:"memory",label: "memory", icon:''}//, + // {value:"redis",label:"redis",icon:''} + ], + validate:RED.utils.validatePropertyExpression, + parse: contextParse, + export: contextExport + }, + global: {value:"global",label:"global.",hasValue:true, + options:[ + {value:"memory",label: "memory", icon:''}, + {value:"redis",label:"redis",icon:''} + ], + validate:RED.utils.validatePropertyExpression, + parse: contextParse, + export: contextExport + }, str: {value:"str",label:"string",icon:"red/images/typedInput/az.png"}, num: {value:"num",label:"number",icon:"red/images/typedInput/09.png",validate:/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/}, bool: {value:"bool",label:"boolean",icon:"red/images/typedInput/bool.png",options:["true","false"]}, diff --git a/nodes/core/core/20-inject.html b/nodes/core/core/20-inject.html index 6f8ebcf69..87bb807c6 100644 --- a/nodes/core/core/20-inject.html +++ b/nodes/core/core/20-inject.html @@ -237,10 +237,13 @@ If you want every 20 minutes from now - use the "interval" option.

} else { return this._("inject.timestamp")+suffix; } - } else if (this.payloadType === 'flow' && this.payload.length < 19) { - return 'flow.'+this.payload+suffix; - } else if (this.payloadType === 'global' && this.payload.length < 17) { - return 'global.'+this.payload+suffix; + } else if (this.payloadType === 'flow' || this.payloadType === 'global') { + var key = this.payload; + var m = /^#:\((\S+?)\)::(.*)$/.exec(key); + if (m) { + key = m[2]; + } + return 'flow.'+key+suffix; } else { return this._("inject.inject")+suffix; }