🔃Add unction getCurrentNodeParameters to get currents parameters in loading function

This commit is contained in:
BenoitTallandier 2019-10-20 20:55:49 +02:00
parent 94d91ff9e8
commit 02a7d92fc1
7 changed files with 39 additions and 9 deletions

View file

@ -525,6 +525,7 @@ class App {
this.app.get('/rest/node-parameter-options', ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<INodePropertyOptions[]> => { this.app.get('/rest/node-parameter-options', ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<INodePropertyOptions[]> => {
const nodeType = req.query.nodeType; const nodeType = req.query.nodeType;
let credentials: INodeCredentials | undefined = undefined; let credentials: INodeCredentials | undefined = undefined;
const currentNodeParameters = req.query.currentNodeParameters;
if (req.query.credentials !== undefined) { if (req.query.credentials !== undefined) {
credentials = JSON.parse(req.query.credentials); credentials = JSON.parse(req.query.credentials);
} }
@ -537,7 +538,7 @@ class App {
const workflowData = loadDataInstance.getWorkflowData() as IWorkflowBase; const workflowData = loadDataInstance.getWorkflowData() as IWorkflowBase;
const workflowCredentials = await WorkflowCredentials(workflowData.nodes); const workflowCredentials = await WorkflowCredentials(workflowData.nodes);
const additionalData = await WorkflowExecuteAdditionalData.getBase(executionMode, workflowCredentials); const additionalData = await WorkflowExecuteAdditionalData.getBase(executionMode, workflowCredentials,currentNodeParameters);
return loadDataInstance.getOptions(methodName, additionalData); return loadDataInstance.getOptions(methodName, additionalData);
})); }));

View file

@ -23,6 +23,7 @@ import {
IWorkflowExecuteAdditionalData, IWorkflowExecuteAdditionalData,
IWorkflowExecuteHooks, IWorkflowExecuteHooks,
WorkflowExecuteMode, WorkflowExecuteMode,
INodeParameters,
} from 'n8n-workflow'; } from 'n8n-workflow';
import * as config from '../config'; import * as config from '../config';
@ -245,7 +246,7 @@ const hooks = (mode: WorkflowExecuteMode, workflowData: IWorkflowBase, execution
* @param {IWorkflowCredentials} credentials * @param {IWorkflowCredentials} credentials
* @returns {Promise<IWorkflowExecuteAdditionalData>} * @returns {Promise<IWorkflowExecuteAdditionalData>}
*/ */
export async function getBase(mode: WorkflowExecuteMode, credentials: IWorkflowCredentials): Promise<IWorkflowExecuteAdditionalData> { export async function getBase(mode: WorkflowExecuteMode, credentials: IWorkflowCredentials,currentNodeParameters: INodeParameters[] = []): Promise<IWorkflowExecuteAdditionalData> {
const urlBaseWebhook = WebhookHelpers.getWebhookBaseUrl(); const urlBaseWebhook = WebhookHelpers.getWebhookBaseUrl();
const timezone = config.get('generic.timezone') as string; const timezone = config.get('generic.timezone') as string;
@ -263,6 +264,7 @@ export async function getBase(mode: WorkflowExecuteMode, credentials: IWorkflowC
timezone, timezone,
webhookBaseUrl, webhookBaseUrl,
webhookTestBaseUrl, webhookTestBaseUrl,
currentNodeParameters
}; };
} }

View file

@ -513,6 +513,13 @@ export function getLoadOptionsFunctions(workflow: Workflow, node: INode, additio
getCredentials(type: string): ICredentialDataDecryptedObject | undefined { getCredentials(type: string): ICredentialDataDecryptedObject | undefined {
return getCredentials(workflow, node, type, additionalData); return getCredentials(workflow, node, type, additionalData);
}, },
getCurrentNodeParameters : (parameterName : string): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => {
const nodeParameters = JSON.parse(''+additionalData.currentNodeParameters);
if(nodeParameters && nodeParameters[parameterName] ){
return nodeParameters[parameterName];
}
return false;
},
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
const runExecutionData: IRunExecutionData | null = null; const runExecutionData: IRunExecutionData | null = null;
const itemIndex = 0; const itemIndex = 0;

View file

@ -53,8 +53,6 @@ declare module 'jsplumb' {
} }
} }
// EndpointOptions from jsplumb seems incomplete and wrong so we define an own one // EndpointOptions from jsplumb seems incomplete and wrong so we define an own one
export interface IEndpointOptions { export interface IEndpointOptions {
anchor?: any; // tslint:disable-line:no-any anchor?: any; // tslint:disable-line:no-any
@ -353,7 +351,6 @@ export interface IPushDataExecutionStarted {
workflowName?: string; workflowName?: string;
} }
export interface IPushDataExecutionFinished { export interface IPushDataExecutionFinished {
data: IRun; data: IRun;
executionIdActive: string; executionIdActive: string;

View file

@ -400,10 +400,9 @@ export default mixins(
}, },
methods: { methods: {
async loadRemoteParameterOptions () { async loadRemoteParameterOptions () {
if (this.node === null || this.remoteMethod === undefined) { if (this.node === null || this.remoteMethod === undefined || this.remoteParameterOptionsLoading) {
return; return;
} }
this.remoteParameterOptionsLoadingIssues = null; this.remoteParameterOptionsLoadingIssues = null;
this.remoteParameterOptionsLoading = true; this.remoteParameterOptionsLoading = true;
this.remoteParameterOptions.length = 0; this.remoteParameterOptions.length = 0;
@ -513,6 +512,28 @@ export default mixins(
this.$watch(() => this.node!.credentials, () => { this.$watch(() => this.node!.credentials, () => {
this.loadRemoteParameterOptions(); this.loadRemoteParameterOptions();
}, { deep: true, immediate: true }); }, { deep: true, immediate: true });
// Reload function on change element from
// displayOptions.typeOptions.reloadOnChange parameters
if (this.parameter.typeOptions && this.parameter.typeOptions.reloadOnChange) {
// Get all paramter in reloadOnChange property
// This reload when parameters in reloadOnChange is updated
const paramtersOnChange : string[] = this.parameter.typeOptions.reloadOnChange;
for (let i = 0; i < paramtersOnChange.length; i++) {
const parameter = paramtersOnChange[i] as string;
if (parameter in this.node.parameters) {
this.$watch(() => {
if (this.node && this.node.parameters && this.node.parameters[parameter]) {
return this.node.parameters![parameter];
} else {
return null;
}
}, () => {
this.loadRemoteParameterOptions();
}, { deep: true, immediate: true });
}
}
}
} }
}, },
}); });

View file

@ -157,8 +157,8 @@ export const restApi = Vue.extend({
nodeType, nodeType,
methodName, methodName,
credentials, credentials,
currentNodeParameters : this.$store.getters.activeNode.parameters,
}; };
return self.restApi().makeRestApiRequest('GET', '/node-parameter-options', sendData); return self.restApi().makeRestApiRequest('GET', '/node-parameter-options', sendData);
}, },

View file

@ -181,6 +181,7 @@ export interface IExecuteSingleFunctions {
export interface ILoadOptionsFunctions { export interface ILoadOptionsFunctions {
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
getCurrentNodeParameters(parameterName: string): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object;
getTimezone(): string; getTimezone(): string;
helpers: { helpers: {
[key: string]: ((...args: any[]) => any) | undefined; //tslint:disable-line:no-any [key: string]: ((...args: any[]) => any) | undefined; //tslint:disable-line:no-any
@ -290,7 +291,7 @@ export type NodeParameterValue = string | number | boolean;
export interface INodeParameters { export interface INodeParameters {
// TODO: Later also has to be possible to add multiple ones with the name name. So array has to be possible // TODO: Later also has to be possible to add multiple ones with the name name. So array has to be possible
[key: string]: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]; [key: string]: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] ;
} }
@ -597,6 +598,7 @@ export interface IWorkflowExecuteAdditionalData {
timezone: string; timezone: string;
webhookBaseUrl: string; webhookBaseUrl: string;
webhookTestBaseUrl: string; webhookTestBaseUrl: string;
currentNodeParameters? : INodeParameters[];
} }
export type WorkflowExecuteMode = 'cli' | 'error' | 'internal' | 'manual' | 'retry' | 'trigger' | 'webhook'; export type WorkflowExecuteMode = 'cli' | 'error' | 'internal' | 'manual' | 'retry' | 'trigger' | 'webhook';