Skip to content

Commit

Permalink
feat: allow to pause simulation at specific element
Browse files Browse the repository at this point in the history
Closes #9.
  • Loading branch information
nikku committed Dec 14, 2021
1 parent 5323070 commit f6c6b06
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
6 changes: 6 additions & 0 deletions assets/css/bpmn-js-token-simulation.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
color: var(--token-simulation-white, #FFFFFF);
}

.djs-overlays:not(.hover) .context-pad:not(:hover).show-hover,
.context-pad:not(:hover) .show-hover,
.context-pad:hover .hide-hover {
display: none;
}

.context-pad.disabled {
background-color: var(--token-simulation-silver-darken-94, #EFEFEF);
color: var(--token-simulation-grey-base-40, #666666);
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 @@ -20,6 +20,7 @@ import ExclusiveGatewayHandler from './handler/ExclusiveGatewayHandler';
import EventBasedGatewayHandler from './handler/EventBasedGatewayHandler';
import IntermediateCatchEventHandler from './handler/IntermediateCatchEventHandler';
import StartEventHandler from './handler/StartEventHandler';
import PauseHandler from './handler/PauseHandler';


const LOW_PRIORITY = 500;
Expand Down Expand Up @@ -54,6 +55,7 @@ export default function ContextPads(
this.registerHandler('bpmn:Process', StartEventHandler);
this.registerHandler('bpmn:SubProcess', StartEventHandler);
this.registerHandler('bpmn:Participant', StartEventHandler);
this.registerHandler('bpmn:Activity', PauseHandler);

eventBus.on(TOGGLE_MODE_EVENT, LOW_PRIORITY, context => {
const active = context.active;
Expand Down
74 changes: 74 additions & 0 deletions lib/features/context-pads/handler/PauseHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
domify
} from 'min-dom';


export default function PauseHandler(simulator) {
this._simulator = simulator;
}

PauseHandler.prototype.createContextPads = function(element) {

return [
this.createPauseContextPad(element)
];
};

PauseHandler.prototype.createPauseContextPad = function(element) {

const scopes = () => this._findScopes({
element
});

// only show if no active scope
if (scopes().length) {
return;
}

const wait = this._isPaused(element);

const html = domify(
`<div class="context-pad ${ wait ? '' : 'show-hover' }" title="${ wait ? 'Remove' : 'Add' } pause point">
<i class="fa ${ wait ? 'fa-circle-o' : 'fa-circle' } show-hover"></i>
<i class="fa fa-circle hide-hover"></i>
</div>`
);

const action = () => {

if (scopes().length) {
return;
}

this._togglePaused(element);
};

return {
action,
element,
html
};
};

PauseHandler.prototype._isPaused = function(element) {

const {
wait
} = this._simulator.getConfig(element);

return wait;
};

PauseHandler.prototype._togglePaused = function(element) {
const wait = !this._isPaused(element);

this._simulator.waitAtElement(element, wait);
};

PauseHandler.prototype._findScopes = function(options) {
return this._simulator.findScopes(options);
};

PauseHandler.$inject = [
'simulator'
];
70 changes: 70 additions & 0 deletions test/spec/SimulationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,76 @@ describe('simulation', function() {
));


describe('pause at node', function() {

it('should add pause point', inject(
async function(simulator) {

// when
triggerElement('Task_1');

triggerElement('StartEvent_1');

await elementEnter('Task_1');

// then
expectHistory([
'StartEvent_1',
'SequenceFlow_1',
'Task_1'
]);

// but when
triggerElement('Task_1');

await scopeDestroyed();

// then
expectHistory([
'StartEvent_1',
'SequenceFlow_1',
'Task_1',
'SequenceFlow_1wm1e59',
'ExclusiveGateway_1',
'SequenceFlow_2',
'Task_2',
'SequenceFlow_3',
'EndEvent_1'
]);
}
));


it('should remove pause point', inject(
async function(simulator) {

// given
triggerElement('Task_1');

// when
triggerElement('Task_1');
triggerElement('StartEvent_1');

await scopeDestroyed();

// then
expectHistory([
'StartEvent_1',
'SequenceFlow_1',
'Task_1',
'SequenceFlow_1wm1e59',
'ExclusiveGateway_1',
'SequenceFlow_2',
'Task_2',
'SequenceFlow_3',
'EndEvent_1'
]);
}
));

});


it('should continue flow', inject(
async function(simulator, exclusiveGatewaySettings) {

Expand Down

0 comments on commit f6c6b06

Please sign in to comment.