mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #4807 from GogoVega/fix-user-count
Fix the config node users count
This commit is contained in:
commit
2a71175cd4
@ -712,7 +712,7 @@ RED.nodes = (function() {
|
|||||||
} else {
|
} else {
|
||||||
if (n.wires && (n.wires.length > n.outputs)) { n.outputs = n.wires.length; }
|
if (n.wires && (n.wires.length > n.outputs)) { n.outputs = n.wires.length; }
|
||||||
n.dirty = true;
|
n.dirty = true;
|
||||||
updateConfigNodeUsers(n);
|
updateConfigNodeUsers(newNode, { action: "add" });
|
||||||
if (n._def.category == "subflows" && typeof n.i === "undefined") {
|
if (n._def.category == "subflows" && typeof n.i === "undefined") {
|
||||||
var nextId = 0;
|
var nextId = 0;
|
||||||
RED.nodes.eachNode(function(node) {
|
RED.nodes.eachNode(function(node) {
|
||||||
@ -785,6 +785,7 @@ RED.nodes = (function() {
|
|||||||
delete nodeLinks[id];
|
delete nodeLinks[id];
|
||||||
removedLinks = links.filter(function(l) { return (l.source === node) || (l.target === node); });
|
removedLinks = links.filter(function(l) { return (l.source === node) || (l.target === node); });
|
||||||
removedLinks.forEach(removeLink);
|
removedLinks.forEach(removeLink);
|
||||||
|
updateConfigNodeUsers(node, { action: "remove" });
|
||||||
var updatedConfigNode = false;
|
var updatedConfigNode = false;
|
||||||
for (var d in node._def.defaults) {
|
for (var d in node._def.defaults) {
|
||||||
if (node._def.defaults.hasOwnProperty(d)) {
|
if (node._def.defaults.hasOwnProperty(d)) {
|
||||||
@ -798,10 +799,6 @@ RED.nodes = (function() {
|
|||||||
if (configNode._def.exclusive) {
|
if (configNode._def.exclusive) {
|
||||||
removeNode(node[d]);
|
removeNode(node[d]);
|
||||||
removedNodes.push(configNode);
|
removedNodes.push(configNode);
|
||||||
} else {
|
|
||||||
var users = configNode.users;
|
|
||||||
users.splice(users.indexOf(node),1);
|
|
||||||
RED.events.emit('nodes:change',configNode)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1798,9 +1795,20 @@ RED.nodes = (function() {
|
|||||||
// Replace config nodes
|
// Replace config nodes
|
||||||
//
|
//
|
||||||
configNodeIds.forEach(function(id) {
|
configNodeIds.forEach(function(id) {
|
||||||
removedNodes = removedNodes.concat(convertNode(getNode(id)));
|
const configNode = getNode(id);
|
||||||
|
const currentUserCount = configNode.users;
|
||||||
|
|
||||||
|
// Add a snapshot of the Config Node
|
||||||
|
removedNodes = removedNodes.concat(convertNode(configNode));
|
||||||
|
|
||||||
|
// Remove the Config Node instance
|
||||||
removeNode(id);
|
removeNode(id);
|
||||||
importNodes([newConfigNodes[id]])
|
|
||||||
|
// Import the new one
|
||||||
|
importNodes([newConfigNodes[id]]);
|
||||||
|
|
||||||
|
// Re-attributes the user count
|
||||||
|
getNode(id).users = currentUserCount;
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -2470,11 +2478,6 @@ RED.nodes = (function() {
|
|||||||
nodeList = nodeList.map(function(id) {
|
nodeList = nodeList.map(function(id) {
|
||||||
var node = node_map[id];
|
var node = node_map[id];
|
||||||
if (node) {
|
if (node) {
|
||||||
if (node._def.category === 'config') {
|
|
||||||
if (node.users.indexOf(n) === -1) {
|
|
||||||
node.users.push(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return node.id;
|
return node.id;
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
@ -2701,19 +2704,44 @@ RED.nodes = (function() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update any config nodes referenced by the provided node to ensure their 'users' list is correct
|
/**
|
||||||
function updateConfigNodeUsers(n) {
|
* Update any config nodes referenced by the provided node to ensure
|
||||||
for (var d in n._def.defaults) {
|
* their 'users' list is correct.
|
||||||
if (n._def.defaults.hasOwnProperty(d)) {
|
*
|
||||||
var property = n._def.defaults[d];
|
* Options:
|
||||||
|
* - `action` - Add or remove the node from the Config Node users list. Default `add`.
|
||||||
|
* - `emitEvent` - Emit the `nodes:changes` event. Default true.
|
||||||
|
*
|
||||||
|
* @param {object} node The node in which to check if it contains references
|
||||||
|
* @param {{ action?: "add" | "remove"; emitEvent?: boolean; }} options Options to apply.
|
||||||
|
*/
|
||||||
|
function updateConfigNodeUsers(node, options = {}) {
|
||||||
|
const defaultOptions = { action: "add", emitEvent: true };
|
||||||
|
options = Object.assign({}, defaultOptions, options);
|
||||||
|
|
||||||
|
for (var d in node._def.defaults) {
|
||||||
|
if (node._def.defaults.hasOwnProperty(d)) {
|
||||||
|
var property = node._def.defaults[d];
|
||||||
if (property.type) {
|
if (property.type) {
|
||||||
var type = registry.getNodeType(property.type);
|
var type = registry.getNodeType(property.type);
|
||||||
if (type && type.category == "config") {
|
if (type && type.category == "config") {
|
||||||
var configNode = configNodes[n[d]];
|
var configNode = configNodes[node[d]];
|
||||||
if (configNode) {
|
if (configNode) {
|
||||||
if (configNode.users.indexOf(n) === -1) {
|
if (options.action === "add") {
|
||||||
configNode.users.push(n);
|
if (configNode.users.indexOf(node) === -1) {
|
||||||
RED.events.emit('nodes:change',configNode)
|
configNode.users.push(node);
|
||||||
|
if (options.emitEvent) {
|
||||||
|
RED.events.emit('nodes:change', configNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (options.action === "remove") {
|
||||||
|
if (configNode.users.indexOf(node) !== -1) {
|
||||||
|
const users = configNode.users;
|
||||||
|
users.splice(users.indexOf(node), 1);
|
||||||
|
if (options.emitEvent) {
|
||||||
|
RED.events.emit('nodes:change', configNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,6 +512,7 @@ RED.subflow = (function() {
|
|||||||
removedNodes.push(n);
|
removedNodes.push(n);
|
||||||
}
|
}
|
||||||
if (n.z == id) {
|
if (n.z == id) {
|
||||||
|
RED.nodes.updateConfigNodeUsers(n, { action: "remove" });
|
||||||
removedNodes.push(n);
|
removedNodes.push(n);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user