Workflow
adaptiveui-workflow
Workflow is a utility to model logic-driven, state-based workflows. Workflow is used to define a series of steps where step progression can change dynamically. One sequence of work exists as an exterior index for the end-user (in the interface) and an interior index to control a more complex process workflow. A Workflow is an object which encapsulates all logic related to a set of steps and so provides helper methods to query the state of the workflow, to support easy interface control for templates.
Install
Install with npm.
npm install --save adaptiveui-workflow
Install with bower.
bower install --save adaptiveui-workflow
Lodash Dependency
This library requires a small set of lodash. Use lodash-modularize to limit how much of lodash is included in your project.
Quick Usage
var workflow = ; // many is* methods to control interface state;; // next will return the next value and advance the internal index;;;
Usage
Workflow Scenarios
The following example(s) demonstrate the power of a Workflow and usefulness of managing two indices.
Form Validation
Every page/view within a multi-part form should have a validation method.
var workflow = ; // Rule: if the current view is not valid, assign the workflow to the current workflowworkflow; workflownext; // same as workflow.index = 1 (or any other index)workflowindex === 0; // the valid method at index 0, prevents progression
User Permission
A Workflow can be used to construct the steps presented to an end-user.
var workflow = ; // Rule: Scan to next/previous permitted itemworkflow; workflownext;workflownext;workflowindex === 2; // it scanned to the next permitted item and not beyond workflowprevious;workflowprevious;workflowindex === 0; // it scanned to the previous permitted item and not beyond
Isolated Parts
A Workflow may be initialized with multiple sets of reflow objects each defining progression rules. It is useful when providing a Workflow to a component that needs to swap progression rules based on application modes.
var workflow = ; // Apply a reflow with no rules, normal +1 rules for next() applyworkflow;workflow;workflownext;workflownext; // Apply a reflow with skipping oddworkflow; workflow;workflow;workflownext;workflownext; // Apply a reflow object directlyworkflow;
Workflow API
Initialize a Workflow
A Workflow can progress over the following types:
integer
which is converted to an array[0, 1, 2, 3, ..., <integer>]
array
object
;;;
The Workflow object also doubles as a factory for itself.
var workflow = ;var workflow = Workflow;
Moving through a Workflow
A Workflow keeps track of an internal index. By default a Workflow maps it's index directly to the underlying source. With an array Workflow, if index = 2
, the current()
you return the item at index 2.
var workflow = ; workflow === 0; // always 0workflowlastIndex === 2; // last index of an array of 3workflowindex === 0; // defaults to 0workflow === true; // index is at 0 which is firstworkflow === false; // index is at 0 which is not the lastworkflow === false // index is at first, so it cannot be after itworkflow === true // index is less than lastIndex()
These methods are most useful in a template, this example uses an imaginary templating language.
{{ customViewAtIndex(workflow.index) }} Previous Next
A Workflow bounds the index.
var workflow = ; workflowindex = 1;workflowindex === 1;// assign an index under the first index, so we set to firstworkflowindex = -3;workflowindex === 0;// assign an index over the last index, so we set to lastworkflowindex = 6;workflowindex === 2;// assign a non-numerical index, leave the index at the same locationworkflowindex = 'as';workflowindex === 2;
Workflows of Objects
The object stored at the index can be retrieved too.
var workflow = ; workflowcurrent === 'two'; // defaults to 'two'workflow === 'two'; // always the first objectworkflow === 'four'; // always the last object
Workflow Size
The size of the object being progressed over.
var workflow = ; workflowlength === 3;workflowsize === 3;
License
MIT © mwjaworski
This software is released under the MIT license:
Copyright (c) 2016 mwjaworski mjaworski@acm.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.))