diff --git a/packages/nodes-base/nodes/Trello/GenericFunctions.ts b/packages/nodes-base/nodes/Trello/GenericFunctions.ts index b7c65c242..c36e1aef0 100644 --- a/packages/nodes-base/nodes/Trello/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Trello/GenericFunctions.ts @@ -53,3 +53,26 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa throw error; } } + +export async function apiRequestAllItems(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query: IDataObject = {}): Promise { // tslint:disable-line:no-any + + query.limit = 30; + + query.sort = '-id'; + + const returnData: IDataObject[] = []; + + let responseData; + + do { + responseData = await apiRequest.call(this, method, endpoint, body, query); + returnData.push.apply(returnData, responseData); + if (responseData.length !== 0) { + query.before = responseData[responseData.length - 1].id; + } + } while ( + query.limit <= responseData.length + ); + + return returnData; +} diff --git a/packages/nodes-base/nodes/Trello/ListDescription.ts b/packages/nodes-base/nodes/Trello/ListDescription.ts index c2a539e28..21bd54f18 100644 --- a/packages/nodes-base/nodes/Trello/ListDescription.ts +++ b/packages/nodes-base/nodes/Trello/ListDescription.ts @@ -33,6 +33,16 @@ export const listOperations = [ value: 'get', description: 'Get the data of a list', }, + { + name: 'Get All', + value: 'getAll', + description: 'Get all the lists', + }, + { + name: 'Get Cards', + value: 'getCards', + description: 'Get all the cards in a list', + }, { name: 'Update', value: 'update', @@ -159,6 +169,89 @@ export const listFields = [ ], }, + // ---------------------------------- + // list:getCards + // ---------------------------------- + { + displayName: 'List ID', + name: 'id', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'getCards', + ], + resource: [ + 'list', + ], + }, + }, + description: 'The ID of the list to get cards.', + }, + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'list', + ], + operation: [ + 'getCards', + ], + }, + }, + default: false, + description: 'If all results should be returned or only up to a given limit.', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + default: 20, + displayOptions: { + show: { + resource: [ + 'list', + ], + operation: [ + 'getCards', + ], + returnAll: [ + false, + ], + }, + }, + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: [ + 'getCards', + ], + resource: [ + 'list', + ], + }, + }, + default: {}, + options: [ + { + displayName: 'Fields', + name: 'fields', + type: 'string', + default: 'all', + description: 'Fields to return. Either "all" or a comma-separated list of fields.', + }, + ], + }, // ---------------------------------- // list:get // ---------------------------------- @@ -207,6 +300,90 @@ export const listFields = [ ], }, + // ---------------------------------- + // list:getAll + // ---------------------------------- + { + displayName: 'Board ID', + name: 'id', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'getAll', + ], + resource: [ + 'list', + ], + }, + }, + description: 'The ID of the board', + }, + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'list', + ], + operation: [ + 'getAll', + ], + }, + }, + default: false, + description: 'If all results should be returned or only up to a given limit.', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + default: 20, + displayOptions: { + show: { + resource: [ + 'list', + ], + operation: [ + 'getAll', + ], + returnAll: [ + false, + ], + }, + }, + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: [ + 'getAll', + ], + resource: [ + 'list', + ], + }, + }, + default: {}, + options: [ + { + displayName: 'Fields', + name: 'fields', + type: 'string', + default: 'all', + description: 'Fields to return. Either "all" or a comma-separated list of fields.', + }, + ], + }, + // ---------------------------------- // list:update // ---------------------------------- diff --git a/packages/nodes-base/nodes/Trello/Trello.node.ts b/packages/nodes-base/nodes/Trello/Trello.node.ts index 99378d969..807c634d0 100644 --- a/packages/nodes-base/nodes/Trello/Trello.node.ts +++ b/packages/nodes-base/nodes/Trello/Trello.node.ts @@ -11,6 +11,7 @@ import { import { apiRequest, + apiRequestAllItems, } from './GenericFunctions'; import { @@ -52,14 +53,14 @@ export class Trello implements INodeType { description: INodeTypeDescription = { displayName: 'Trello', name: 'trello', - icon: 'file:trello.png', + icon: 'file:trello.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Create, change and delete boards and cards', defaults: { name: 'Trello', - color: '#026aa7', + color: '#0079bf', }, inputs: ['main'], outputs: ['main'], @@ -147,6 +148,8 @@ export class Trello implements INodeType { let requestMethod: string; let endpoint: string; + let returnAll = false; + let responseData; for (let i = 0; i < items.length; i++) { requestMethod = 'GET'; @@ -365,6 +368,46 @@ export class Trello implements INodeType { const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; Object.assign(qs, additionalFields); + } else if (operation === 'getAll') { + // ---------------------------------- + // getAll + // ---------------------------------- + + requestMethod = 'GET'; + + returnAll = this.getNodeParameter('returnAll', i) as boolean; + + if (returnAll === false) { + qs.limit = this.getNodeParameter('limit', i) as number; + } + + const id = this.getNodeParameter('id', i) as string; + + endpoint = `boards/${id}/lists`; + + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + Object.assign(qs, additionalFields); + + } else if (operation === 'getCards') { + // ---------------------------------- + // getCards + // ---------------------------------- + + requestMethod = 'GET'; + + returnAll = this.getNodeParameter('returnAll', i) as boolean; + + if (returnAll === false) { + qs.limit = this.getNodeParameter('limit', i) as number; + } + + const id = this.getNodeParameter('id', i) as string; + + endpoint = `lists/${id}/cards`; + + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + Object.assign(qs, additionalFields); + } else if (operation === 'update') { // ---------------------------------- // update @@ -549,7 +592,7 @@ export class Trello implements INodeType { const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; Object.assign(qs, additionalFields); - } else if (operation ==='completedCheckItems') { + } else if (operation === 'completedCheckItems') { // ---------------------------------- // completedCheckItems // ---------------------------------- @@ -673,7 +716,21 @@ export class Trello implements INodeType { throw new Error(`The resource "${resource}" is not known!`); } - const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs); + + // resources listed here do not support pagination so + // paginate them 'manually' + const skipPagination = [ + 'list:getAll', + ]; + + if (returnAll === true && !skipPagination.includes(`${resource}:${operation}`)) { + responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs); + } else { + responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs); + if (returnAll === false && qs.limit) { + responseData = responseData.splice(0, qs.limit); + } + } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]); diff --git a/packages/nodes-base/nodes/Trello/trello.png b/packages/nodes-base/nodes/Trello/trello.png deleted file mode 100644 index 2b75a6c66..000000000 Binary files a/packages/nodes-base/nodes/Trello/trello.png and /dev/null differ diff --git a/packages/nodes-base/nodes/Trello/trello.svg b/packages/nodes-base/nodes/Trello/trello.svg new file mode 100644 index 000000000..eecadb36b --- /dev/null +++ b/packages/nodes-base/nodes/Trello/trello.svg @@ -0,0 +1,22 @@ + + + + trello-mark-blue-flat + Created with Sketch. + + + + + + + + + \ No newline at end of file