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 Nov 20, 2023
1 parent d0fe24a commit 622e6ef
Show file tree
Hide file tree
Showing 21 changed files with 1,248 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SetAnimationSpeedModule from './features/set-animation-speed';

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

export default {
Expand All @@ -31,6 +32,7 @@ export default {
SetAnimationSpeedModule,
ExclusiveGatewaySettingsModule,
NeutralElementColors,
InclusiveGatewaySettingsModule,
TokenSimulationPaletteModule
]
};
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
161 changes: 161 additions & 0 deletions lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
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';

const COLOR_ID = 'inclusive-gateway-settings';


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 43 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

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

Added line #L43 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 55 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L54-L55

Added lines #L54 - L55 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 63 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L61 - L63 were not covered by tests

let newActiveOutgoing;
if (activeOutgoing.includes(sequenceFlow)) {
newActiveOutgoing = without(activeOutgoing, 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#L66-L67

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L69 was not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L73 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L76-L77

Added lines #L76 - L77 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 81 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

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

Added line #L81 was not covered by tests
}
}

this._setActiveOutgoing(gateway, newActiveOutgoing);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L85 was not covered by tests
};

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

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

return activeOutgoing;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L93 was not covered by tests
};

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

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L99 was not covered by tests

// set colors
sequenceFlows.forEach(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

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

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
SELECTED_COLOR : NOT_SELECTED_COLOR;
const stroke = this._simulationStyles.get(style);

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

this._elementColors.add(outgoing, COLOR_ID, {

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

Check warning on line 115 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

Added line #L115 was not covered by tests

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

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#L117-L118

Added lines #L117 - L118 were not covered by tests

this._setActiveOutgoing(gateway, nonDefaultFlows);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L120 was not covered by tests
};

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L124 was not covered by tests
};

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

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

Check warning on line 136 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

Added line #L136 was not covered by tests

if (!defaultFlow) {
return;

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

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L138-L139

Added lines #L138 - L139 were not covered by tests
}

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

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#L142-L143

Added lines #L142 - L143 were not covered by tests

return flowBo === defaultFlow;

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

Check warning on line 150 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

Added line #L150 was not covered by tests

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

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#L152-L153

Added lines #L152 - L153 were not covered by tests

return flowBo !== defaultFlow;

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L160 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 622e6ef

Please sign in to comment.