🐛 Fix that drop connection and addNodeButton did connect wrong

This commit is contained in:
Jan Oberhauser 2019-12-10 15:39:14 +01:00
parent 5da4a80d67
commit f31049d454
3 changed files with 21 additions and 5 deletions

View file

@ -173,6 +173,7 @@ export const mouseSelect = mixins(nodeIndex).extend({
this.instance.clearDragSelection(); this.instance.clearDragSelection();
this.$store.commit('resetSelectedNodes'); this.$store.commit('resetSelectedNodes');
this.$store.commit('setLastSelectedNode', null); this.$store.commit('setLastSelectedNode', null);
this.$store.commit('setLastSelectedNodeOutputIndex', null);
this.$store.commit('setActiveNode', null); this.$store.commit('setActiveNode', null);
}, },
}, },

View file

@ -56,6 +56,7 @@ export const store = new Vuex.Store({
versionCli: '0.0.0', versionCli: '0.0.0',
workflowExecutionData: null as IExecutionResponse | null, workflowExecutionData: null as IExecutionResponse | null,
lastSelectedNode: null as string | null, lastSelectedNode: null as string | null,
lastSelectedNodeOutputIndex: null as number | null,
nodeIndex: [] as Array<string | null>, nodeIndex: [] as Array<string | null>,
nodeTypes: [] as INodeTypeDescription[], nodeTypes: [] as INodeTypeDescription[],
nodeViewOffsetPosition: [0, 0] as XYPositon, nodeViewOffsetPosition: [0, 0] as XYPositon,
@ -501,6 +502,10 @@ export const store = new Vuex.Store({
state.lastSelectedNode = nodeName; state.lastSelectedNode = nodeName;
}, },
setLastSelectedNodeOutputIndex(state, outputIndex: number | null) {
state.lastSelectedNodeOutputIndex = outputIndex;
},
setWorkflowExecutionData (state, workflowResultData: IExecutionResponse | null) { setWorkflowExecutionData (state, workflowResultData: IExecutionResponse | null) {
state.workflowExecutionData = workflowResultData; state.workflowExecutionData = workflowResultData;
}, },
@ -712,6 +717,9 @@ export const store = new Vuex.Store({
lastSelectedNode: (state, getters): INodeUi | null => { lastSelectedNode: (state, getters): INodeUi | null => {
return getters.nodeByName(state.lastSelectedNode); return getters.nodeByName(state.lastSelectedNode);
}, },
lastSelectedNodeOutputIndex: (state, getters): number | null => {
return state.lastSelectedNodeOutputIndex;
},
// Active Execution // Active Execution
executingNode: (state): string | null => { executingNode: (state): string | null => {

View file

@ -806,6 +806,7 @@ export default mixins(
} }
this.$store.commit('setLastSelectedNode', node.name); this.$store.commit('setLastSelectedNode', node.name);
this.$store.commit('setLastSelectedNodeOutputIndex', null);
if (setActive === true) { if (setActive === true) {
this.$store.commit('setActiveNode', node.name); this.$store.commit('setActiveNode', node.name);
@ -936,6 +937,7 @@ export default mixins(
// Check if there is a last selected node // Check if there is a last selected node
const lastSelectedNode = this.$store.getters.lastSelectedNode; const lastSelectedNode = this.$store.getters.lastSelectedNode;
const lastSelectedNodeOutputIndex = this.$store.getters.lastSelectedNodeOutputIndex;
if (lastSelectedNode) { if (lastSelectedNode) {
// If a node is active then add the new node directly after the current one // If a node is active then add the new node directly after the current one
// newNodeData.position = [activeNode.position[0], activeNode.position[1] + 60]; // newNodeData.position = [activeNode.position[0], activeNode.position[1] + 60];
@ -960,6 +962,8 @@ export default mixins(
this.nodeSelectedByName(newNodeData.name, true); this.nodeSelectedByName(newNodeData.name, true);
}); });
const outputIndex = lastSelectedNodeOutputIndex || 0;
if (lastSelectedNode) { if (lastSelectedNode) {
// If a node is last selected then connect between the active and its child ones // If a node is last selected then connect between the active and its child ones
await Vue.nextTick(); await Vue.nextTick();
@ -971,15 +975,15 @@ export default mixins(
connections = JSON.parse(JSON.stringify(connections)); connections = JSON.parse(JSON.stringify(connections));
for (const type of Object.keys(connections)) { for (const type of Object.keys(connections)) {
for (let inputIndex = 0; inputIndex < connections[type].length; inputIndex++) { if (outputIndex <= connections[type].length) {
connections[type][inputIndex].forEach((connectionInfo: IConnection) => { connections[type][outputIndex].forEach((connectionInfo: IConnection) => {
// Remove currenct connection // Remove currenct connection
const connectionDataDisonnect = [ const connectionDataDisonnect = [
{ {
node: lastSelectedNode.name, node: lastSelectedNode.name,
type, type,
index: inputIndex, index: outputIndex,
}, },
connectionInfo, connectionInfo,
] as [IConnection, IConnection]; ] as [IConnection, IConnection];
@ -990,7 +994,7 @@ export default mixins(
{ {
node: newNodeData.name, node: newNodeData.name,
type, type,
index: inputIndex, index: 0,
}, },
connectionInfo, connectionInfo,
] as [IConnection, IConnection]; ] as [IConnection, IConnection];
@ -1007,7 +1011,7 @@ export default mixins(
{ {
node: lastSelectedNode.name, node: lastSelectedNode.name,
type: 'main', type: 'main',
index: 0, index: outputIndex,
}, },
{ {
node: newNodeData.name, node: newNodeData.name,
@ -1063,6 +1067,9 @@ export default mixins(
const sourceNodeName = this.$store.getters.getNodeNameByIndex(info.sourceId.slice(NODE_NAME_PREFIX.length)); const sourceNodeName = this.$store.getters.getNodeNameByIndex(info.sourceId.slice(NODE_NAME_PREFIX.length));
this.$store.commit('setLastSelectedNode', sourceNodeName); this.$store.commit('setLastSelectedNode', sourceNodeName);
const sourceInfo = info.getParameters();
this.$store.commit('setLastSelectedNodeOutputIndex', sourceInfo.index);
// Display the node-creator // Display the node-creator
this.createNodeActive = true; this.createNodeActive = true;
}); });