Small improvements on Cockpit-Node

This commit is contained in:
Jan Oberhauser 2020-04-06 10:03:49 +02:00
parent 30e5960248
commit 7e17486383
6 changed files with 84 additions and 58 deletions

View file

@ -26,7 +26,7 @@ import {
singletonOperations, singletonOperations,
} from './SingletonDescription'; } from './SingletonDescription';
import { import {
getAllSingleton, getSingleton,
getAllSingletonNames, getAllSingletonNames,
} from './SingletonFunctions'; } from './SingletonFunctions';
@ -61,15 +61,15 @@ export class Cockpit implements INodeType {
options: [ options: [
{ {
name: 'Collection', name: 'Collection',
value: 'collections', value: 'collection',
}, },
{ {
name: 'Form', name: 'Form',
value: 'forms', value: 'form',
}, },
{ {
name: 'Singleton', name: 'Singleton',
value: 'singletons', value: 'singleton',
}, },
], ],
}, },
@ -94,7 +94,7 @@ export class Cockpit implements INodeType {
return { return {
name: itemName, name: itemName,
value: itemName, value: itemName,
} };
}); });
}, },
@ -105,7 +105,7 @@ export class Cockpit implements INodeType {
return { return {
name: itemName, name: itemName,
value: itemName, value: itemName,
} };
}); });
}, },
}, },
@ -121,7 +121,7 @@ export class Cockpit implements INodeType {
let responseData; let responseData;
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
if (resource === 'collections') { if (resource === 'collection') {
const collectionName = this.getNodeParameter('collection', i) as string; const collectionName = this.getNodeParameter('collection', i) as string;
if (operation === 'create') { if (operation === 'create') {
const data = this.getNodeParameter('data', i) as IDataObject; const data = this.getNodeParameter('data', i) as IDataObject;
@ -129,6 +129,11 @@ export class Cockpit implements INodeType {
responseData = await createCollectionEntry.call(this, collectionName, data); responseData = await createCollectionEntry.call(this, collectionName, data);
} else if (operation === 'getAll') { } else if (operation === 'getAll') {
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll !== true) {
options.limit = this.getNodeParameter('limit', i) as number;
}
responseData = await getAllCollectionEntries.call(this, collectionName, options); responseData = await getAllCollectionEntries.call(this, collectionName, options);
} else if (operation === 'update') { } else if (operation === 'update') {
@ -137,17 +142,17 @@ export class Cockpit implements INodeType {
responseData = await createCollectionEntry.call(this, collectionName, data, id); responseData = await createCollectionEntry.call(this, collectionName, data, id);
} }
} else if (resource === 'forms') { } else if (resource === 'form') {
const formName = this.getNodeParameter('form', i) as string; const formName = this.getNodeParameter('form', i) as string;
if (operation === 'submit') { if (operation === 'submit') {
const form = this.getNodeParameter('form', i) as IDataObject; const form = this.getNodeParameter('form', i) as IDataObject;
responseData = await submitForm.call(this, formName, form); responseData = await submitForm.call(this, formName, form);
} }
} else if (resource === 'singletons') { } else if (resource === 'singleton') {
const singletonName = this.getNodeParameter('singleton', i) as string; const singletonName = this.getNodeParameter('singleton', i) as string;
if (operation === 'getAll') { if (operation === 'get') {
responseData = await getAllSingleton.call(this, singletonName); responseData = await getSingleton.call(this, singletonName);
} }
} }

View file

@ -8,7 +8,7 @@ export const collectionOperations = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'collections', 'collection',
], ],
}, },
}, },
@ -46,7 +46,7 @@ export const collectionFields = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'collections', 'collection',
], ],
}, },
}, },
@ -54,7 +54,7 @@ export const collectionFields = [
description: 'Name of the collection to operate on.' description: 'Name of the collection to operate on.'
}, },
// Collections:entry:create // Collection:entry:create
{ {
displayName: 'Data', displayName: 'Data',
name: 'data', name: 'data',
@ -67,7 +67,7 @@ export const collectionFields = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'collections', 'collection',
], ],
operation: [ operation: [
'create', 'create',
@ -77,7 +77,48 @@ export const collectionFields = [
description: 'The data to create.', description: 'The data to create.',
}, },
// Collections:entry:getAll // Collection:entry:getAll
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'collection',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'collection',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
},
{ {
displayName: 'Options', displayName: 'Options',
name: 'options', name: 'options',
@ -87,7 +128,7 @@ export const collectionFields = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'collections', 'collection',
], ],
operation: [ operation: [
'getAll', 'getAll',
@ -122,13 +163,6 @@ export const collectionFields = [
default: '', default: '',
description: 'Return normalized language fields.', description: 'Return normalized language fields.',
}, },
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: '',
description: 'Limit number of returned entries.',
},
{ {
displayName: 'Populate', displayName: 'Populate',
name: 'populate', name: 'populate',
@ -144,14 +178,6 @@ export const collectionFields = [
default: false, default: false,
description: `Returns the data exactly in the way it got received from the API.`, description: `Returns the data exactly in the way it got received from the API.`,
}, },
{
displayName: 'Simple',
name: 'simple',
type: 'boolean',
required: true,
default: true,
description: 'Return only result entries.',
},
{ {
displayName: 'Skip', displayName: 'Skip',
name: 'skip', name: 'skip',
@ -169,7 +195,7 @@ export const collectionFields = [
], ],
}, },
// Collections:entry:update // Collection:entry:update
{ {
displayName: 'Entry ID', displayName: 'Entry ID',
name: 'id', name: 'id',
@ -179,7 +205,7 @@ export const collectionFields = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'collections', 'collection',
], ],
operation: [ operation: [
'update', 'update',
@ -200,7 +226,7 @@ export const collectionFields = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'collections', 'collection',
], ],
operation: [ operation: [
'update', 'update',

View file

@ -50,24 +50,19 @@ export async function getAllCollectionEntries(this: IExecuteFunctions | IExecute
body.populate = options.populate as boolean; body.populate = options.populate as boolean;
} }
if (options.simple) { body.simple = true;
body.simple = options.simple as boolean; if (options.rawData) {
body.simple = !options.rawData as boolean;
} }
if (options.language) { if (options.language) {
body.lang = options.language as string; body.lang = options.language as string;
} }
const resultData = await cockpitApiRequest.call(this, 'post', `/collections/get/${resourceName}`, body); return cockpitApiRequest.call(this, 'post', `/collections/get/${resourceName}`, body);
if (options.rawData === true) {
return resultData;
}
return (resultData as unknown as IDataObject).entries;
} }
export async function getAllCollectionNames(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions): Promise<string[]> { export async function getAllCollectionNames(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions): Promise<string[]> {
return cockpitApiRequest.call(this, 'GET', `/collections/listCollections`, {}); return cockpitApiRequest.call(this, 'GET', `/collections/listCollections`, {});
} }

View file

@ -8,7 +8,7 @@ export const formOperations = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'forms', 'form',
], ],
}, },
}, },
@ -33,7 +33,7 @@ export const formFields = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'forms', 'form',
], ],
}, },
}, },
@ -42,7 +42,7 @@ export const formFields = [
description: 'Name of the form to operate on.' description: 'Name of the form to operate on.'
}, },
// Forms:submit // Form:submit
{ {
displayName: 'Form data', displayName: 'Form data',
name: 'form', name: 'form',
@ -55,7 +55,7 @@ export const formFields = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'forms', 'form',
], ],
}, },
}, },

View file

@ -8,18 +8,18 @@ export const singletonOperations = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'singletons', 'singleton',
], ],
}, },
}, },
options: [ options: [
{ {
name: 'Get All', name: 'Get',
value: 'getAll', value: 'get',
description: 'Get all singletons', description: 'Gets a singleton',
}, },
], ],
default: 'getAll', default: 'get',
description: 'The operation to perform.', description: 'The operation to perform.',
} }
] as INodeProperties[]; ] as INodeProperties[];
@ -36,11 +36,11 @@ export const singletonFields = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'singletons', 'singleton',
], ],
}, },
}, },
required: true, required: true,
description: 'Name of the singleton to operate on.' description: 'Name of the singleton to operate on.'
}, },
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -5,10 +5,10 @@ import {
} from 'n8n-core'; } from 'n8n-core';
import { cockpitApiRequest } from './GenericFunctions'; import { cockpitApiRequest } from './GenericFunctions';
export async function getAllSingleton(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resourceName: string): Promise<any> { // tslint:disable-line:no-any export async function getSingleton(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resourceName: string): Promise<any> { // tslint:disable-line:no-any
return cockpitApiRequest.call(this, 'get', `/singletons/get/${resourceName}`); return cockpitApiRequest.call(this, 'get', `/singletons/get/${resourceName}`);
} }
export async function getAllSingletonNames(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions): Promise<string[]> { export async function getAllSingletonNames(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions): Promise<string[]> {
return cockpitApiRequest.call(this, 'GET', `/singletons/listSingletons`, {}); return cockpitApiRequest.call(this, 'GET', `/singletons/listSingletons`, {});
} }