mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Make it possible to reste SplitInBatches-Node
This commit is contained in:
parent
7a27979ddd
commit
89a73d4653
|
@ -1,5 +1,6 @@
|
||||||
import { IExecuteFunctions } from 'n8n-core';
|
import { IExecuteFunctions } from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
|
IDataObject,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
|
@ -31,6 +32,23 @@ export class SplitInBatches implements INodeType {
|
||||||
default: 10,
|
default: 10,
|
||||||
description: 'The number of items to return with each call.',
|
description: 'The number of items to return with each call.',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
displayName: 'Options',
|
||||||
|
name: 'options',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Option',
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Reset',
|
||||||
|
name: 'reset',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'If set to true, the node will be reset and so with the current input-data newly initialized.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,7 +63,9 @@ export class SplitInBatches implements INodeType {
|
||||||
|
|
||||||
const returnItems: INodeExecutionData[] = [];
|
const returnItems: INodeExecutionData[] = [];
|
||||||
|
|
||||||
if (nodeContext.items === undefined) {
|
const options = this.getNodeParameter('options', 0, {}) as IDataObject;
|
||||||
|
|
||||||
|
if (nodeContext.items === undefined || options.reset === true) {
|
||||||
// Is the first time the node runs
|
// Is the first time the node runs
|
||||||
|
|
||||||
nodeContext.currentRunIndex = 0;
|
nodeContext.currentRunIndex = 0;
|
||||||
|
@ -56,7 +76,7 @@ export class SplitInBatches implements INodeType {
|
||||||
|
|
||||||
// Set the other items to be saved in the context to return at later runs
|
// Set the other items to be saved in the context to return at later runs
|
||||||
nodeContext.items = items;
|
nodeContext.items = items;
|
||||||
} else {
|
} else {
|
||||||
// The node has been called before. So return the next batch of items.
|
// The node has been called before. So return the next batch of items.
|
||||||
nodeContext.currentRunIndex += 1;
|
nodeContext.currentRunIndex += 1;
|
||||||
returnItems.push.apply(returnItems, nodeContext.items.splice(0, batchSize));
|
returnItems.push.apply(returnItems, nodeContext.items.splice(0, batchSize));
|
||||||
|
|
Loading…
Reference in a new issue