Skip to content

Commit

Permalink
feat: add bpmn:InclusiveGateway support
Browse files Browse the repository at this point in the history
Closes #88
  • Loading branch information
barmac committed Feb 18, 2022
1 parent 1b3870a commit 31db2c4
Show file tree
Hide file tree
Showing 17 changed files with 788 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import TokenCountModule from './features/token-count';
import SetAnimationSpeedModule from './features/set-animation-speed';

import ExclusiveGatewaySettingsModule from './features/exclusive-gateway-settings';
import InclusiveGatewaySettingsModule from './features/inclusive-gateway-settings';
import PreserveElementColorsModule from './features/preserve-element-colors';
import TokenSimulationPaletteModule from './features/palette';

Expand All @@ -30,6 +31,7 @@ export default {
TokenCountModule,
SetAnimationSpeedModule,
ExclusiveGatewaySettingsModule,
InclusiveGatewaySettingsModule,
PreserveElementColorsModule,
TokenSimulationPaletteModule
]
Expand Down
2 changes: 2 additions & 0 deletions lib/features/context-pads/ContextPads.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from 'min-dom';

import ExclusiveGatewayHandler from './handler/ExclusiveGatewayHandler';
import InclusiveGatewayHandler from './handler/InclusiveGatewayHandler';
import PauseHandler from './handler/PauseHandler';
import TriggerHandler from './handler/TriggerHandler';

Expand Down Expand Up @@ -45,6 +46,7 @@ export default function ContextPads(
this._handlers = [];

this.registerHandler('bpmn:ExclusiveGateway', ExclusiveGatewayHandler);
this.registerHandler('bpmn:InclusiveGateway', InclusiveGatewayHandler);

this.registerHandler('bpmn:Activity', PauseHandler);

Expand Down
47 changes: 47 additions & 0 deletions lib/features/context-pads/handler/InclusiveGatewayHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
ForkIcon
} from '../../../icons';

import { getBusinessObject } from '../../../util/ElementHelper';
import { isSequenceFlow } from '../../../simulator/util/ModelUtil';

export default function InclusiveGatewayHandler(inclusiveGatewaySettings) {
this._inclusiveGatewaySettings = inclusiveGatewaySettings;
}

InclusiveGatewayHandler.prototype.createContextPads = function(element) {
const outgoingFlows = element.outgoing.filter(isSequenceFlow);

if (outgoingFlows.length < 2) {
return;
}

const nonDefaultFlows = outgoingFlows.filter(outgoing => {
const flowBo = getBusinessObject(outgoing),
gatewayBo = getBusinessObject(element);

Check warning on line 21 in lib/features/context-pads/handler/InclusiveGatewayHandler.js

View check run for this annotation

Codecov / codecov/patch

lib/features/context-pads/handler/InclusiveGatewayHandler.js#L19-L21

Added lines #L19 - L21 were not covered by tests

return gatewayBo.default !== flowBo;

Check warning on line 23 in lib/features/context-pads/handler/InclusiveGatewayHandler.js

View check run for this annotation

Codecov / codecov/patch

lib/features/context-pads/handler/InclusiveGatewayHandler.js#L23

Added line #L23 was not covered by tests
});

const html = `

Check warning on line 26 in lib/features/context-pads/handler/InclusiveGatewayHandler.js

View check run for this annotation

Codecov / codecov/patch

lib/features/context-pads/handler/InclusiveGatewayHandler.js#L26

Added line #L26 was not covered by tests
<div class="bts-context-pad" title="Set Sequence Flow">
${ForkIcon()}
</div>
`;

return nonDefaultFlows.map(sequenceFlow => {
const action = () => {
this._inclusiveGatewaySettings.toggleSequenceFlow(element, sequenceFlow);

Check warning on line 34 in lib/features/context-pads/handler/InclusiveGatewayHandler.js

View check run for this annotation

Codecov / codecov/patch

lib/features/context-pads/handler/InclusiveGatewayHandler.js#L32-L34

Added lines #L32 - L34 were not covered by tests
};

return {

Check warning on line 37 in lib/features/context-pads/handler/InclusiveGatewayHandler.js

View check run for this annotation

Codecov / codecov/patch

lib/features/context-pads/handler/InclusiveGatewayHandler.js#L37

Added line #L37 was not covered by tests
action,
element: sequenceFlow,
html
};
});
};

InclusiveGatewayHandler.$inject = [
'inclusiveGatewaySettings'
];
1 change: 0 additions & 1 deletion lib/features/element-support/ElementSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {


const UNSUPPORTED_ELEMENTS = [
'bpmn:InclusiveGateway',
'bpmn:ComplexGateway'
];

Expand Down
159 changes: 159 additions & 0 deletions lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import {
TOGGLE_MODE_EVENT
} from '../../util/EventHelper';


const SELECTED_COLOR = '--token-simulation-grey-darken-30';
const NOT_SELECTED_COLOR = '--token-simulation-grey-lighten-56';

import {
getBusinessObject,
is,
isSequenceFlow
} from '../../simulator/util/ModelUtil';


export default function InclusiveGatewaySettings(
eventBus, elementRegistry,
elementColors, simulator, simulationStyles) {

this._elementRegistry = elementRegistry;
this._elementColors = elementColors;
this._simulator = simulator;
this._simulationStyles = simulationStyles;

eventBus.on(TOGGLE_MODE_EVENT, event => {
if (event.active) {
this.setDefaults();
} else {
this.reset();
}
});
}

InclusiveGatewaySettings.prototype.setDefaults = function() {
const inclusiveGateways = this._elementRegistry.filter(element => {
return is(element, 'bpmn:InclusiveGateway');
});

inclusiveGateways.forEach(inclusiveGateway => {
if (inclusiveGateway.outgoing.filter(isSequenceFlow).length > 1) {
this._setGatewayDefaults(inclusiveGateway);

Check warning on line 41 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L41

Added line #L41 was not covered by tests
}
});
};

InclusiveGatewaySettings.prototype.reset = function() {
const inclusiveGateways = this._elementRegistry.filter(element => {
return is(element, 'bpmn:InclusiveGateway');
});

inclusiveGateways.forEach(inclusiveGateway => {
if (inclusiveGateway.outgoing.filter(isSequenceFlow).length > 1) {
this._resetGateway(inclusiveGateway);

Check warning on line 53 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L52-L53

Added lines #L52 - L53 were not covered by tests
}
});
};

InclusiveGatewaySettings.prototype.toggleSequenceFlow = function(gateway, sequenceFlow) {
const activeOutgoing = this._getActiveOutgoing(gateway),
defaultFlow = getDefaultFlow(gateway),
nonDefaultFlows = getNonDefaultFlows(gateway);

Check warning on line 61 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L59-L61

Added lines #L59 - L61 were not covered by tests

let newActiveOutgoing;
if (activeOutgoing.includes(sequenceFlow)) {
newActiveOutgoing = without(activeOutgoing, sequenceFlow);

Check warning on line 65 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L64-L65

Added lines #L64 - L65 were not covered by tests
} else {
newActiveOutgoing = without(activeOutgoing, defaultFlow).concat(sequenceFlow);

Check warning on line 67 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L67

Added line #L67 was not covered by tests
}

// make sure at least one flow is active
if (!newActiveOutgoing.length) {

Check warning on line 71 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L71

Added line #L71 was not covered by tests

// default flow if available
if (defaultFlow) {
newActiveOutgoing = [ defaultFlow ];

Check warning on line 75 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L74-L75

Added lines #L74 - L75 were not covered by tests
} else {

// or another flow which is not the one toggled
newActiveOutgoing = [ nonDefaultFlows.find(flow => flow !== sequenceFlow) ];

Check warning on line 79 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L79

Added line #L79 was not covered by tests
}
}

this._setActiveOutgoing(gateway, newActiveOutgoing);

Check warning on line 83 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L83

Added line #L83 was not covered by tests
};

InclusiveGatewaySettings.prototype._getActiveOutgoing = function(gateway) {
const {
activeOutgoing
} = this._simulator.getConfig(gateway);

Check warning on line 89 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L89

Added line #L89 was not covered by tests

return activeOutgoing;

Check warning on line 91 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L91

Added line #L91 was not covered by tests
};

InclusiveGatewaySettings.prototype._setActiveOutgoing = function(gateway, activeOutgoing) {
this._simulator.setConfig(gateway, { activeOutgoing });

Check warning on line 95 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L95

Added line #L95 was not covered by tests

const sequenceFlows = gateway.outgoing.filter(isSequenceFlow);

Check warning on line 97 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L97

Added line #L97 was not covered by tests

// set colors
sequenceFlows.forEach(outgoing => {

Check warning on line 100 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L100

Added line #L100 was not covered by tests

const style = (!activeOutgoing || activeOutgoing.includes(outgoing)) ?

Check warning on line 102 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L102

Added line #L102 was not covered by tests
SELECTED_COLOR : NOT_SELECTED_COLOR;
const stroke = this._simulationStyles.get(style);

Check warning on line 104 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L104

Added line #L104 was not covered by tests

this._elementColors.set(outgoing, {

Check warning on line 106 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L106

Added line #L106 was not covered by tests
stroke
});
});
};

InclusiveGatewaySettings.prototype._setGatewayDefaults = function(gateway) {
const sequenceFlows = gateway.outgoing.filter(isSequenceFlow);

Check warning on line 113 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L113

Added line #L113 was not covered by tests

const defaultFlow = getDefaultFlow(gateway);
const nonDefaultFlows = without(sequenceFlows, defaultFlow);

Check warning on line 116 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L115-L116

Added lines #L115 - L116 were not covered by tests

this._setActiveOutgoing(gateway, nonDefaultFlows);

Check warning on line 118 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L118

Added line #L118 was not covered by tests
};

InclusiveGatewaySettings.prototype._resetGateway = function(gateway) {
this._setActiveOutgoing(gateway, undefined);

Check warning on line 122 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L122

Added line #L122 was not covered by tests
};

InclusiveGatewaySettings.$inject = [
'eventBus',
'elementRegistry',
'elementColors',
'simulator',
'simulationStyles'
];

function getDefaultFlow(gateway) {
const defaultFlow = getBusinessObject(gateway).default;

Check warning on line 134 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L134

Added line #L134 was not covered by tests

if (!defaultFlow) {
return;

Check warning on line 137 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L136-L137

Added lines #L136 - L137 were not covered by tests
}

return gateway.outgoing.find(flow => {
const flowBo = getBusinessObject(flow);

Check warning on line 141 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L140-L141

Added lines #L140 - L141 were not covered by tests

return flowBo === defaultFlow;

Check warning on line 143 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L143

Added line #L143 was not covered by tests
});
}

function getNonDefaultFlows(gateway) {
const defaultFlow = getDefaultFlow(gateway);

Check warning on line 148 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L148

Added line #L148 was not covered by tests

return gateway.outgoing.filter(flow => {
const flowBo = getBusinessObject(flow);

Check warning on line 151 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L150-L151

Added lines #L150 - L151 were not covered by tests

return flowBo !== defaultFlow;

Check warning on line 153 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L153

Added line #L153 was not covered by tests
});
}

function without(array, element) {
return array.filter(arrayElement => arrayElement !== element);

Check warning on line 158 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L158

Added line #L158 was not covered by tests
}
11 changes: 11 additions & 0 deletions lib/features/inclusive-gateway-settings/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import InclusiveGatewaySettings from './InclusiveGatewaySettings';
import ElementColorsModule from '../element-colors';
import SimulationStylesModule from '../simulation-styles';

export default {
__depends__: [
ElementColorsModule,
SimulationStylesModule
],
inclusiveGatewaySettings: [ 'type', InclusiveGatewaySettings ]
};
Loading

0 comments on commit 31db2c4

Please sign in to comment.