1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-09-22 10:39:35 +03:00

🔀 Merge branch 'RicardoE105-feature/clickup'

This commit is contained in:
Jan Oberhauser 2020-02-06 18:41:18 -08:00
commit 121d5d6e1c
5 changed files with 321 additions and 2 deletions

View File

@ -12,11 +12,16 @@ import {
import {
clickupApiRequest,
clickupApiRequestAllItems,
validateJSON,
} from './GenericFunctions';
import {
taskFields,
taskOperations,
} from './TaskDescription';
import {
listFields,
listOperations,
} from './ListDescription';
import {
ITask,
} from './TaskInterface';
@ -48,6 +53,10 @@ export class ClickUp implements INodeType {
name: 'resource',
type: 'options',
options: [
{
name: 'List',
value: 'list',
},
{
name: 'Task',
value: 'task',
@ -58,6 +67,8 @@ export class ClickUp implements INodeType {
},
...taskOperations,
...taskFields,
...listOperations,
...listFields,
],
};
@ -212,6 +223,13 @@ export class ClickUp implements INodeType {
const body: ITask = {
name,
};
if (additionalFields.customFieldsJson) {
const customFields = validateJSON(additionalFields.customFieldsJson as string);
if (customFields === undefined) {
throw new Error('Custom Fields: Invalid JSON');
}
body.custom_fields = customFields;
}
if (additionalFields.content) {
body.content = additionalFields.content as string;
}
@ -252,7 +270,6 @@ export class ClickUp implements INodeType {
delete body.content;
body.markdown_content = additionalFields.content as string;
}
responseData = await clickupApiRequest.call(this, 'POST', `/list/${listId}/task`, body);
}
if (operation === 'update') {
@ -351,11 +368,39 @@ export class ClickUp implements INodeType {
// responseData = responseData.tasks;
}
}
if (operation === 'setCustomField') {
const taskId = this.getNodeParameter('task', i) as string;
const fieldId = this.getNodeParameter('field', i) as string;
const value = this.getNodeParameter('value', i) as string;
const jsonParse = this.getNodeParameter('jsonParse', i) as boolean;
const body: IDataObject = {};
body.value = value;
if (jsonParse === true) {
body.value = validateJSON(body.value);
if (body.value === undefined) {
throw new Error('Value is invalid JSON!');
}
} else {
//@ts-ignore
if (!isNaN(body.value)) {
body.value = parseInt(body.value, 10);
}
}
responseData = await clickupApiRequest.call(this, 'POST', `/task/${taskId}/field/${fieldId}`, body);
}
if (operation === 'delete') {
const taskId = this.getNodeParameter('id', i) as string;
responseData = await clickupApiRequest.call(this, 'DELETE', `/task/${taskId}`, {});
}
}
if (resource === 'list') {
if (operation === 'customFields') {
const listId = this.getNodeParameter('list', i) as string;
responseData = await clickupApiRequest.call(this, 'GET', `/list/${listId}/field`);
responseData = responseData.fields;
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {

View File

@ -54,3 +54,13 @@ export async function clickupApiRequestAllItems(this: IHookFunctions | IExecuteF
);
return returnData;
}
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
let result;
try {
result = JSON.parse(json!);
} catch (exception) {
result = undefined;
}
return result;
}

View File

@ -0,0 +1,170 @@
import { INodeProperties } from 'n8n-workflow';
export const listOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'list',
],
},
},
options: [
{
name: 'Custom Fields',
value: 'customFields',
description: `Retrieve list's custom fields`,
},
],
default: 'customFields',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const listFields = [
/* -------------------------------------------------------------------------- */
/* list:customFields */
/* -------------------------------------------------------------------------- */
{
displayName: 'Team',
name: 'team',
type: 'options',
default: '',
displayOptions: {
show: {
resource: [
'list',
],
operation: [
'customFields',
],
},
},
typeOptions: {
loadOptionsMethod: 'getTeams',
},
required: true,
},
{
displayName: 'Space',
name: 'space',
type: 'options',
default: '',
displayOptions: {
show: {
resource: [
'list',
],
operation: [
'customFields',
],
},
},
typeOptions: {
loadOptionsMethod: 'getSpaces',
loadOptionsDependsOn: [
'team',
]
},
required: true,
},
{
displayName: 'Folderless List',
name: 'folderless',
type: 'boolean',
default: false,
displayOptions: {
show: {
resource: [
'list',
],
operation: [
'customFields',
],
},
},
required: true,
},
{
displayName: 'Folder',
name: 'folder',
type: 'options',
default: '',
displayOptions: {
show: {
resource: [
'list',
],
operation: [
'customFields',
],
folderless: [
false,
],
},
},
typeOptions: {
loadOptionsMethod: 'getFolders',
loadOptionsDependsOn: [
'space',
],
},
required: true,
},
{
displayName: 'List',
name: 'list',
type: 'options',
default: '',
displayOptions: {
show: {
resource: [
'list',
],
operation: [
'customFields',
],
folderless: [
true,
],
},
},
typeOptions: {
loadOptionsMethod: 'getFolderlessLists',
loadOptionsDependsOn: [
'space',
],
},
required: true,
},
{
displayName: 'List',
name: 'list',
type: 'options',
default: '',
displayOptions: {
show: {
resource: [
'list',
],
operation: [
'customFields',
],
folderless: [
false,
],
},
},
typeOptions: {
loadOptionsMethod: 'getLists',
loadOptionsDependsOn: [
'folder',
]
},
required: true,
},
] as INodeProperties[];

View File

@ -33,6 +33,11 @@ export const taskOperations = [
value: 'getAll',
description: 'Get all tasks',
},
{
name: 'Set custom field',
value: 'setCustomField',
description: 'Set a custom field',
},
{
name: 'Update',
value: 'update',
@ -235,6 +240,16 @@ export const taskFields = [
default: [],
},
{
displayName: 'Custom Fields JSON',
name: 'customFieldsJson',
type: 'json',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Custom fields to set as JSON in the format:<br />[{"id": "", "value": ""}]',
},
{
displayName: 'Content',
name: 'content',
@ -721,7 +736,7 @@ export const taskFields = [
name: 'includeClosed',
type: 'boolean',
default: false,
description: 'the api does not include closed tasks. Set this to true and dont send a status filter to include closed tasks',
description: 'The response does by default not include closed tasks. Set this to true and dont send a status filter to include closed tasks.',
},
{
displayName: 'Order By',
@ -802,4 +817,80 @@ export const taskFields = [
},
description: 'task ID',
},
/* -------------------------------------------------------------------------- */
/* task:setCustomField */
/* -------------------------------------------------------------------------- */
{
displayName: 'Task ID',
name: 'task',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'task',
],
operation: [
'setCustomField',
],
},
},
description: 'The ID of the task to add custom field to.',
},
{
displayName: 'Field ID',
name: 'field',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'task',
],
operation: [
'setCustomField',
],
},
},
description: 'The ID of the field to add custom field to.',
},
{
displayName: 'Value is JSON',
name: 'jsonParse',
type: 'boolean',
displayOptions: {
show: {
resource: [
'task',
],
operation: [
'setCustomField',
]
},
},
default: false,
description: `The value is JSON and will be parsed as such. Is needed<br />
if for example needed for labels which expects the value<br />
to be an array.`,
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'task',
],
operation: [
'setCustomField',
],
},
},
description: 'The value to set on custom field.',
},
] as INodeProperties[];

View File

@ -1,3 +1,5 @@
import { IDataObject } from "n8n-workflow";
export interface ITask {
name?: string;
content?: string;
@ -13,4 +15,5 @@ export interface ITask {
markdown_content?: string;
notify_all?: boolean;
parent?: string;
custom_fields?: IDataObject[];
}