1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Load typedinput context list from settings

This commit is contained in:
Nick O'Leary 2018-07-03 21:17:15 +01:00
parent c243481432
commit 33b4774c49
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -22,28 +22,28 @@
parts.value = m[2]; parts.value = m[2];
} else { } else {
parts.value = v; parts.value = v;
parts.option = RED.settings.context.default;
} }
return parts; return parts;
} }
var contextExport = function(v,opt) { var contextExport = function(v,opt) {
return "#:("+((typeof opt === "string")?opt:opt.value)+")::"+v; var store = ((typeof opt === "string")?opt:opt.value)
if (store !== RED.settings.context.default) {
return "#:("+store+")::"+v;
} else {
return v;
}
} }
var allOptions = { var allOptions = {
msg: {value:"msg",label:"msg.",validate:RED.utils.validatePropertyExpression}, msg: {value:"msg",label:"msg.",validate:RED.utils.validatePropertyExpression},
flow: {value:"flow",label:"flow.",hasValue:true, flow: {value:"flow",label:"flow.",hasValue:true,
options:[ options:[],
{value:"memory",label: "memory", icon:'<i class="red-ui-typedInput-icon fa fa-database" style="color: #ddd"></i>'}//,
// {value:"redis",label:"redis",icon:'<i class="red-ui-typedInput-icon fa fa-database" style="color: #777"></i>'}
],
validate:RED.utils.validatePropertyExpression, validate:RED.utils.validatePropertyExpression,
parse: contextParse, parse: contextParse,
export: contextExport export: contextExport
}, },
global: {value:"global",label:"global.",hasValue:true, global: {value:"global",label:"global.",hasValue:true,
options:[ options:[],
{value:"memory",label: "memory", icon:'<i class="red-ui-typedInput-icon fa fa-database" style="color: #ddd"></i>'},
{value:"redis",label:"redis",icon:'<i class="red-ui-typedInput-icon fa fa-database" style="color: #777"></i>'}
],
validate:RED.utils.validatePropertyExpression, validate:RED.utils.validatePropertyExpression,
parse: contextParse, parse: contextParse,
export: contextExport export: contextExport
@ -117,12 +117,19 @@
$.widget( "nodered.typedInput", { $.widget( "nodered.typedInput", {
_create: function() { _create: function() {
try {
if (!nlsd && RED && RED._) { if (!nlsd && RED && RED._) {
for (var i in allOptions) { for (var i in allOptions) {
if (allOptions.hasOwnProperty(i)) { if (allOptions.hasOwnProperty(i)) {
allOptions[i].label = RED._("typedInput.type."+i,{defaultValue:allOptions[i].label}); allOptions[i].label = RED._("typedInput.type."+i,{defaultValue:allOptions[i].label});
} }
} }
var contextStores = RED.settings.context.stores;
var contextOptions = contextStores.map(function(store) {
return {value:store,label: store, icon:'<i class="red-ui-typedInput-icon fa fa-database" style="color: #'+(store==='memory'?'ddd':'777')+'"></i>'}
})
allOptions.flow.options = contextOptions;
allOptions.global.options = contextOptions;
} }
nlsd = true; nlsd = true;
var that = this; var that = this;
@ -200,6 +207,9 @@
// explicitly set optionSelectTrigger display to inline-block otherwise jQ sets it to 'inline' // explicitly set optionSelectTrigger display to inline-block otherwise jQ sets it to 'inline'
this.optionSelectTrigger = $('<button tabindex="0" class="red-ui-typedInput-option-trigger" style="display:inline-block"><span class="red-ui-typedInput-option-caret"><i class="red-ui-typedInput-icon fa fa-sort-desc"></i></span></button>').appendTo(this.uiSelect); this.optionSelectTrigger = $('<button tabindex="0" class="red-ui-typedInput-option-trigger" style="display:inline-block"><span class="red-ui-typedInput-option-caret"><i class="red-ui-typedInput-icon fa fa-sort-desc"></i></span></button>').appendTo(this.uiSelect);
this.optionSelectLabel = $('<span class="red-ui-typedInput-option-label"></span>').prependTo(this.optionSelectTrigger); this.optionSelectLabel = $('<span class="red-ui-typedInput-option-label"></span>').prependTo(this.optionSelectTrigger);
RED.popover.tooltip(this.optionSelectLabel,function() {
return that.optionValue;
});
this.optionSelectTrigger.click(function(event) { this.optionSelectTrigger.click(function(event) {
event.preventDefault(); event.preventDefault();
that._showOptionSelectMenu(); that._showOptionSelectMenu();
@ -216,6 +226,9 @@
this.optionExpandButton = $('<button tabindex="0" class="red-ui-typedInput-option-expand" style="display:inline-block"><i class="red-ui-typedInput-icon fa fa-ellipsis-h"></i></button>').appendTo(this.uiSelect); this.optionExpandButton = $('<button tabindex="0" class="red-ui-typedInput-option-expand" style="display:inline-block"><i class="red-ui-typedInput-icon fa fa-ellipsis-h"></i></button>').appendTo(this.uiSelect);
this.type(this.options.default||this.typeList[0].value); this.type(this.options.default||this.typeList[0].value);
}catch(err) {
console.log(err.stack);
}
}, },
_showTypeMenu: function() { _showTypeMenu: function() {
if (this.typeList.length > 1) { if (this.typeList.length > 1) {
@ -578,6 +591,9 @@
if (typeof selectedOption === "string") { if (typeof selectedOption === "string") {
this.optionValue = selectedOption; this.optionValue = selectedOption;
if (!this.activeOptions.hasOwnProperty(selectedOption)) {
selectedOption = Object.keys(this.activeOptions)[0];
}
this._updateOptionSelectLabel(this.activeOptions[selectedOption]); this._updateOptionSelectLabel(this.activeOptions[selectedOption]);
} else { } else {
this.optionValue = selectedOption.value; this.optionValue = selectedOption.value;