Skip to content

Commit

Permalink
feat(replace): add multiplicity marker to replace menu for participants
Browse files Browse the repository at this point in the history
Closes #533
  • Loading branch information
azeghers committed Dec 9, 2020
1 parent f5566db commit 1d9e718
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 4 deletions.
38 changes: 37 additions & 1 deletion lib/features/popup-menu/ReplaceMenuProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ ReplaceMenuProvider.prototype.getHeaderEntries = function(element) {
headerEntries = headerEntries.concat(this._getDataObjectIsCollection(element));
}

if (is(element, 'bpmn:Participant')) {
headerEntries = headerEntries.concat(this._getParticipantMultiplicity(element));
}

if (is(element, 'bpmn:SubProcess') &&
!is(element, 'bpmn:Transaction') &&
!isEventSubProcess(element)) {
Expand Down Expand Up @@ -486,7 +490,7 @@ ReplaceMenuProvider.prototype._getLoopEntries = function(element) {
};

/**
* Get a list of menu items containing buttons for multi instance markers
* Get a list of menu items containing a button for the collection marker
*
* @param {djs.model.Base} element
*
Expand Down Expand Up @@ -519,6 +523,38 @@ ReplaceMenuProvider.prototype._getDataObjectIsCollection = function(element) {
return dataObjectEntries;
};

/**
* Get a list of menu items containing a button for the participant multiplicity marker
*
* @param {djs.model.Base} element
*
* @return {Array<Object>} a list of menu items
*/
ReplaceMenuProvider.prototype._getParticipantMultiplicity = function(element) {

var self = this;
var translate = this._translate;

function toggleParticipantMultiplicity(event, entry) {
self._modeling.updateProperties(
element,
{ participantMultiplicity: !entry.active });
}

var participantMultiplicity = element.businessObject.participantMultiplicity;

var participantEntries = [
{
id: 'toggle-participant-multiplicity',
className: 'bpmn-icon-parallel-mi-marker',
title: translate('Participant Multiplicity'),
active: participantMultiplicity,
action: toggleParticipantMultiplicity,
}
];
return participantEntries;
};


/**
* Get the menu items containing a button for the ad hoc marker
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/bpmn/features/replace/participants.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
<bpmn:collaboration id="Collaboration_1">
<bpmn:participant id="Participant_1" processRef="Process_1" />
</bpmn:collaboration>
<bpmn:process id="Process_1" isExecutable="false" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">
<bpmndi:BPMNShape id="Participant_1_di" bpmnElement="Participant_1" isHorizontal="true">
<dc:Bounds x="200" y="200" width="600" height="250" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
105 changes: 102 additions & 3 deletions test/spec/features/popup-menu/ReplaceMenuProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe('features/popup-menu - replace menu provider', function() {

var diagramXMLMarkers = require('../../../fixtures/bpmn/draw/activity-markers-simple.bpmn'),
diagramXMLReplace = require('../../../fixtures/bpmn/features/replace/01_replace.bpmn'),
diagramXMLDataElements = require('../../../fixtures/bpmn/features/replace/data-elements.bpmn');
diagramXMLDataElements = require('../../../fixtures/bpmn/features/replace/data-elements.bpmn'),
diagramXMLParticipants = require('../../../fixtures/bpmn/features/replace/participants.bpmn');

var testModules = [
coreModule,
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('features/popup-menu - replace menu provider', function() {
}));


it('should undo toggle on', inject(function(commandStack, elementRegistry) {
it('should undo', inject(function(commandStack, elementRegistry) {

// given
var dataObjectReference = elementRegistry.get('DataObjectReference_1');
Expand All @@ -98,7 +99,7 @@ describe('features/popup-menu - replace menu provider', function() {
}));


it('should redo toggle on', inject(function(commandStack, elementRegistry) {
it('should redo', inject(function(commandStack, elementRegistry) {

// given
var dataObjectReference = elementRegistry.get('DataObjectReference_1');
Expand Down Expand Up @@ -188,6 +189,104 @@ describe('features/popup-menu - replace menu provider', function() {
// then
expect(domClasses(isCollectionMarker).has('active')).to.be.false;
}));

});


describe('participants - multiplicity marker', function() {

beforeEach(bootstrapModeler(diagramXMLParticipants, { modules: testModules }));


it('should toggle on', inject(function(elementRegistry) {

// given
var participant = elementRegistry.get('Participant_1');

openPopup(participant);

// when
triggerAction('toggle-participant-multiplicity');

openPopup(participant);

var multiplicityMarker = queryEntry('toggle-participant-multiplicity');

// then
expect(domClasses(multiplicityMarker).has('active')).to.be.true;
expect(participant.businessObject.participantMultiplicity).to.be.true;
}));


it('should undo', inject(function(commandStack, elementRegistry) {

// given
var participant = elementRegistry.get('Participant_1');

openPopup(participant);

triggerAction('toggle-participant-multiplicity');

// when
commandStack.undo();

openPopup(participant);

var multiplicityMarker = queryEntry('toggle-participant-multiplicity');

// then
expect(domClasses(multiplicityMarker).has('active')).not.to.be.true;
expect(participant.businessObject.participantMultiplicity).not.to.be.true;
}));


it('should redo', inject(function(commandStack, elementRegistry) {

// given
var participant = elementRegistry.get('Participant_1');

openPopup(participant);

triggerAction('toggle-participant-multiplicity');

commandStack.undo();

// when
commandStack.redo();

openPopup(participant);

var multiplicityMarker = queryEntry('toggle-participant-multiplicity');

// then
expect(domClasses(multiplicityMarker).has('active')).to.be.true;
expect(participant.businessObject.participantMultiplicity).to.be.true;
}));


it('should toggle off', inject(function(elementRegistry) {

// given
var participant = elementRegistry.get('Participant_1');

openPopup(participant);

triggerAction('toggle-participant-multiplicity');

openPopup(participant);

// when
triggerAction('toggle-participant-multiplicity');

openPopup(participant);

var multiplicityMarker = queryEntry('toggle-participant-multiplicity');

// then
expect(domClasses(multiplicityMarker).has('active')).to.be.false;
expect(participant.businessObject.participantMultiplicity).to.be.false;
}));

});


Expand Down

0 comments on commit 1d9e718

Please sign in to comment.