mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Fix context store handling in autocomplete
This commit is contained in:
parent
a007ab7f2e
commit
4a4a15de93
@ -46,12 +46,6 @@
|
|||||||
opacity: 0.3
|
opacity: 0.3
|
||||||
}).appendTo(container);
|
}).appendTo(container);
|
||||||
this.elementDiv.show();
|
this.elementDiv.show();
|
||||||
if (!this.input.hasClass('red-ui-autoComplete')) {
|
|
||||||
this.input.autoComplete({
|
|
||||||
search: contextAutoComplete({ input: that }),
|
|
||||||
minLength: 0
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var mapDeprecatedIcon = function(icon) {
|
var mapDeprecatedIcon = function(icon) {
|
||||||
if (/^red\/images\/typedInput\/.+\.png$/.test(icon)) {
|
if (/^red\/images\/typedInput\/.+\.png$/.test(icon)) {
|
||||||
@ -203,7 +197,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextAutoComplete = function(options) {
|
const contextAutoComplete = function() {
|
||||||
|
const that = this
|
||||||
const getContextKeysFromRuntime = function(scope, store, searchKey, done) {
|
const getContextKeysFromRuntime = function(scope, store, searchKey, done) {
|
||||||
contextKnownKeys[scope] = contextKnownKeys[scope] || {}
|
contextKnownKeys[scope] = contextKnownKeys[scope] || {}
|
||||||
contextKnownKeys[scope][store] = contextKnownKeys[scope][store] || new Set()
|
contextKnownKeys[scope][store] = contextKnownKeys[scope][store] || new Set()
|
||||||
@ -242,7 +237,7 @@
|
|||||||
const getContextKeys = function(key, done) {
|
const getContextKeys = function(key, done) {
|
||||||
const keyParts = key.split('.')
|
const keyParts = key.split('.')
|
||||||
const partialKey = keyParts.pop()
|
const partialKey = keyParts.pop()
|
||||||
let scope = options.input.propertyType
|
let scope = that.propertyType
|
||||||
if (scope === 'flow') {
|
if (scope === 'flow') {
|
||||||
// Get the flow id of the node we're editing
|
// Get the flow id of the node we're editing
|
||||||
const editStack = RED.editor.getEditStack()
|
const editStack = RED.editor.getEditStack()
|
||||||
@ -258,7 +253,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const store = options.input.optionValue
|
const store = (contextStoreOptions.length === 1) ? contextStoreOptions[0].value : that.optionValue
|
||||||
const searchKey = keyParts.join('.')
|
const searchKey = keyParts.join('.')
|
||||||
|
|
||||||
getContextKeysFromRuntime(scope, store, searchKey, function() {
|
getContextKeysFromRuntime(scope, store, searchKey, function() {
|
||||||
@ -369,14 +364,16 @@
|
|||||||
validate:RED.utils.validatePropertyExpression,
|
validate:RED.utils.validatePropertyExpression,
|
||||||
parse: contextParse,
|
parse: contextParse,
|
||||||
export: contextExport,
|
export: contextExport,
|
||||||
valueLabel: contextLabel
|
valueLabel: contextLabel,
|
||||||
|
autoComplete: contextAutoComplete
|
||||||
},
|
},
|
||||||
global: {value:"global",label:"global.",hasValue:true,
|
global: {value:"global",label:"global.",hasValue:true,
|
||||||
options:[],
|
options:[],
|
||||||
validate:RED.utils.validatePropertyExpression,
|
validate:RED.utils.validatePropertyExpression,
|
||||||
parse: contextParse,
|
parse: contextParse,
|
||||||
export: contextExport,
|
export: contextExport,
|
||||||
valueLabel: contextLabel
|
valueLabel: contextLabel,
|
||||||
|
autoComplete: contextAutoComplete
|
||||||
},
|
},
|
||||||
str: {value:"str",label:"string",icon:"red/images/typedInput/az.svg"},
|
str: {value:"str",label:"string",icon:"red/images/typedInput/az.svg"},
|
||||||
num: {value:"num",label:"number",icon:"red/images/typedInput/09.svg",validate: function(v) {
|
num: {value:"num",label:"number",icon:"red/images/typedInput/09.svg",validate: function(v) {
|
||||||
@ -625,6 +622,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var nlsd = false;
|
var nlsd = false;
|
||||||
|
let contextStoreOptions;
|
||||||
|
|
||||||
$.widget( "nodered.typedInput", {
|
$.widget( "nodered.typedInput", {
|
||||||
_create: function() {
|
_create: function() {
|
||||||
@ -636,7 +634,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var contextStores = RED.settings.context.stores;
|
var contextStores = RED.settings.context.stores;
|
||||||
var contextOptions = contextStores.map(function(store) {
|
contextStoreOptions = contextStores.map(function(store) {
|
||||||
return {value:store,label: store, icon:'<i class="red-ui-typedInput-icon fa fa-database"></i>'}
|
return {value:store,label: store, icon:'<i class="red-ui-typedInput-icon fa fa-database"></i>'}
|
||||||
}).sort(function(A,B) {
|
}).sort(function(A,B) {
|
||||||
if (A.value === RED.settings.context.default) {
|
if (A.value === RED.settings.context.default) {
|
||||||
@ -647,12 +645,12 @@
|
|||||||
return A.value.localeCompare(B.value);
|
return A.value.localeCompare(B.value);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (contextOptions.length < 2) {
|
if (contextStoreOptions.length < 2) {
|
||||||
allOptions.flow.options = [];
|
allOptions.flow.options = [];
|
||||||
allOptions.global.options = [];
|
allOptions.global.options = [];
|
||||||
} else {
|
} else {
|
||||||
allOptions.flow.options = contextOptions;
|
allOptions.flow.options = contextStoreOptions;
|
||||||
allOptions.global.options = contextOptions;
|
allOptions.global.options = contextStoreOptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nlsd = true;
|
nlsd = true;
|
||||||
@ -1344,6 +1342,16 @@
|
|||||||
} else {
|
} else {
|
||||||
this.optionSelectTrigger.hide();
|
this.optionSelectTrigger.hide();
|
||||||
}
|
}
|
||||||
|
if (opt.autoComplete) {
|
||||||
|
let searchFunction = opt.autoComplete
|
||||||
|
if (searchFunction.length === 0) {
|
||||||
|
searchFunction = opt.autoComplete.call(this)
|
||||||
|
}
|
||||||
|
this.input.autoComplete({
|
||||||
|
search: searchFunction,
|
||||||
|
minLength: 0
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.optionMenu = this._createMenu(opt.options,opt,function(v){
|
this.optionMenu = this._createMenu(opt.options,opt,function(v){
|
||||||
if (!opt.multiple) {
|
if (!opt.multiple) {
|
||||||
@ -1386,8 +1394,12 @@
|
|||||||
this.valueLabelContainer.hide();
|
this.valueLabelContainer.hide();
|
||||||
this.elementDiv.show();
|
this.elementDiv.show();
|
||||||
if (opt.autoComplete) {
|
if (opt.autoComplete) {
|
||||||
|
let searchFunction = opt.autoComplete
|
||||||
|
if (searchFunction.length === 0) {
|
||||||
|
searchFunction = opt.autoComplete.call(this)
|
||||||
|
}
|
||||||
this.input.autoComplete({
|
this.input.autoComplete({
|
||||||
search: opt.autoComplete,
|
search: searchFunction,
|
||||||
minLength: 0
|
minLength: 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user