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

View file

@ -8,7 +8,7 @@ export const collectionOperations = [
displayOptions: {
show: {
resource: [
'collections',
'collection',
],
},
},
@ -46,7 +46,7 @@ export const collectionFields = [
displayOptions: {
show: {
resource: [
'collections',
'collection',
],
},
},
@ -54,7 +54,7 @@ export const collectionFields = [
description: 'Name of the collection to operate on.'
},
// Collections:entry:create
// Collection:entry:create
{
displayName: 'Data',
name: 'data',
@ -67,7 +67,7 @@ export const collectionFields = [
displayOptions: {
show: {
resource: [
'collections',
'collection',
],
operation: [
'create',
@ -77,7 +77,48 @@ export const collectionFields = [
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',
name: 'options',
@ -87,7 +128,7 @@ export const collectionFields = [
displayOptions: {
show: {
resource: [
'collections',
'collection',
],
operation: [
'getAll',
@ -122,13 +163,6 @@ export const collectionFields = [
default: '',
description: 'Return normalized language fields.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: '',
description: 'Limit number of returned entries.',
},
{
displayName: 'Populate',
name: 'populate',
@ -144,14 +178,6 @@ export const collectionFields = [
default: false,
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',
name: 'skip',
@ -169,7 +195,7 @@ export const collectionFields = [
],
},
// Collections:entry:update
// Collection:entry:update
{
displayName: 'Entry ID',
name: 'id',
@ -179,7 +205,7 @@ export const collectionFields = [
displayOptions: {
show: {
resource: [
'collections',
'collection',
],
operation: [
'update',
@ -200,7 +226,7 @@ export const collectionFields = [
displayOptions: {
show: {
resource: [
'collections',
'collection',
],
operation: [
'update',

View file

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

View file

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

View file

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

View file

@ -5,10 +5,10 @@ import {
} from 'n8n-core';
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}`);
}
export async function getAllSingletonNames(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions): Promise<string[]> {
return cockpitApiRequest.call(this, 'GET', `/singletons/listSingletons`, {});
}
}