mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	@@ -725,6 +725,90 @@ RED.view.tools = (function() {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    function wireSeriesOfNodes() {
 | 
			
		||||
        var selection = RED.view.selection();
 | 
			
		||||
        if (selection.nodes) {
 | 
			
		||||
            if (selection.nodes.length > 1) {
 | 
			
		||||
                var i = 0;
 | 
			
		||||
                var newLinks = [];
 | 
			
		||||
                while (i < selection.nodes.length - 1) {
 | 
			
		||||
                    var nodeA = selection.nodes[i];
 | 
			
		||||
                    var nodeB = selection.nodes[i+1];
 | 
			
		||||
                    if (nodeA.outputs > 0 && nodeB.inputs > 0) {
 | 
			
		||||
                        var existingLinks = RED.nodes.filterLinks({
 | 
			
		||||
                            source: nodeA,
 | 
			
		||||
                            target: nodeB,
 | 
			
		||||
                            sourcePort: 0
 | 
			
		||||
                        })
 | 
			
		||||
                        if (existingLinks.length === 0) {
 | 
			
		||||
                            var newLink = {
 | 
			
		||||
                                source: nodeA,
 | 
			
		||||
                                target: nodeB,
 | 
			
		||||
                                sourcePort: 0
 | 
			
		||||
                            }
 | 
			
		||||
                            RED.nodes.addLink(newLink);
 | 
			
		||||
                            newLinks.push(newLink);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    i++;
 | 
			
		||||
                }
 | 
			
		||||
                if (newLinks.length > 0) {
 | 
			
		||||
                    RED.history.push({
 | 
			
		||||
                        t: 'add',
 | 
			
		||||
                        links: newLinks,
 | 
			
		||||
                        dirty: RED.nodes.dirty()
 | 
			
		||||
                    })
 | 
			
		||||
                    RED.nodes.dirty(true);
 | 
			
		||||
                    RED.view.redraw(true);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function wireNodeToMultiple() {
 | 
			
		||||
        var selection = RED.view.selection();
 | 
			
		||||
        if (selection.nodes) {
 | 
			
		||||
            if (selection.nodes.length > 1) {
 | 
			
		||||
                var sourceNode = selection.nodes[0];
 | 
			
		||||
                if (sourceNode.outputs === 0) {
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                var i = 1;
 | 
			
		||||
                var newLinks = [];
 | 
			
		||||
                while (i < selection.nodes.length) {
 | 
			
		||||
                    var targetNode = selection.nodes[i];
 | 
			
		||||
                    if (targetNode.inputs > 0) {
 | 
			
		||||
                        var existingLinks = RED.nodes.filterLinks({
 | 
			
		||||
                            source: sourceNode,
 | 
			
		||||
                            target: targetNode,
 | 
			
		||||
                            sourcePort: Math.min(sourceNode.outputs-1,i-1)
 | 
			
		||||
                        })
 | 
			
		||||
                        if (existingLinks.length === 0) {
 | 
			
		||||
                            var newLink = {
 | 
			
		||||
                                source: sourceNode,
 | 
			
		||||
                                target: targetNode,
 | 
			
		||||
                                sourcePort: Math.min(sourceNode.outputs-1,i-1)
 | 
			
		||||
                            }
 | 
			
		||||
                            RED.nodes.addLink(newLink);
 | 
			
		||||
                            newLinks.push(newLink);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    i++;
 | 
			
		||||
                }
 | 
			
		||||
                if (newLinks.length > 0) {
 | 
			
		||||
                    RED.history.push({
 | 
			
		||||
                        t: 'add',
 | 
			
		||||
                        links: newLinks,
 | 
			
		||||
                        dirty: RED.nodes.dirty()
 | 
			
		||||
                    })
 | 
			
		||||
                    RED.nodes.dirty(true);
 | 
			
		||||
                    RED.view.redraw(true);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        init: function() {
 | 
			
		||||
            RED.actions.add("core:show-selected-node-labels", function() { setSelectedNodeLabelState(true); })
 | 
			
		||||
@@ -783,7 +867,8 @@ RED.view.tools = (function() {
 | 
			
		||||
            RED.actions.add("core:distribute-selection-horizontally", function() { distributeSelection('h') })
 | 
			
		||||
            RED.actions.add("core:distribute-selection-vertically", function() { distributeSelection('v') })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            RED.actions.add("core:wire-series-of-nodes", function() { wireSeriesOfNodes() })
 | 
			
		||||
            RED.actions.add("core:wire-node-to-multiple", function() { wireNodeToMultiple() })
 | 
			
		||||
 | 
			
		||||
            // RED.actions.add("core:add-node", function() { addNode() })
 | 
			
		||||
        },
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user