-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bpmn:InclusiveGateway support
Closes #88
- Loading branch information
Showing
21 changed files
with
1,248 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
lib/features/context-pads/handler/InclusiveGatewayHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
return gatewayBo.default !== flowBo; | ||
}); | ||
|
||
const html = ` | ||
<div class="bts-context-pad" title="Set Sequence Flow"> | ||
${ForkIcon()} | ||
</div> | ||
`; | ||
|
||
return nonDefaultFlows.map(sequenceFlow => { | ||
const action = () => { | ||
this._inclusiveGatewaySettings.toggleSequenceFlow(element, sequenceFlow); | ||
}; | ||
|
||
return { | ||
action, | ||
element: sequenceFlow, | ||
html | ||
}; | ||
}); | ||
}; | ||
|
||
InclusiveGatewayHandler.$inject = [ | ||
'inclusiveGatewaySettings' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ import { | |
|
||
|
||
const UNSUPPORTED_ELEMENTS = [ | ||
'bpmn:InclusiveGateway', | ||
'bpmn:ComplexGateway' | ||
]; | ||
|
||
|
161 changes: 161 additions & 0 deletions
161
lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}; | ||
|
||
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); | ||
} | ||
}); | ||
}; | ||
|
||
InclusiveGatewaySettings.prototype.toggleSequenceFlow = function(gateway, sequenceFlow) { | ||
const activeOutgoing = this._getActiveOutgoing(gateway), | ||
defaultFlow = getDefaultFlow(gateway), | ||
nonDefaultFlows = getNonDefaultFlows(gateway); | ||
|
||
let newActiveOutgoing; | ||
if (activeOutgoing.includes(sequenceFlow)) { | ||
newActiveOutgoing = without(activeOutgoing, sequenceFlow); | ||
} else { | ||
newActiveOutgoing = without(activeOutgoing, defaultFlow).concat(sequenceFlow); | ||
} | ||
|
||
// make sure at least one flow is active | ||
if (!newActiveOutgoing.length) { | ||
|
||
// default flow if available | ||
if (defaultFlow) { | ||
newActiveOutgoing = [ defaultFlow ]; | ||
} else { | ||
|
||
// or another flow which is not the one toggled | ||
newActiveOutgoing = [ nonDefaultFlows.find(flow => flow !== sequenceFlow) ]; | ||
} | ||
} | ||
|
||
this._setActiveOutgoing(gateway, newActiveOutgoing); | ||
}; | ||
|
||
InclusiveGatewaySettings.prototype._getActiveOutgoing = function(gateway) { | ||
const { | ||
activeOutgoing | ||
} = this._simulator.getConfig(gateway); | ||
|
||
return activeOutgoing; | ||
}; | ||
|
||
InclusiveGatewaySettings.prototype._setActiveOutgoing = function(gateway, activeOutgoing) { | ||
this._simulator.setConfig(gateway, { activeOutgoing }); | ||
|
||
const sequenceFlows = gateway.outgoing.filter(isSequenceFlow); | ||
|
||
// set colors | ||
sequenceFlows.forEach(outgoing => { | ||
|
||
const style = (!activeOutgoing || activeOutgoing.includes(outgoing)) ? | ||
SELECTED_COLOR : NOT_SELECTED_COLOR; | ||
const stroke = this._simulationStyles.get(style); | ||
|
||
this._elementColors.add(outgoing, COLOR_ID, { | ||
stroke | ||
}); | ||
}); | ||
}; | ||
|
||
InclusiveGatewaySettings.prototype._setGatewayDefaults = function(gateway) { | ||
const sequenceFlows = gateway.outgoing.filter(isSequenceFlow); | ||
|
||
const defaultFlow = getDefaultFlow(gateway); | ||
const nonDefaultFlows = without(sequenceFlows, defaultFlow); | ||
|
||
this._setActiveOutgoing(gateway, nonDefaultFlows); | ||
}; | ||
|
||
InclusiveGatewaySettings.prototype._resetGateway = function(gateway) { | ||
this._setActiveOutgoing(gateway, undefined); | ||
}; | ||
|
||
InclusiveGatewaySettings.$inject = [ | ||
'eventBus', | ||
'elementRegistry', | ||
'elementColors', | ||
'simulator', | ||
'simulationStyles' | ||
]; | ||
|
||
function getDefaultFlow(gateway) { | ||
const defaultFlow = getBusinessObject(gateway).default; | ||
|
||
if (!defaultFlow) { | ||
return; | ||
} | ||
|
||
return gateway.outgoing.find(flow => { | ||
const flowBo = getBusinessObject(flow); | ||
|
||
return flowBo === defaultFlow; | ||
}); | ||
} | ||
|
||
function getNonDefaultFlows(gateway) { | ||
const defaultFlow = getDefaultFlow(gateway); | ||
|
||
return gateway.outgoing.filter(flow => { | ||
const flowBo = getBusinessObject(flow); | ||
|
||
return flowBo !== defaultFlow; | ||
}); | ||
} | ||
|
||
function without(array, element) { | ||
return array.filter(arrayElement => arrayElement !== element); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] | ||
}; |
Oops, something went wrong.