# FlowManager

## appmixer.ui.FlowManager

![](https://3013747694-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LATDgYqVMe0hChW7efU%2F-L_Iqy4wpN4OpykkYsJU%2F-L_Ix3yb1x2WGzcHpjl4%2FScreenshot%202019-03-06%20at%2018.01.37.png?alt=media\&token=ce3869b2-253a-4a65-be12-5020ed1afd89)

The appmixer.ui.FlowManager is a UI widget that displays a list of flows the user created.

| **Method**                        | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `appmixer.ui.FlowManager(config)` | <p>A function that accepts a config object and returns an instance of flow manager. The config object must contain at least the el property that points to a container DOM element where the flow manager will be rendered. el can either be a CSS selector or a reference to a DOM element. <br><br><code>config.options.menu</code> can optionally define the flow menu. For example: <br><br><code>{ options: { menu: \[ { label: 'Rename', event: 'flow:rename' }, { label: 'Insights', event: 'flow:insights' }, { label: 'Clone', event: 'flow:clone' }, { label: 'Export to SVG', event: 'flow:export-svg' }, { label: 'Export to PNG', event: 'flow:export-png' }, { label: 'Print', event: 'flow:print' } ] }</code><br><br>defines a menu with 6 items. Note that each item can also optionally contain icon property (which we omitted from the example above to save space. The icon property is a URL of an image. <br><br><code>config.sharePermissions</code> can optionally define the sharing options for the flows. For example:<br><br><code>sharePermissions: \[ { label: 'Read', value: 'read' }, { label: 'Start', value: 'start' }, { label: 'Stop', value: 'stop' } ]</code> <br><br>Define a share dialog box that gives the user permission to share their flows for all the read/start/stop permissions. Additionally, you can also define the scope of the share with <code>config.shareTypes</code>: <br><br><code>shareTypes: \[ { label: 'Email', value: 'email', placeholder: 'Enter an email' }, { label: 'Scope', value: 'scope', placeholder: 'Enter a scope' }, { label: 'Domain', value: 'domain', placeholder: 'Enter a domain' }, ]</code><br><br><code>config.options.customFilter</code> is an optional object that can contain properties that we'd like to filter on. This is especially useful in connection with customFields metadata object as it allows you to display multiple different Flow Managers each listing a different category of flows. For example: <br><br><code>options: {</code> <br>  <code>customFilter: {</code><br>    <code>'customFields.template': true</code><br>    <code>'customFields.category': 'healthcare'</code></p><p>  <code>}</code><br><code>}</code><br></p><p><code>config.options.layout.default</code> is an optional string that determines the default layout of the flow manager. Currently list and thumbnail are supported. If not specified, the default layout is thumbnail.<br></p><p><code>config.options.layout.table</code> is an optional object that allows customizing the list layout column headers and values displayed. For example: <br><br><code>options: {</code> <br>  <code>layout: {</code> <br>    <code>table: {</code> <br>      <code>columns: \[</code> <br>        <code>{ property: 'name', label: 'Flow Name' },</code> <br>        <code>{ property: 'status', label: 'Current Status' },</code> <br>        <code>{ property: 'btime', label: 'Start Time' },</code> <br>        <code>{ property: 'mtime', label: 'Last Updated' }</code> <br>      <code>]</code> <br>    <code>}</code> <br>  <code>}</code> <br><code>}</code><br><br>The label property makes reference to the label displayed on the column header, while property makes reference to the flow property value that will be displayed on that column.</p> |
| `open()`                          | Render the flow manager inside its container.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `close()`                         | Close the flow manager.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `on(event, handler)`              | React on events of the flow manager. See below for the list of events the flow manager supports.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `off([event, handler])`           | Remove event listeners. If no arguments are provided, remove all event listeners. If only the `event` is provided, remove all listeners for that event. If both `event` and `handler` are given, remove the listener for that specific handler only.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `state(name, value, [details])`   | Change the state of the UI. Currently, only `"loader"` and `"error"` states are supported. For example, in order to show a loader in the flow manager UI, just call `state("loader", true)`. If you want to display an error in the flow manager UI, call `state("error", "Something went wrong.")`. The optional `details` parameter allows you to add details to the `error` message, for exmaple: `state('error', 'Something went wrong', 'Loading failed because ....')`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `reload()`                        | Re-render the flow manager. Call this when you changed the state of a flow (e.g. renamed a flow, started a flow, ...) to make sure the flow manager reflects the new changes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

### Flow Manager Events

| **Event**       | **Callback**       | Triggered when...                                         |
| --------------- | ------------------ | --------------------------------------------------------- |
| `flow:open`     | `function(flowId)` | the user clicks on a flow to open it.                     |
| `flow:create`   | `function()`       | the user clicks the "Create Flow" button.                 |
| `flow:start`    | `function(flowId)` | the user clicks the button to start the flow.             |
| `flow:stop`     | `function(flowId)` | the user clicks the button to stop the flow.              |
| `flow:insights` | `function(flowId)` | the user clicks the button to open Insights for the flow. |
| `flow:clone`    | `function(flowId)` | the user clicks the button to clone the flow.             |
| `flow:remove`   | `function(flowId)` | the user clicks the button to delete the flow.            |

### Example

```javascript
var flowManager = appmixer.ui.FlowManager({
    el: '#your-flow-manager-div',
    options: {
        menu: [
            { label: 'Edit', event: 'flow:open' },
            { label: 'Clone', event: 'flow:clone' },
            { label: 'Share', event: 'flow:share' },
            { label: 'Insights', event: 'flow:insights' },
            { label: 'Delete', event: 'flow:remove' }
        ]
    }
});
flowManager.on('flow:start', function(flowId) {
    flowManager.state('loader', true);
    appmixer.api.startFlow(flowId).then(function() {
        flowManager.state('loader', false);
        flowManager.reload();
    }).catch(function(error) {
        flowManager.state('error', 'Starting flow failed.');
    });
});
flowManager.on('flow:create', function() {
    flowManager.state('loader', true);
    appmixer.api.createFlow('New flow').then(function(flowId) {
        flowManager.state('loader', false);
        designer.set('flowId', flowId);
        designer.open();
    }).catch(function(error) {
        flowManager.state('error', 'Creating flow failed.');
    });
});
flowManager.open();
```

##
