mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-14 02:54:37 +00:00
feat(replace): add multiplicity marker to replace menu for participants
Closes #533
This commit is contained in:
parent
0c227dc80a
commit
5eff166135
@ -1648,7 +1648,7 @@ export default function BpmnRenderer(
|
||||
});
|
||||
|
||||
drawMarker('participant-multiplicity', parentGfx, markerPath, {
|
||||
strokeWidth: 1,
|
||||
strokeWidth: 2,
|
||||
fill: getFillColor(element, defaultFillColor),
|
||||
stroke: getStrokeColor(element, defaultStrokeColor)
|
||||
});
|
||||
|
@ -24,9 +24,10 @@ import * as replaceOptions from '../replace/ReplaceOptions';
|
||||
* This module is an element agnostic replace menu provider for the popup menu.
|
||||
*/
|
||||
export default function ReplaceMenuProvider(
|
||||
popupMenu, modeling, moddle,
|
||||
bpmnFactory, popupMenu, modeling, moddle,
|
||||
bpmnReplace, rules, translate) {
|
||||
|
||||
this._bpmnFactory = bpmnFactory;
|
||||
this._popupMenu = popupMenu;
|
||||
this._modeling = modeling;
|
||||
this._moddle = moddle;
|
||||
@ -38,6 +39,7 @@ export default function ReplaceMenuProvider(
|
||||
}
|
||||
|
||||
ReplaceMenuProvider.$inject = [
|
||||
'bpmnFactory',
|
||||
'popupMenu',
|
||||
'modeling',
|
||||
'moddle',
|
||||
@ -268,6 +270,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)) {
|
||||
@ -486,7 +492,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
|
||||
*
|
||||
@ -519,6 +525,46 @@ 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 bpmnFactory = this._bpmnFactory;
|
||||
var translate = this._translate;
|
||||
|
||||
function toggleParticipantMultiplicity(event, entry) {
|
||||
var isActive = entry.active;
|
||||
var participantMultiplicity;
|
||||
|
||||
if (!isActive) {
|
||||
participantMultiplicity = bpmnFactory.create('bpmn:ParticipantMultiplicity');
|
||||
}
|
||||
|
||||
self._modeling.updateProperties(
|
||||
element,
|
||||
{ participantMultiplicity: participantMultiplicity });
|
||||
}
|
||||
|
||||
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
|
||||
|
14
test/fixtures/bpmn/features/replace/participants.bpmn
vendored
Normal file
14
test/fixtures/bpmn/features/replace/participants.bpmn
vendored
Normal file
@ -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>
|
@ -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,
|
||||
@ -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');
|
||||
@ -93,12 +94,12 @@ describe('features/popup-menu - replace menu provider', function() {
|
||||
var isCollectionMarker = queryEntry('toggle-is-collection');
|
||||
|
||||
// then
|
||||
expect(domClasses(isCollectionMarker).has('active')).not.to.be.true;
|
||||
expect(domClasses(isCollectionMarker).has('active')).to.be.false;
|
||||
expect(dataObjectReference.businessObject.dataObjectRef.isCollection).not.to.be.true;
|
||||
}));
|
||||
|
||||
|
||||
it('should redo toggle on', inject(function(commandStack, elementRegistry) {
|
||||
it('should redo', inject(function(commandStack, elementRegistry) {
|
||||
|
||||
// given
|
||||
var dataObjectReference = elementRegistry.get('DataObjectReference_1');
|
||||
@ -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.exist;
|
||||
}));
|
||||
|
||||
|
||||
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')).to.be.false;
|
||||
expect(participant.businessObject.participantMultiplicity).not.to.exist;
|
||||
}));
|
||||
|
||||
|
||||
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.exist;
|
||||
}));
|
||||
|
||||
|
||||
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).not.to.exist;
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user