mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-28 12:50:50 -08:00
refactor js plumb
This commit is contained in:
parent
81565b5621
commit
4f7875ddb5
|
@ -952,28 +952,6 @@ export default mixins(
|
||||||
this.nodeSelectedByName(lastSelectedNode.name);
|
this.nodeSelectedByName(lastSelectedNode.name);
|
||||||
},
|
},
|
||||||
|
|
||||||
// getJSPlumbConnection (sourceNodeName: string, targetNodeName: string, sourceOutputIndex: number, targetInputIndex: number): Connection | undefined {
|
|
||||||
// const sourceIndex = this.getNodeIndex(sourceNodeName);
|
|
||||||
// const sourceId = `${NODE_NAME_PREFIX}${sourceIndex}`;
|
|
||||||
|
|
||||||
// const targetIndex = this.getNodeIndex(targetNodeName);
|
|
||||||
// const targetId = `${NODE_NAME_PREFIX}${targetIndex}`;
|
|
||||||
|
|
||||||
// const sourceEndpoint = `${sourceIndex}-output${sourceOutputIndex}`;
|
|
||||||
// const targetEndpoint = `${targetIndex}-input${targetInputIndex}`;
|
|
||||||
|
|
||||||
// // @ts-ignore
|
|
||||||
// const connections = this.instance.getConnections({
|
|
||||||
// source: sourceId,
|
|
||||||
// target: targetId,
|
|
||||||
// }) as Connection[];
|
|
||||||
|
|
||||||
// return connections.find((connection: Connection) => {
|
|
||||||
// const uuids = connection.getUuids();
|
|
||||||
// return uuids[0] === sourceEndpoint && uuids[1] === targetEndpoint;
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
|
|
||||||
pushDownstreamNodes (sourceNodeName: string, margin: number) {
|
pushDownstreamNodes (sourceNodeName: string, margin: number) {
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getWorkflow();
|
||||||
for (const nodeName of workflow.getChildNodes(sourceNodeName)) {
|
for (const nodeName of workflow.getChildNodes(sourceNodeName)) {
|
||||||
|
@ -1922,6 +1900,27 @@ export default mixins(
|
||||||
|
|
||||||
this.$telemetry.track('User duplicated node', { node_type: node.type, workflow_id: this.$store.getters.workflowId });
|
this.$telemetry.track('User duplicated node', { node_type: node.type, workflow_id: this.$store.getters.workflowId });
|
||||||
},
|
},
|
||||||
|
getJSPlumbConnection (sourceNodeName: string, sourceOutputIndex: number, targetNodeName: string, targetInputIndex: number): Connection | undefined {
|
||||||
|
const sourceIndex = this.getNodeIndex(sourceNodeName);
|
||||||
|
const sourceId = `${NODE_NAME_PREFIX}${sourceIndex}`;
|
||||||
|
|
||||||
|
const targetIndex = this.getNodeIndex(targetNodeName);
|
||||||
|
const targetId = `${NODE_NAME_PREFIX}${targetIndex}`;
|
||||||
|
|
||||||
|
const sourceEndpoint = `${sourceIndex}-output${sourceOutputIndex}`;
|
||||||
|
const targetEndpoint = `${targetIndex}-input${targetInputIndex}`;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
const connections = this.instance.getConnections({
|
||||||
|
source: sourceId,
|
||||||
|
target: targetId,
|
||||||
|
}) as Connection[];
|
||||||
|
|
||||||
|
return connections.find((connection: Connection) => {
|
||||||
|
const uuids = connection.getUuids();
|
||||||
|
return uuids[0] === sourceEndpoint && uuids[1] === targetEndpoint;
|
||||||
|
});
|
||||||
|
},
|
||||||
onNodeMoved (node: INodeUi) {
|
onNodeMoved (node: INodeUi) {
|
||||||
const name = `${NODE_NAME_PREFIX}${this.$store.getters.getNodeIndex(node.name)}`;
|
const name = `${NODE_NAME_PREFIX}${this.$store.getters.getNodeIndex(node.name)}`;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -1940,7 +1939,8 @@ export default mixins(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onNodeRun ({name, data}: {name: string, data: ITaskData[] | null}) {
|
onNodeRun ({name, data}: {name: string, data: ITaskData[] | null}) {
|
||||||
const sourceIndex = this.$store.getters.getNodeIndex(name);
|
const sourceNodeName = name;
|
||||||
|
const sourceIndex = this.$store.getters.getNodeIndex(sourceNodeName);
|
||||||
const sourceId = `${NODE_NAME_PREFIX}${sourceIndex}`;
|
const sourceId = `${NODE_NAME_PREFIX}${sourceIndex}`;
|
||||||
|
|
||||||
if (data === null || data.length === 0) {
|
if (data === null || data.length === 0) {
|
||||||
|
@ -1957,12 +1957,12 @@ export default mixins(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeConnections = (this.$store.getters.outgoingConnectionsByNodeName(name) as INodeConnections).main;
|
const nodeConnections = (this.$store.getters.outgoingConnectionsByNodeName(sourceNodeName) as INodeConnections).main;
|
||||||
if (!nodeConnections) {
|
if (!nodeConnections) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputMap: {[sourceEndpoint: string]: {[targetId: string]: {[targetEndpoint: string]: {total: number, iterations: number}}}} = {};
|
const outputMap: {[sourceOutputIndex: string]: {[targetNodeName: string]: {[targetInputIndex: string]: {total: number, iterations: number}}}} = {};
|
||||||
|
|
||||||
data.forEach((run: ITaskData) => {
|
data.forEach((run: ITaskData) => {
|
||||||
if (!run.data || !run.data.main) {
|
if (!run.data || !run.data.main) {
|
||||||
|
@ -1976,53 +1976,41 @@ export default mixins(
|
||||||
|
|
||||||
nodeConnections[i]
|
nodeConnections[i]
|
||||||
.map((conn: IConnection) => {
|
.map((conn: IConnection) => {
|
||||||
const targetIndex = this.getNodeIndex(conn.node);
|
const sourceOutputIndex = i;
|
||||||
const targetId = `${NODE_NAME_PREFIX}${targetIndex}`;
|
const targetNodeName = conn.node;
|
||||||
|
const targetInputIndex = conn.index;
|
||||||
|
|
||||||
const sourceEndpoint = `${sourceIndex}-output${i}`;
|
if (!outputMap[sourceOutputIndex]) {
|
||||||
const targetEndpoint = `${targetIndex}-input${conn.index}`;
|
outputMap[sourceOutputIndex] = {};
|
||||||
|
|
||||||
if (!outputMap[sourceEndpoint]) {
|
|
||||||
outputMap[sourceEndpoint] = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!outputMap[sourceEndpoint][targetId]) {
|
if (!outputMap[sourceOutputIndex][targetNodeName]) {
|
||||||
outputMap[sourceEndpoint][targetId] = {};
|
outputMap[sourceOutputIndex][targetNodeName] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!outputMap[sourceEndpoint][targetId][targetEndpoint]) {
|
if (!outputMap[sourceOutputIndex][targetNodeName][targetInputIndex]) {
|
||||||
outputMap[sourceEndpoint][targetId][targetEndpoint] = {
|
outputMap[sourceOutputIndex][targetNodeName][targetInputIndex] = {
|
||||||
total: 0,
|
total: 0,
|
||||||
iterations: 0,
|
iterations: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
outputMap[sourceEndpoint][targetId][targetEndpoint].total += output ? output.length : 0;
|
outputMap[sourceOutputIndex][targetNodeName][targetInputIndex].total += output ? output.length : 0;
|
||||||
outputMap[sourceEndpoint][targetId][targetEndpoint].iterations += output ? 1 : 0;
|
outputMap[sourceOutputIndex][targetNodeName][targetInputIndex].iterations += output ? 1 : 0;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(outputMap).forEach((sourceEndpoint: string) => {
|
Object.keys(outputMap).forEach((sourceOutputIndex: string) => {
|
||||||
Object.keys(outputMap[sourceEndpoint]).forEach((targetId: string) => {
|
Object.keys(outputMap[sourceOutputIndex]).forEach((targetNodeName: string) => {
|
||||||
Object.keys(outputMap[sourceEndpoint][targetId]).forEach((targetEndpoint: string) => {
|
Object.keys(outputMap[sourceOutputIndex][targetNodeName]).forEach((targetInputIndex: string) => {
|
||||||
// @ts-ignore
|
const conn = this.getJSPlumbConnection(sourceNodeName, parseInt(sourceOutputIndex, 10), targetNodeName, parseInt(targetInputIndex, 10));
|
||||||
const connections = this.instance.getConnections({
|
|
||||||
source: sourceId,
|
|
||||||
target: targetId,
|
|
||||||
}) as Connection[];
|
|
||||||
|
|
||||||
const conn = connections.find((connection: Connection) => {
|
|
||||||
// @ts-ignore
|
|
||||||
const uuids = connection.getUuids();
|
|
||||||
return uuids[0] === sourceEndpoint && uuids[1] === targetEndpoint;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const output = outputMap[sourceEndpoint][targetId][targetEndpoint];
|
const output = outputMap[sourceOutputIndex][targetNodeName][targetInputIndex];
|
||||||
if (!output || !output.total) {
|
if (!output || !output.total) {
|
||||||
conn.setPaintStyle(CONNECTOR_PAINT_STYLE_DEFAULT);
|
conn.setPaintStyle(CONNECTOR_PAINT_STYLE_DEFAULT);
|
||||||
conn.removeOverlay(OVERLAY_RUN_ITEMS_ID);
|
conn.removeOverlay(OVERLAY_RUN_ITEMS_ID);
|
||||||
|
|
Loading…
Reference in a new issue