Skip to content

Commit

Permalink
feat(modeling): add isHorizontal=true to participant/lane di shapes
Browse files Browse the repository at this point in the history
Closes #934
  • Loading branch information
barmac committed Jan 30, 2019
1 parent ef09e1a commit a080f0d
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/features/modeling/behavior/IsHorizontalFix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
getBusinessObject
} from '../../../util/ModelUtil';

import {
isAny
} from '../util/ModelingUtil';

/**
* A component that makes sure that each created or updated
* Pool and Lane is assigned an isHorizontal property set to true.
*
* @param {EventBus} eventBus
*/
export default function IsHorizontalFix(eventBus) {

var elementTypesToUpdate = [
'bpmn:Participant',
'bpmn:Lane'
];

eventBus.on('element.changed', function(context) {
var bo = getBusinessObject(context.element);

if (isAny(bo, elementTypesToUpdate) && !bo.di.get('isHorizontal')) {
// set attribute directly to avoid modeling#updateProperty side effects
bo.di.set('isHorizontal', true);
}
});

}

IsHorizontalFix.$inject = [ 'eventBus' ];
3 changes: 3 additions & 0 deletions lib/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import DataStoreBehavior from './DataStoreBehavior';
import DeleteLaneBehavior from './DeleteLaneBehavior';
import DropOnFlowBehavior from './DropOnFlowBehavior';
import ImportDockingFix from './ImportDockingFix';
import IsHorizontalFix from './IsHorizontalFix';
import LabelBehavior from './LabelBehavior';
import ModelingFeedback from './ModelingFeedback';
import ReplaceConnectionBehavior from './ReplaceConnectionBehavior';
Expand All @@ -36,6 +37,7 @@ export default {
'deleteLaneBehavior',
'dropOnFlowBehavior',
'importDockingFix',
'isHorizontalFix',
'labelBehavior',
'modelingFeedback',
'removeElementBehavior',
Expand All @@ -60,6 +62,7 @@ export default {
deleteLaneBehavior: [ 'type', DeleteLaneBehavior ],
dropOnFlowBehavior: [ 'type', DropOnFlowBehavior ],
importDockingFix: [ 'type', ImportDockingFix ],
isHorizontalFix: [ 'type', IsHorizontalFix ],
labelBehavior: [ 'type', LabelBehavior ],
modelingFeedback: [ 'type', ModelingFeedback ],
replaceConnectionBehavior: [ 'type', ReplaceConnectionBehavior ],
Expand Down
40 changes: 40 additions & 0 deletions test/spec/features/modeling/behavior/IsHorizontalFix.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions 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:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_0f2kqle" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="2.2.4">
<bpmn:collaboration id="Collaboration_08digmd">
<bpmn:participant id="Participant" processRef="Process_1" />
</bpmn:collaboration>
<bpmn:process id="Process_1">
<bpmn:laneSet id="LaneSet_13y425u">
<bpmn:lane id="Lane">
<bpmn:flowNodeRef>StartEvent_1</bpmn:flowNodeRef>
</bpmn:lane>
<bpmn:lane id="Lane_2" />
</bpmn:laneSet>
<bpmn:startEvent id="StartEvent_1">
<bpmn:extensionElements>
<camunda:executionListener event="start">
<camunda:script scriptFormat="groovy">println execution.eventName</camunda:script>
</camunda:executionListener>
<camunda:executionListener event="end">
<camunda:script scriptFormat="groovy">println end</camunda:script>
</camunda:executionListener>
</bpmn:extensionElements>
</bpmn:startEvent>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_08digmd">
<bpmndi:BPMNShape id="Participant_di" bpmnElement="Participant">
<dc:Bounds x="123" y="82" width="600" height="370" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="173" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Lane_di" bpmnElement="Lane">
<dc:Bounds x="153" y="82" width="570" height="250" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Lane_2_di" bpmnElement="Lane_2">
<dc:Bounds x="153" y="332" width="570" height="120" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
104 changes: 104 additions & 0 deletions test/spec/features/modeling/behavior/IsHorizontalFixSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
bootstrapModeler,
inject
} from 'test/TestHelper';

import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';

import { getBusinessObject } from 'lib/util/ModelUtil';


describe('features/modeling/behavior - IsHorizontalFix', function() {

var diagramXML;

describe('set on change', function() {

diagramXML = require('./IsHorizontalFix.bpmn');

beforeEach(bootstrapModeler(diagramXML, {
modules: [
coreModule,
modelingModule
]
}));


it('should set isHorizontal=true when participant is changed', inject(function(elementRegistry, modeling) {

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

// when
modeling.updateProperties(participant, {});

// then
var isHorizontal = getBusinessObject(participant).di.get('isHorizontal');

expect(isHorizontal).to.be.true;
}));


it('should set isHorizontal=true when lane is changed', inject(function(elementRegistry, modeling) {

// given
var lane = elementRegistry.get('Lane');

// when
modeling.updateProperties(lane, {});

// then
var isHorizontal = getBusinessObject(lane).di.get('isHorizontal');

expect(isHorizontal).to.be.true;
}));

});


describe('set on create', function() {

diagramXML = require('test/fixtures/bpmn/simple.bpmn');

beforeEach(bootstrapModeler(diagramXML, {
modules: [
coreModule,
modelingModule
]
}));


it('should set isHorizontal=true when participant is created', inject(function(canvas, elementFactory, modeling) {
// given
var processShape = canvas.getRootElement(),
participantShape = elementFactory.createParticipantShape(true);

// when
var participant = modeling.createShape(participantShape, { x: 350, y: 200 }, processShape);

// then
var isHorizontal = getBusinessObject(participant).di.get('isHorizontal');

expect(isHorizontal).to.be.true;
}));


it('should set isHorizontal=true when lane is created', inject(function(canvas, elementFactory, modeling) {
// given
var processShape = canvas.getRootElement(),
participantShape = elementFactory.createParticipantShape(true),
participant = modeling.createShape(participantShape, { x: 350, y: 200 }, processShape);

// when
var lane = modeling.addLane(participant, 'bottom');

// then
var isHorizontal = getBusinessObject(lane).di.get('isHorizontal');

expect(isHorizontal).to.be.true;
}));

});

});

0 comments on commit a080f0d

Please sign in to comment.