mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
fix conversion of junction to subflow
This commit is contained in:
parent
551e73adef
commit
94471b6d07
@ -738,6 +738,10 @@ RED.nodes = (function() {
|
|||||||
moveGroupToTab(node,z);
|
moveGroupToTab(node,z);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (node.type === "junction") {
|
||||||
|
moveJunctionToTab(node,z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var oldZ = node.z;
|
var oldZ = node.z;
|
||||||
allNodes.moveNode(node,z);
|
allNodes.moveNode(node,z);
|
||||||
var nl = nodeLinks[node.id];
|
var nl = nodeLinks[node.id];
|
||||||
@ -772,6 +776,38 @@ RED.nodes = (function() {
|
|||||||
RED.events.emit("groups:change",group);
|
RED.events.emit("groups:change",group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function moveJunctionToTab(junction, z) {
|
||||||
|
var index = junctionsByZ[junction.z].indexOf(junction);
|
||||||
|
junctionsByZ[junction.z].splice(junction,1);
|
||||||
|
junctionsByZ[z] = junctionsByZ[z] || [];
|
||||||
|
junctionsByZ[z].push(junction);
|
||||||
|
junction.z = z;
|
||||||
|
|
||||||
|
var oldZ = junction.z;
|
||||||
|
var nl = nodeLinks[junction.id];
|
||||||
|
if (nl) {
|
||||||
|
nl.in.forEach(function(l) {
|
||||||
|
var idx = linkTabMap[oldZ].indexOf(l);
|
||||||
|
if (idx != -1) {
|
||||||
|
linkTabMap[oldZ].splice(idx, 1);
|
||||||
|
}
|
||||||
|
if ((l.source.z === z) && linkTabMap[z]) {
|
||||||
|
linkTabMap[z].push(l);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
nl.out.forEach(function(l) {
|
||||||
|
var idx = linkTabMap[oldZ].indexOf(l);
|
||||||
|
if (idx != -1) {
|
||||||
|
linkTabMap[oldZ].splice(idx, 1);
|
||||||
|
}
|
||||||
|
if ((l.target.z === z) && linkTabMap[z]) {
|
||||||
|
linkTabMap[z].push(l);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
RED.events.emit("junctions:change",junction);
|
||||||
|
}
|
||||||
|
|
||||||
function removeLink(l) {
|
function removeLink(l) {
|
||||||
var index = links.indexOf(l);
|
var index = links.indexOf(l);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
|
@ -604,6 +604,14 @@ RED.subflow = (function() {
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nodeOrJunction(id) {
|
||||||
|
var node = RED.nodes.node(id);
|
||||||
|
if (node) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
return RED.nodes.junction(id);
|
||||||
|
}
|
||||||
|
|
||||||
function convertToSubflow() {
|
function convertToSubflow() {
|
||||||
var selection = RED.view.selection();
|
var selection = RED.view.selection();
|
||||||
if (!selection.nodes) {
|
if (!selection.nodes) {
|
||||||
@ -792,14 +800,15 @@ RED.subflow = (function() {
|
|||||||
|
|
||||||
subflow.in.forEach(function(input) {
|
subflow.in.forEach(function(input) {
|
||||||
input.wires.forEach(function(wire) {
|
input.wires.forEach(function(wire) {
|
||||||
var link = {source: input, sourcePort: 0, target: RED.nodes.node(wire.id) }
|
var link = {source: input, sourcePort: 0, target: nodeOrJunction(wire.id) }
|
||||||
new_links.push(link);
|
new_links.push(link);
|
||||||
RED.nodes.addLink(link);
|
RED.nodes.addLink(link);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
subflow.out.forEach(function(output,i) {
|
subflow.out.forEach(function(output,i) {
|
||||||
output.wires.forEach(function(wire) {
|
output.wires.forEach(function(wire) {
|
||||||
var link = {source: RED.nodes.node(wire.id), sourcePort: wire.port , target: output }
|
var link = {source: nodeOrJunction(wire.id), sourcePort: wire.port , target: output }
|
||||||
new_links.push(link);
|
new_links.push(link);
|
||||||
RED.nodes.addLink(link);
|
RED.nodes.addLink(link);
|
||||||
});
|
});
|
||||||
@ -815,7 +824,7 @@ RED.subflow = (function() {
|
|||||||
n.links = n.links.filter(function(id) {
|
n.links = n.links.filter(function(id) {
|
||||||
var isLocalLink = nodes.hasOwnProperty(id);
|
var isLocalLink = nodes.hasOwnProperty(id);
|
||||||
if (!isLocalLink) {
|
if (!isLocalLink) {
|
||||||
var otherNode = RED.nodes.node(id);
|
var otherNode = nodeOrJunction(id);
|
||||||
if (otherNode && otherNode.links) {
|
if (otherNode && otherNode.links) {
|
||||||
var i = otherNode.links.indexOf(n.id);
|
var i = otherNode.links.indexOf(n.id);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
@ -831,7 +840,6 @@ RED.subflow = (function() {
|
|||||||
RED.nodes.moveNodeToTab(n, subflow.id);
|
RED.nodes.moveNodeToTab(n, subflow.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var historyEvent = {
|
var historyEvent = {
|
||||||
t:'createSubflow',
|
t:'createSubflow',
|
||||||
nodes:[subflowInstance.id],
|
nodes:[subflowInstance.id],
|
||||||
|
Loading…
Reference in New Issue
Block a user