mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #4947 from GogoVega/fix-conf-type-env
Handle subflow node as user of config nodes
This commit is contained in:
commit
4e6c8ea367
@ -453,10 +453,48 @@ RED.history = (function() {
|
||||
RED.events.emit("nodes:change",newConfigNode);
|
||||
}
|
||||
});
|
||||
} else if (i === "env" && ev.node.type.indexOf("subflow:") === 0) {
|
||||
// Subflow can have config node in node.env
|
||||
let nodeList = ev.node.env || [];
|
||||
nodeList = nodeList.reduce((list, prop) => {
|
||||
if (prop.type === "conf-type" && prop.value) {
|
||||
list.push(prop.value);
|
||||
}
|
||||
return list;
|
||||
}, []);
|
||||
|
||||
nodeList.forEach(function(id) {
|
||||
const configNode = RED.nodes.node(id);
|
||||
if (configNode) {
|
||||
if (configNode.users.indexOf(ev.node) !== -1) {
|
||||
configNode.users.splice(configNode.users.indexOf(ev.node), 1);
|
||||
RED.events.emit("nodes:change", configNode);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nodeList = ev.changes.env || [];
|
||||
nodeList = nodeList.reduce((list, prop) => {
|
||||
if (prop.type === "conf-type" && prop.value) {
|
||||
list.push(prop.value);
|
||||
}
|
||||
return list;
|
||||
}, []);
|
||||
|
||||
nodeList.forEach(function(id) {
|
||||
const configNode = RED.nodes.node(id);
|
||||
if (configNode) {
|
||||
if (configNode.users.indexOf(ev.node) === -1) {
|
||||
configNode.users.push(ev.node);
|
||||
RED.events.emit("nodes:change", configNode);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
ev.node[i] = ev.changes[i];
|
||||
}
|
||||
}
|
||||
|
||||
ev.node.dirty = true;
|
||||
ev.node.changed = ev.changed;
|
||||
|
||||
|
@ -708,7 +708,7 @@ RED.nodes = (function() {
|
||||
n["_"] = RED._;
|
||||
}
|
||||
if (n._def.category == "config") {
|
||||
configNodes[n.id] = n;
|
||||
configNodes[n.id] = newNode;
|
||||
} else {
|
||||
if (n.wires && (n.wires.length > n.outputs)) { n.outputs = n.wires.length; }
|
||||
n.dirty = true;
|
||||
@ -812,6 +812,20 @@ RED.nodes = (function() {
|
||||
if (sf) {
|
||||
sf.instances.splice(sf.instances.indexOf(node),1);
|
||||
}
|
||||
|
||||
node.env?.forEach((prop) => {
|
||||
if (prop.type === "conf-type" && prop.value) {
|
||||
// Remove the node from the config node users
|
||||
const configNode = getNode(prop.value);
|
||||
if (configNode) {
|
||||
if (configNode.users.indexOf(node) !== -1) {
|
||||
configNode.users.splice(configNode.users.indexOf(node), 1);
|
||||
RED.events.emit('nodes:change', configNode);
|
||||
updatedConfigNode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (updatedConfigNode) {
|
||||
@ -2748,6 +2762,22 @@ RED.nodes = (function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Subflows can have config node env
|
||||
if (n.type.indexOf("subflow:") === 0) {
|
||||
n.env?.forEach((prop) => {
|
||||
if (prop.type === "conf-type" && prop.value) {
|
||||
// Add the node to the config node users
|
||||
const configNode = getNode(prop.value);
|
||||
if (configNode) {
|
||||
if (configNode.users.indexOf(n) === -1) {
|
||||
configNode.users.push(n);
|
||||
RED.events.emit('nodes:change', configNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function flowVersion(version) {
|
||||
|
@ -20,10 +20,31 @@
|
||||
apply: function(editState) {
|
||||
var old_env = node.env;
|
||||
var new_env = [];
|
||||
|
||||
if (/^subflow:/.test(node.type)) {
|
||||
// Get the list of environment variables from the node properties
|
||||
new_env = RED.subflow.exportSubflowInstanceEnv(node);
|
||||
}
|
||||
|
||||
if (old_env && old_env.length) {
|
||||
old_env.forEach(function (prop) {
|
||||
if (prop.type === "conf-type" && prop.value) {
|
||||
const stillInUse = new_env?.some((p) => p.type === "conf-type" && p.name === prop.name && p.value === prop.value);
|
||||
if (!stillInUse) {
|
||||
// Remove the node from the config node users
|
||||
// Only for empty value or modified
|
||||
const configNode = RED.nodes.node(prop.value);
|
||||
if (configNode) {
|
||||
if (configNode.users.indexOf(node) !== -1) {
|
||||
configNode.users.splice(configNode.users.indexOf(node), 1);
|
||||
RED.events.emit('nodes:change', configNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Get the values from the Properties table tab
|
||||
var items = this.list.editableList('items');
|
||||
items.each(function (i,el) {
|
||||
@ -41,7 +62,6 @@
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (new_env && new_env.length > 0) {
|
||||
new_env.forEach(function(prop) {
|
||||
if (prop.type === "cred") {
|
||||
@ -52,6 +72,15 @@
|
||||
editState.changed = true;
|
||||
}
|
||||
delete prop.value;
|
||||
} else if (prop.type === "conf-type" && prop.value) {
|
||||
const configNode = RED.nodes.node(prop.value);
|
||||
if (configNode) {
|
||||
if (configNode.users.indexOf(node) === -1) {
|
||||
// Add the node to the config node users
|
||||
configNode.users.push(node);
|
||||
RED.events.emit('nodes:change', configNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -44,6 +44,7 @@
|
||||
apply: function(editState) {
|
||||
var newValue;
|
||||
var d;
|
||||
// If the node is a subflow, the node's properties (exepts name) are saved by `envProperties`
|
||||
if (node._def.defaults) {
|
||||
for (d in node._def.defaults) {
|
||||
if (node._def.defaults.hasOwnProperty(d)) {
|
||||
|
@ -1363,7 +1363,7 @@ RED.subflow = (function() {
|
||||
item.value = ""+input.prop("checked");
|
||||
break;
|
||||
case "conf-types":
|
||||
item.value = input.val()
|
||||
item.value = input.val() === "_ADD_" ? "" : input.val();
|
||||
item.type = "conf-type"
|
||||
}
|
||||
if (ui.type === "cred" || item.type !== data.parent.type || item.value !== data.parent.value) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user