mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Fix setting of config node select value
This commit is contained in:
		| @@ -426,14 +426,8 @@ RED.editor = (function() { | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         var label = ""; | ||||
|         var configNode = RED.nodes.node(nodeValue); | ||||
|  | ||||
|         if (configNode) { | ||||
|             label = RED.utils.getNodeLabel(configNode, configNode.id); | ||||
|         } | ||||
|  | ||||
|         input.val(label); | ||||
|         // Set the select value | ||||
|         select.val(nodeValue); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -848,99 +842,89 @@ RED.editor = (function() { | ||||
|     function updateConfigNodeSelect(name,type,value,prefix,filter) { | ||||
|         // if prefix is null, there is no config select to update | ||||
|         if (prefix) { | ||||
|             var button = $("#"+prefix+"-edit-"+name); | ||||
|             if (button.length) { | ||||
|                 if (value) { | ||||
|                     button.text(RED._("editor.configEdit")); | ||||
|                 } else { | ||||
|                     button.text(RED._("editor.configAdd")); | ||||
|                 } | ||||
|                 $("#"+prefix+"-"+name).val(value); | ||||
|             } else { | ||||
|                 let inclSubflowEnvvars = false | ||||
|                 var select = $("#"+prefix+"-"+name); | ||||
|                 var node_def = RED.nodes.getType(type); | ||||
|                 select.children().remove(); | ||||
|             let inclSubflowEnvvars = false | ||||
|             var select = $("#"+prefix+"-"+name); | ||||
|             var node_def = RED.nodes.getType(type); | ||||
|             select.children().remove(); | ||||
|  | ||||
|                 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); | ||||
|             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); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user