mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Revert the updateConfigNodeSelect
changes
This commit is contained in:
parent
6623e56a1e
commit
9c511b6674
@ -842,89 +842,99 @@ RED.editor = (function() {
|
|||||||
function updateConfigNodeSelect(name,type,value,prefix,filter) {
|
function updateConfigNodeSelect(name,type,value,prefix,filter) {
|
||||||
// if prefix is null, there is no config select to update
|
// if prefix is null, there is no config select to update
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
let inclSubflowEnvvars = false
|
var button = $("#"+prefix+"-edit-"+name);
|
||||||
var select = $("#"+prefix+"-"+name);
|
if (button.length) {
|
||||||
var node_def = RED.nodes.getType(type);
|
if (value) {
|
||||||
select.children().remove();
|
button.text(RED._("editor.configEdit"));
|
||||||
|
} else {
|
||||||
var activeWorkspace = RED.nodes.workspace(RED.workspaces.active());
|
button.text(RED._("editor.configAdd"));
|
||||||
if (!activeWorkspace) {
|
|
||||||
activeWorkspace = RED.nodes.subflow(RED.workspaces.active());
|
|
||||||
inclSubflowEnvvars = true
|
|
||||||
}
|
|
||||||
|
|
||||||
var configNodes = [];
|
|
||||||
if (typeof filter !== 'function') {
|
|
||||||
filter = null;
|
|
||||||
}
|
|
||||||
RED.nodes.eachConfig(function(config) {
|
|
||||||
if (config.type == type && (!config.z || config.z === activeWorkspace.id)) {
|
|
||||||
if (!filter || filter.call(null,config)) {
|
|
||||||
var label = RED.utils.getNodeLabel(config,config.id);
|
|
||||||
config.__label__ = label+(config.d?" ["+RED._("workspace.disabled")+"]":"");
|
|
||||||
configNodes.push(config);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
$("#"+prefix+"-"+name).val(value);
|
||||||
|
|
||||||
// as includeSubflowEnvvars is true, this is a subflow.
|
|
||||||
// include any 'conf-types' env vars as a list of avaiable configs
|
|
||||||
// in the config dropdown as `[env] node-name`
|
|
||||||
if (inclSubflowEnvvars && activeWorkspace.env) {
|
|
||||||
const parentEnv = activeWorkspace.env.filter(env => env.ui?.type === 'conf-types' && env.type === type)
|
|
||||||
if (parentEnv && parentEnv.length > 0) {
|
|
||||||
const locale = RED.i18n.lang()
|
|
||||||
for (let i = 0; i < parentEnv.length; i++) {
|
|
||||||
const tenv = parentEnv[i]
|
|
||||||
const ui = tenv.ui || {}
|
|
||||||
const labels = ui.label || {}
|
|
||||||
const labelText = RED.editor.envVarList.lookupLabel(labels, labels["en-US"] || tenv.name, locale)
|
|
||||||
const config = {
|
|
||||||
env: tenv,
|
|
||||||
id: '${' + parentEnv[0].name + '}',
|
|
||||||
type: type,
|
|
||||||
label: labelText,
|
|
||||||
__label__: `[env] ${labelText}`
|
|
||||||
}
|
|
||||||
configNodes.push(config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var configSortFn = defaultConfigNodeSort;
|
|
||||||
if (typeof node_def.sort == "function") {
|
|
||||||
configSortFn = node_def.sort;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
configNodes.sort(configSortFn);
|
|
||||||
} catch(err) {
|
|
||||||
console.log("Definition error: "+node_def.type+".sort",err);
|
|
||||||
}
|
|
||||||
|
|
||||||
configNodes.forEach(function(cn) {
|
|
||||||
const option = $('<option value="'+cn.id+'"'+(value==cn.id?" selected":"")+'></option>').text(RED.text.bidi.enforceTextDirectionWithUCC(cn.__label__)).appendTo(select);
|
|
||||||
if (cn.env) {
|
|
||||||
option.data('env', cn.env) // set a data attribute to indicate this is an env var (to inhibit the edit button)
|
|
||||||
}
|
|
||||||
delete cn.__label__;
|
|
||||||
});
|
|
||||||
|
|
||||||
var label = type;
|
|
||||||
if (typeof node_def.paletteLabel !== "undefined") {
|
|
||||||
try {
|
|
||||||
label = RED.utils.sanitize((typeof node_def.paletteLabel === "function" ? node_def.paletteLabel.call(node_def) : node_def.paletteLabel)||type);
|
|
||||||
} catch(err) {
|
|
||||||
console.log("Definition error: "+type+".paletteLabel",err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!configNodes.length) {
|
|
||||||
select.append('<option value="_ADD_" selected>' + RED._("editor.addNewType", { type: label }) + '</option>');
|
|
||||||
} else {
|
} else {
|
||||||
select.append('<option value="">' + RED._("editor.inputs.none") + '</option>');
|
let inclSubflowEnvvars = false
|
||||||
}
|
var select = $("#"+prefix+"-"+name);
|
||||||
|
var node_def = RED.nodes.getType(type);
|
||||||
|
select.children().remove();
|
||||||
|
|
||||||
window.setTimeout(function() { select.trigger("change");},50);
|
var activeWorkspace = RED.nodes.workspace(RED.workspaces.active());
|
||||||
|
if (!activeWorkspace) {
|
||||||
|
activeWorkspace = RED.nodes.subflow(RED.workspaces.active());
|
||||||
|
inclSubflowEnvvars = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var configNodes = [];
|
||||||
|
if (typeof filter !== 'function') {
|
||||||
|
filter = null;
|
||||||
|
}
|
||||||
|
RED.nodes.eachConfig(function(config) {
|
||||||
|
if (config.type == type && (!config.z || config.z === activeWorkspace.id)) {
|
||||||
|
if (!filter || filter.call(null,config)) {
|
||||||
|
var label = RED.utils.getNodeLabel(config,config.id);
|
||||||
|
config.__label__ = label+(config.d?" ["+RED._("workspace.disabled")+"]":"");
|
||||||
|
configNodes.push(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// as includeSubflowEnvvars is true, this is a subflow.
|
||||||
|
// include any 'conf-types' env vars as a list of avaiable configs
|
||||||
|
// in the config dropdown as `[env] node-name`
|
||||||
|
if (inclSubflowEnvvars && activeWorkspace.env) {
|
||||||
|
const parentEnv = activeWorkspace.env.filter(env => env.ui?.type === 'conf-types' && env.type === type)
|
||||||
|
if (parentEnv && parentEnv.length > 0) {
|
||||||
|
const locale = RED.i18n.lang()
|
||||||
|
for (let i = 0; i < parentEnv.length; i++) {
|
||||||
|
const tenv = parentEnv[i]
|
||||||
|
const ui = tenv.ui || {}
|
||||||
|
const labels = ui.label || {}
|
||||||
|
const labelText = RED.editor.envVarList.lookupLabel(labels, labels["en-US"] || tenv.name, locale)
|
||||||
|
const config = {
|
||||||
|
env: tenv,
|
||||||
|
id: '${' + parentEnv[0].name + '}',
|
||||||
|
type: type,
|
||||||
|
label: labelText,
|
||||||
|
__label__: `[env] ${labelText}`
|
||||||
|
}
|
||||||
|
configNodes.push(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var configSortFn = defaultConfigNodeSort;
|
||||||
|
if (typeof node_def.sort == "function") {
|
||||||
|
configSortFn = node_def.sort;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
configNodes.sort(configSortFn);
|
||||||
|
} catch(err) {
|
||||||
|
console.log("Definition error: "+node_def.type+".sort",err);
|
||||||
|
}
|
||||||
|
|
||||||
|
configNodes.forEach(function(cn) {
|
||||||
|
const option = $('<option value="'+cn.id+'"'+(value==cn.id?" selected":"")+'></option>').text(RED.text.bidi.enforceTextDirectionWithUCC(cn.__label__)).appendTo(select);
|
||||||
|
if (cn.env) {
|
||||||
|
option.data('env', cn.env) // set a data attribute to indicate this is an env var (to inhibit the edit button)
|
||||||
|
}
|
||||||
|
delete cn.__label__;
|
||||||
|
});
|
||||||
|
|
||||||
|
var label = type;
|
||||||
|
if (typeof node_def.paletteLabel !== "undefined") {
|
||||||
|
try {
|
||||||
|
label = RED.utils.sanitize((typeof node_def.paletteLabel === "function" ? node_def.paletteLabel.call(node_def) : node_def.paletteLabel)||type);
|
||||||
|
} catch(err) {
|
||||||
|
console.log("Definition error: "+type+".paletteLabel",err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!configNodes.length) {
|
||||||
|
select.append('<option value="_ADD_" selected>' + RED._("editor.addNewType", { type: label }) + '</option>');
|
||||||
|
} else {
|
||||||
|
select.append('<option value="">' + RED._("editor.inputs.none") + '</option>');
|
||||||
|
}
|
||||||
|
|
||||||
|
window.setTimeout(function() { select.trigger("change");},50);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user