https://github.com/eden-js/flow
https://github.com/eden-js/flow
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/eden-js/flow
- Owner: eden-js
- Created: 2019-06-04T06:30:37.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-02T06:32:20.000Z (over 5 years ago)
- Last Synced: 2025-01-26T18:17:29.631Z (4 months ago)
- Language: JavaScript
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EdenJS - Flow
[](https://travis-ci.com/eden-js/flow)
[](https://github.com/eden-js/flow/issues)
[](https://github.com/eden-js/flow)
[](https://github.com/eden-js/flow)
[](https://discord.gg/5u3f3up)Flow Builder base logic component for [EdenJS](https://github.com/edenjs-cli)
`@edenjs/flow` creates a drag and droppable flow builder in admin for administering flows.
## Setup
### Install
```
npm i --save @edenjs/flow
```### Configure
No configuration is required for this module
## Models
### `Flow` _[Usage](https://github.com/eden-js/flow/blob/master/bundles/flow/models/flow.js)_
Flow model consits of a single entry for flow created.
#### Example
```js
// load model
const Flow = model('flow');// get first entry
const entry = await Flow.findOne();// data used in frontend
const data = await entry.sanitise();
```## Hooks
### `flow.build` _[Usage](https://github.com/eden-js/flow/blob/master/bundles/flow/controllers/admin.js#L59)_ _[Usage](https://github.com/eden-js/flow/blob/master/bundles/flow/controllers/admin.js#L263)_
Flow Build hook fires any time we want to setup new flow elements.
#### Example
```js
/**
* setup flow hook
*
* @pre flow.build
*/
flowSetupHook(flow) {
// create trigger
flow.trigger('trigger', {...
}
```## Flow Elements
### `trigger` _[Usage](https://github.com/eden-js/flow/blob/master/bundles/flow/controllers/admin.js#L270)_
Flow Triggers are used to define when and how a flow should be started.
#### Example
```js
/**
* setup flow hook
*
* @pre flow.build
*/
flowSetupHook(flow) {
// create trigger
flow.trigger('interval', { // name and create flow trigger, these can be taken over
icon : 'fa fa-clock', // set icon for flow drag in element
title : '30 second trigger', // set title for flow drag in element
}, (action, render) => {
// any async logic that needs to be added to the render method can be added here
}, (run, cancel, query) => {
// run is a function that is run whenever this flow should be triggered
// query is a query on the model `Flow` that can be returned changed// run trigger every 30 seconds
setInterval(() => run({
query : query.where({ // only run flows matching this query (optional)
'test' : true,
}),
value : {},
}), 30000);
});
}
```### `action` _[Usage](https://github.com/eden-js/flow/blob/master/bundles/flow/controllers/admin.js#L428)_
Flow Actions are used to define how this flow should proceed with data.
#### Example
```js
/**
* setup flow hook
*
* @pre flow.build
*/
flowSetupHook(flow) {
// create action
flow.action('email', { // name and crew flow action, these can be taken over
tag : 'email', // this will render the tag `action-email` in the admin flow manager
icon : 'fa fa-envelope', // set icon for flow drag in element
title : 'Send Email', // set title for flow drag in element
}, (action, render) => {
// any async logic that needs to be added to the render method can be added here
}, async (opts, element, model) => {
// set config
element.config = element.config || {};// send model
if (model instanceof Model) {
// sanitise model
model = await model.sanitise();
}// send email
await emailHelper.send((tmpl.tmpl(element.config.to || '', model)).split(',').map(i => i.trim()), 'blank', {
body : tmpl.tmpl(element.config.body || '', model),
subject : tmpl.tmpl(element.config.subject || '', model),
});// return true to signify that this flow can be continued
return true;
});
}
```