2021-08-21 05:11:32 -07:00
|
|
|
import {
|
|
|
|
PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
|
|
|
|
PLACEHOLDER_EMPTY_WORKFLOW_ID,
|
|
|
|
} from '@/constants';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
import {
|
2019-08-09 09:47:33 -07:00
|
|
|
IConnections,
|
2021-05-14 22:28:51 -07:00
|
|
|
IDataObject,
|
2019-06-23 03:35:23 -07:00
|
|
|
INode,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeIssues,
|
2021-05-14 22:28:51 -07:00
|
|
|
INodeParameters,
|
2021-05-16 17:25:04 -07:00
|
|
|
NodeParameterValue,
|
2021-08-21 05:11:32 -07:00
|
|
|
INodeCredentials,
|
2019-06-23 03:35:23 -07:00
|
|
|
INodeType,
|
2019-08-09 03:51:45 -07:00
|
|
|
INodeTypes,
|
|
|
|
INodeTypeData,
|
2019-06-23 03:35:23 -07:00
|
|
|
INodeTypeDescription,
|
|
|
|
IRunData,
|
|
|
|
IRunExecutionData,
|
|
|
|
IWorfklowIssues,
|
2021-08-21 05:11:32 -07:00
|
|
|
IWorkflowDataProxyAdditionalKeys,
|
2019-06-23 03:35:23 -07:00
|
|
|
Workflow,
|
|
|
|
NodeHelpers,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import {
|
|
|
|
IExecutionResponse,
|
|
|
|
INodeTypesMaxCount,
|
|
|
|
INodeUi,
|
|
|
|
IWorkflowData,
|
2020-07-09 13:54:50 -07:00
|
|
|
IWorkflowDb,
|
2019-07-17 07:05:01 -07:00
|
|
|
IWorkflowDataUpdate,
|
|
|
|
XYPositon,
|
2021-05-29 11:31:21 -07:00
|
|
|
ITag,
|
2019-06-23 03:35:23 -07:00
|
|
|
} from '../../Interface';
|
|
|
|
|
2021-01-19 14:48:30 -08:00
|
|
|
import { externalHooks } from '@/components/mixins/externalHooks';
|
2019-06-23 03:35:23 -07:00
|
|
|
import { restApi } from '@/components/mixins/restApi';
|
|
|
|
import { nodeHelpers } from '@/components/mixins/nodeHelpers';
|
|
|
|
import { showMessage } from '@/components/mixins/showMessage';
|
|
|
|
|
2020-07-09 13:54:50 -07:00
|
|
|
import { isEqual } from 'lodash';
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
import mixins from 'vue-typed-mixins';
|
2021-08-19 01:51:27 -07:00
|
|
|
import { v4 as uuidv4} from 'uuid';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
export const workflowHelpers = mixins(
|
2021-01-19 14:48:30 -08:00
|
|
|
externalHooks,
|
2019-06-23 03:35:23 -07:00
|
|
|
nodeHelpers,
|
|
|
|
restApi,
|
|
|
|
showMessage,
|
|
|
|
)
|
|
|
|
.extend({
|
|
|
|
methods: {
|
|
|
|
// Returns connectionInputData to be able to execute an expression.
|
|
|
|
connectionInputData (parentNode: string[], inputName: string, runIndex: number, inputIndex: number): INodeExecutionData[] | null {
|
|
|
|
let connectionInputData = null;
|
|
|
|
|
|
|
|
if (parentNode.length) {
|
|
|
|
// Add the input data to be able to also resolve the short expression format
|
|
|
|
// which does not use the node name
|
|
|
|
const parentNodeName = parentNode[0];
|
|
|
|
|
|
|
|
const workflowRunData = this.$store.getters.getWorkflowRunData as IRunData | null;
|
|
|
|
if (workflowRunData === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!workflowRunData[parentNodeName] ||
|
|
|
|
workflowRunData[parentNodeName].length <= runIndex ||
|
|
|
|
!workflowRunData[parentNodeName][runIndex].hasOwnProperty('data') ||
|
|
|
|
workflowRunData[parentNodeName][runIndex].data === undefined ||
|
|
|
|
!workflowRunData[parentNodeName][runIndex].data!.hasOwnProperty(inputName) ||
|
|
|
|
workflowRunData[parentNodeName][runIndex].data![inputName].length <= inputIndex
|
|
|
|
) {
|
|
|
|
connectionInputData = [];
|
|
|
|
} else {
|
|
|
|
connectionInputData = workflowRunData[parentNodeName][runIndex].data![inputName][inputIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return connectionInputData;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns a shallow copy of the nodes which means that all the data on the lower
|
|
|
|
// levels still only gets referenced but the top level object is a different one.
|
|
|
|
// This has the advantage that it is very fast and does not cause problems with vuex
|
|
|
|
// when the workflow replaces the node-parameters.
|
|
|
|
getNodes (): INodeUi[] {
|
|
|
|
const nodes = this.$store.getters.allNodes;
|
|
|
|
const returnNodes: INodeUi[] = [];
|
|
|
|
|
|
|
|
for (const node of nodes) {
|
|
|
|
returnNodes.push(Object.assign({}, node));
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnNodes;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns data about nodeTypes which ahve a "maxNodes" limit set.
|
|
|
|
// For each such type does it return how high the limit is, how many
|
|
|
|
// already exist and the name of this nodes.
|
|
|
|
getNodeTypesMaxCount (): INodeTypesMaxCount {
|
|
|
|
const nodes = this.$store.getters.allNodes;
|
|
|
|
|
|
|
|
const returnData: INodeTypesMaxCount = {};
|
|
|
|
|
|
|
|
const nodeTypes = this.$store.getters.allNodeTypes;
|
|
|
|
for (const nodeType of nodeTypes) {
|
|
|
|
if (nodeType.maxNodes !== undefined) {
|
|
|
|
returnData[nodeType.name] = {
|
|
|
|
exist: 0,
|
|
|
|
max: nodeType.maxNodes,
|
|
|
|
nodeNames: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const node of nodes) {
|
|
|
|
if (returnData[node.type] !== undefined) {
|
|
|
|
returnData[node.type].exist += 1;
|
|
|
|
returnData[node.type].nodeNames.push(node.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns how many nodes of the given type currently exist
|
|
|
|
getNodeTypeCount (nodeType: string): number {
|
|
|
|
const nodes = this.$store.getters.allNodes;
|
|
|
|
|
|
|
|
let count = 0;
|
|
|
|
|
|
|
|
for (const node of nodes) {
|
|
|
|
if (node.type === nodeType) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Checks if everything in the workflow is complete and ready to be executed
|
|
|
|
checkReadyForExecution (workflow: Workflow) {
|
|
|
|
let node: INode;
|
|
|
|
let nodeType: INodeType | undefined;
|
|
|
|
let nodeIssues: INodeIssues | null = null;
|
|
|
|
const workflowIssues: IWorfklowIssues = {};
|
|
|
|
|
|
|
|
for (const nodeName of Object.keys(workflow.nodes)) {
|
|
|
|
nodeIssues = null;
|
|
|
|
node = workflow.nodes[nodeName];
|
|
|
|
|
|
|
|
if (node.disabled === true) {
|
2019-07-07 10:17:34 -07:00
|
|
|
// Ignore issues on disabled nodes
|
2019-06-23 03:35:23 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeType = workflow.nodeTypes.getByName(node.type);
|
|
|
|
|
|
|
|
if (nodeType === undefined) {
|
|
|
|
// Node type is not known
|
|
|
|
nodeIssues = {
|
|
|
|
typeUnknown: true,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
nodeIssues = this.getNodeIssues(nodeType.description, node, ['execution']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nodeIssues !== null) {
|
|
|
|
workflowIssues[node.name] = nodeIssues;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object.keys(workflowIssues).length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return workflowIssues;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns a workflow instance.
|
2019-08-09 09:47:33 -07:00
|
|
|
getWorkflow (nodes?: INodeUi[], connections?: IConnections, copyData?: boolean): Workflow {
|
|
|
|
nodes = nodes || this.getNodes();
|
|
|
|
connections = connections || (this.$store.getters.allConnections as IConnections);
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2019-08-09 03:51:45 -07:00
|
|
|
const nodeTypes: INodeTypes = {
|
|
|
|
nodeTypes: {},
|
|
|
|
init: async (nodeTypes?: INodeTypeData): Promise<void> => { },
|
|
|
|
getAll: (): INodeType[] => {
|
2019-06-23 03:35:23 -07:00
|
|
|
// Does not get used in Workflow so no need to return it
|
|
|
|
return [];
|
|
|
|
},
|
2019-08-09 03:51:45 -07:00
|
|
|
getByName: (nodeType: string): INodeType | undefined => {
|
2019-06-23 03:35:23 -07:00
|
|
|
const nodeTypeDescription = this.$store.getters.nodeType(nodeType);
|
|
|
|
|
|
|
|
if (nodeTypeDescription === null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
description: nodeTypeDescription,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let workflowId = this.$store.getters.workflowId;
|
2020-02-15 17:07:01 -08:00
|
|
|
if (workflowId === PLACEHOLDER_EMPTY_WORKFLOW_ID) {
|
2019-06-23 03:35:23 -07:00
|
|
|
workflowId = undefined;
|
|
|
|
}
|
|
|
|
|
2020-02-15 17:07:01 -08:00
|
|
|
const workflowName = this.$store.getters.workflowName;
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
if (copyData === true) {
|
2020-02-15 17:07:01 -08:00
|
|
|
return new Workflow({ id: workflowId, name: workflowName, nodes: JSON.parse(JSON.stringify(nodes)), connections: JSON.parse(JSON.stringify(connections)), active: false, nodeTypes});
|
2019-06-23 03:35:23 -07:00
|
|
|
} else {
|
2020-02-15 17:07:01 -08:00
|
|
|
return new Workflow({ id: workflowId, name: workflowName, nodes, connections, active: false, nodeTypes});
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns the currently loaded workflow as JSON.
|
|
|
|
getWorkflowDataToSave (): Promise<IWorkflowData> {
|
|
|
|
const workflowNodes = this.$store.getters.allNodes;
|
|
|
|
const workflowConnections = this.$store.getters.allConnections;
|
|
|
|
|
|
|
|
let nodeData;
|
|
|
|
|
|
|
|
const nodes = [];
|
|
|
|
for (let nodeIndex = 0; nodeIndex < workflowNodes.length; nodeIndex++) {
|
|
|
|
try {
|
|
|
|
// @ts-ignore
|
|
|
|
nodeData = this.getNodeDataToSave(workflowNodes[nodeIndex]);
|
|
|
|
} catch (e) {
|
|
|
|
return Promise.reject(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes.push(nodeData);
|
|
|
|
}
|
|
|
|
|
|
|
|
const data: IWorkflowData = {
|
|
|
|
name: this.$store.getters.workflowName,
|
|
|
|
nodes,
|
|
|
|
connections: workflowConnections,
|
|
|
|
active: this.$store.getters.isActive,
|
|
|
|
settings: this.$store.getters.workflowSettings,
|
2021-05-29 11:31:21 -07:00
|
|
|
tags: this.$store.getters.workflowTags,
|
2019-06-23 03:35:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const workflowId = this.$store.getters.workflowId;
|
|
|
|
if (workflowId !== PLACEHOLDER_EMPTY_WORKFLOW_ID) {
|
|
|
|
data.id = workflowId;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve(data);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns all node-types
|
|
|
|
getNodeDataToSave (node: INodeUi): INodeUi {
|
|
|
|
const skipKeys = [
|
|
|
|
'color',
|
|
|
|
'continueOnFail',
|
|
|
|
'credentials',
|
|
|
|
'disabled',
|
|
|
|
'issues',
|
|
|
|
'notes',
|
|
|
|
'parameters',
|
|
|
|
'status',
|
|
|
|
];
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const nodeData: INodeUi = {
|
|
|
|
parameters: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const key in node) {
|
|
|
|
if (key.charAt(0) !== '_' && skipKeys.indexOf(key) === -1) {
|
|
|
|
// @ts-ignore
|
|
|
|
nodeData[key] = node[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the data of the node type that we can get the default values
|
|
|
|
// TODO: Later also has to care about the node-type-version as defaults could be different
|
|
|
|
const nodeType = this.$store.getters.nodeType(node.type) as INodeTypeDescription;
|
|
|
|
|
|
|
|
if (nodeType !== null) {
|
|
|
|
// Node-Type is known so we can save the parameters correctly
|
|
|
|
|
|
|
|
const nodeParameters = NodeHelpers.getNodeParameters(nodeType.properties, node.parameters, false, false);
|
|
|
|
nodeData.parameters = nodeParameters !== null ? nodeParameters : {};
|
|
|
|
|
|
|
|
// Add the node credentials if there are some set and if they should be displayed
|
|
|
|
if (node.credentials !== undefined && nodeType.credentials !== undefined) {
|
|
|
|
const saveCredenetials: INodeCredentials = {};
|
|
|
|
for (const nodeCredentialTypeName of Object.keys(node.credentials)) {
|
|
|
|
const credentialTypeDescription = nodeType.credentials
|
|
|
|
.find((credentialTypeDescription) => credentialTypeDescription.name === nodeCredentialTypeName);
|
|
|
|
|
|
|
|
if (credentialTypeDescription === undefined) {
|
|
|
|
// Credential type is not know so do not save
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.displayParameter(node.parameters, credentialTypeDescription, '') === false) {
|
|
|
|
// Credential should not be displayed so do also not save
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
saveCredenetials[nodeCredentialTypeName] = node.credentials[nodeCredentialTypeName];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set credential property only if it has content
|
|
|
|
if (Object.keys(saveCredenetials).length !== 0) {
|
|
|
|
nodeData.credentials = saveCredenetials;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the node color only if it is different to the default color
|
|
|
|
if (node.color && node.color !== nodeType.defaults.color) {
|
|
|
|
nodeData.color = node.color;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Node-Type is not known so save the data as it is
|
|
|
|
nodeData.credentials = node.credentials;
|
|
|
|
nodeData.parameters = node.parameters;
|
|
|
|
if (nodeData.color !== undefined) {
|
|
|
|
nodeData.color = node.color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the disabled property and continueOnFail only when is set
|
|
|
|
if (node.disabled === true) {
|
|
|
|
nodeData.disabled = true;
|
|
|
|
}
|
|
|
|
if (node.continueOnFail === true) {
|
|
|
|
nodeData.continueOnFail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the notes only if when they contain data
|
|
|
|
if (![undefined, ''].includes(node.notes)) {
|
|
|
|
nodeData.notes = node.notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodeData;
|
|
|
|
},
|
|
|
|
|
2021-05-16 17:25:04 -07:00
|
|
|
|
|
|
|
resolveParameter(parameter: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]) {
|
2019-06-23 03:35:23 -07:00
|
|
|
const inputIndex = 0;
|
|
|
|
const itemIndex = 0;
|
|
|
|
const runIndex = 0;
|
|
|
|
const inputName = 'main';
|
|
|
|
const activeNode = this.$store.getters.activeNode;
|
|
|
|
const workflow = this.getWorkflow();
|
|
|
|
const parentNode = workflow.getParentNodes(activeNode.name, inputName, 1);
|
|
|
|
const executionData = this.$store.getters.getWorkflowExecution as IExecutionResponse | null;
|
|
|
|
let connectionInputData = this.connectionInputData(parentNode, inputName, runIndex, inputIndex);
|
|
|
|
|
|
|
|
let runExecutionData: IRunExecutionData;
|
|
|
|
if (executionData === null) {
|
|
|
|
runExecutionData = {
|
|
|
|
resultData: {
|
|
|
|
runData: {},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
runExecutionData = executionData.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connectionInputData === null) {
|
|
|
|
connectionInputData = [];
|
|
|
|
}
|
|
|
|
|
2021-08-21 05:11:32 -07:00
|
|
|
const additionalKeys: IWorkflowDataProxyAdditionalKeys = {
|
|
|
|
$executionId: PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
|
|
|
|
$resumeWebhookUrl: PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
|
|
|
|
};
|
|
|
|
|
|
|
|
return workflow.expression.getParameterValue(parameter, runExecutionData, runIndex, itemIndex, activeNode.name, connectionInputData, 'manual', additionalKeys, false) as IDataObject;
|
2021-05-16 17:25:04 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
resolveExpression(expression: string, siblingParameters: INodeParameters = {}) {
|
|
|
|
|
2021-05-14 22:28:51 -07:00
|
|
|
const parameters = {
|
|
|
|
'__xxxxxxx__': expression,
|
|
|
|
...siblingParameters,
|
|
|
|
};
|
2021-05-16 17:25:04 -07:00
|
|
|
const returnData = this.resolveParameter(parameters) as IDataObject;
|
2021-05-14 22:28:51 -07:00
|
|
|
|
|
|
|
if (typeof returnData['__xxxxxxx__'] === 'object') {
|
2021-05-16 17:25:04 -07:00
|
|
|
const workflow = this.getWorkflow();
|
2021-05-14 22:28:51 -07:00
|
|
|
return workflow.expression.convertObjectValueToString(returnData['__xxxxxxx__'] as object);
|
|
|
|
}
|
|
|
|
return returnData['__xxxxxxx__'];
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
async saveCurrentWorkflow({name, tags}: {name?: string, tags?: string[]} = {}): Promise<boolean> {
|
2019-06-23 03:35:23 -07:00
|
|
|
const currentWorkflow = this.$route.params.name;
|
2021-05-29 11:31:21 -07:00
|
|
|
if (!currentWorkflow) {
|
|
|
|
return this.saveAsNewWorkflow({name, tags});
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
// Workflow exists already so update it
|
2019-06-23 03:35:23 -07:00
|
|
|
try {
|
|
|
|
this.$store.commit('addActiveAction', 'workflowSaving');
|
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
const workflowDataRequest: IWorkflowDataUpdate = await this.getWorkflowDataToSave();
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
if (name) {
|
|
|
|
workflowDataRequest.name = name.trim();
|
|
|
|
}
|
2019-07-17 03:20:26 -07:00
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
if (tags) {
|
|
|
|
workflowDataRequest.tags = tags;
|
|
|
|
}
|
2019-07-17 03:20:26 -07:00
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
const workflowData = await this.restApi().updateWorkflow(currentWorkflow, workflowDataRequest);
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
if (name) {
|
|
|
|
this.$store.commit('setWorkflowName', {newName: workflowData.name});
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
if (tags) {
|
|
|
|
const createdTags = (workflowData.tags || []) as ITag[];
|
|
|
|
const tagIds = createdTags.map((tag: ITag): string => tag.id);
|
|
|
|
this.$store.commit('setWorkflowTagIds', tagIds);
|
2019-10-04 03:43:48 -07:00
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2020-09-01 07:06:08 -07:00
|
|
|
this.$store.commit('setStateDirty', false);
|
2021-05-29 11:31:21 -07:00
|
|
|
this.$store.commit('removeActiveAction', 'workflowSaving');
|
|
|
|
this.$externalHooks().run('workflow.afterUpdate', { workflowData });
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
this.$store.commit('removeActiveAction', 'workflowSaving');
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
this.$showMessage({
|
2021-05-29 11:31:21 -07:00
|
|
|
title: 'Problem saving workflow',
|
|
|
|
message: `There was a problem saving the workflow: "${e.message}"`,
|
|
|
|
type: 'error',
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-08-19 06:26:38 -07:00
|
|
|
async saveAsNewWorkflow ({name, tags, resetWebhookUrls}: {name?: string, tags?: string[], resetWebhookUrls?: boolean} = {}): Promise<boolean> {
|
2021-05-29 11:31:21 -07:00
|
|
|
try {
|
|
|
|
this.$store.commit('addActiveAction', 'workflowSaving');
|
|
|
|
|
|
|
|
const workflowDataRequest: IWorkflowDataUpdate = await this.getWorkflowDataToSave();
|
|
|
|
// make sure that the new ones are not active
|
|
|
|
workflowDataRequest.active = false;
|
2021-08-19 06:26:38 -07:00
|
|
|
if (resetWebhookUrls) {
|
|
|
|
workflowDataRequest.nodes = workflowDataRequest.nodes!.map(node => {
|
2021-08-19 01:51:27 -07:00
|
|
|
if (node.webhookId) {
|
|
|
|
node.webhookId = uuidv4();
|
|
|
|
}
|
2021-08-19 06:26:38 -07:00
|
|
|
return node;
|
2021-08-19 01:51:27 -07:00
|
|
|
});
|
|
|
|
}
|
2021-05-29 11:31:21 -07:00
|
|
|
|
|
|
|
if (name) {
|
|
|
|
workflowDataRequest.name = name.trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tags) {
|
|
|
|
workflowDataRequest.tags = tags;
|
|
|
|
}
|
|
|
|
const workflowData = await this.restApi().createNewWorkflow(workflowDataRequest);
|
|
|
|
|
2021-08-19 01:51:27 -07:00
|
|
|
this.$store.commit('setWorkflow', workflowData);
|
2021-05-29 11:31:21 -07:00
|
|
|
this.$store.commit('setWorkflowName', {newName: workflowData.name, setStateDirty: false});
|
|
|
|
this.$store.commit('setStateDirty', false);
|
|
|
|
|
|
|
|
const createdTags = (workflowData.tags || []) as ITag[];
|
|
|
|
const tagIds = createdTags.map((tag: ITag): string => tag.id);
|
|
|
|
this.$store.commit('setWorkflowTagIds', tagIds);
|
|
|
|
|
|
|
|
this.$router.push({
|
|
|
|
name: 'NodeViewExisting',
|
|
|
|
params: { name: workflowData.id as string, action: 'workflowSave' },
|
2019-06-23 03:35:23 -07:00
|
|
|
});
|
2021-05-29 11:31:21 -07:00
|
|
|
|
|
|
|
this.$store.commit('removeActiveAction', 'workflowSaving');
|
|
|
|
this.$store.commit('setStateDirty', false);
|
2021-01-19 14:48:30 -08:00
|
|
|
this.$externalHooks().run('workflow.afterUpdate', { workflowData });
|
2021-05-29 11:31:21 -07:00
|
|
|
|
|
|
|
return true;
|
2019-06-23 03:35:23 -07:00
|
|
|
} catch (e) {
|
|
|
|
this.$store.commit('removeActiveAction', 'workflowSaving');
|
|
|
|
|
|
|
|
this.$showMessage({
|
|
|
|
title: 'Problem saving workflow',
|
|
|
|
message: `There was a problem saving the workflow: "${e.message}"`,
|
|
|
|
type: 'error',
|
|
|
|
});
|
2021-05-29 11:31:21 -07:00
|
|
|
|
|
|
|
return false;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
},
|
2019-07-17 07:05:01 -07:00
|
|
|
|
|
|
|
// Updates the position of all the nodes that the top-left node
|
|
|
|
// is at the given position
|
|
|
|
updateNodePositions (workflowData: IWorkflowData | IWorkflowDataUpdate, position: XYPositon): void {
|
|
|
|
if (workflowData.nodes === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find most top-left node
|
|
|
|
const minPosition = [99999999, 99999999];
|
|
|
|
for (const node of workflowData.nodes) {
|
|
|
|
if (node.position[1] < minPosition[1]) {
|
|
|
|
minPosition[0] = node.position[0];
|
|
|
|
minPosition[1] = node.position[1];
|
|
|
|
} else if (node.position[1] === minPosition[1]) {
|
|
|
|
if (node.position[0] < minPosition[0]) {
|
|
|
|
minPosition[0] = node.position[0];
|
|
|
|
minPosition[1] = node.position[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the position on all nodes so that the
|
|
|
|
// most top-left one is at given position
|
|
|
|
const offsetPosition = [position[0] - minPosition[0], position[1] - minPosition[1]];
|
|
|
|
for (const node of workflowData.nodes) {
|
|
|
|
node.position[0] += offsetPosition[0];
|
|
|
|
node.position[1] += offsetPosition[1];
|
|
|
|
}
|
|
|
|
},
|
2020-07-09 13:54:50 -07:00
|
|
|
async dataHasChanged(id: string) {
|
|
|
|
const currentData = await this.getWorkflowDataToSave();
|
|
|
|
|
|
|
|
let data: IWorkflowDb;
|
|
|
|
data = await this.restApi().getWorkflow(id);
|
|
|
|
|
|
|
|
if(data !== undefined) {
|
|
|
|
const x = {
|
|
|
|
nodes: data.nodes,
|
|
|
|
connections: data.connections,
|
|
|
|
settings: data.settings,
|
2020-09-01 07:06:08 -07:00
|
|
|
name: data.name,
|
2020-07-09 13:54:50 -07:00
|
|
|
};
|
|
|
|
const y = {
|
|
|
|
nodes: currentData.nodes,
|
|
|
|
connections: currentData.connections,
|
|
|
|
settings: currentData.settings,
|
2020-09-01 07:06:08 -07:00
|
|
|
name: currentData.name,
|
2020-07-09 13:54:50 -07:00
|
|
|
};
|
|
|
|
return !isEqual(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
});
|