Skip to content

Commit

Permalink
feat(modeling): set isHorizontal=true for partipant/lane DIs
Browse files Browse the repository at this point in the history
Closes #934
  • Loading branch information
barmac authored and merge-me[bot] committed Jan 31, 2019
1 parent 762b3d2 commit 39d4f1c
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/features/modeling/behavior/IsHorizontalFix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import inherits from 'inherits';

import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

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) {

CommandInterceptor.call(this, eventBus);

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

this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], function(event) {
var bo = getBusinessObject(event.context.shape);

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' ];

inherits(IsHorizontalFix, CommandInterceptor);
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>
237 changes: 237 additions & 0 deletions test/spec/features/modeling/behavior/IsHorizontalFixSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
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 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;
})
);

});


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

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

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


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

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

// when
modeling.moveElements([ participant ], { x: 0, y: 0 });

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

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


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

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

// when
modeling.moveElements([ lane ], { x: 0, y: 0 });

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

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


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

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

// when
modeling.resizeShape(participant, { x: 0, y: 0, width: 10, height: 10 });

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

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


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

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

// when
modeling.resizeLane(lane, { x: 0, y: 0, width: 10, height: 10 });

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

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

});


describe('never unset on revert', function() {

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

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


it('should not unset isHorizontal=true when participant move action is reverted',
inject(function(commandStack, elementRegistry, modeling) {

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

modeling.moveElements([ participant ], { x: 0, y: 0 });

// when
commandStack.undo();

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

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


it('should not unset isHorizontal=true when lane move action is reverted',
inject(function(commandStack, elementRegistry, modeling) {

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

modeling.moveElements([ lane ], { x: 0, y: 0 });

// when
commandStack.undo();

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

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


it('should not unset isHorizontal=true when participant resize action is reverted',
inject(function(commandStack, elementRegistry, modeling) {

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

modeling.resizeShape(participant, { x: 0, y: 0, width: 10, height: 10 });

// when
commandStack.undo();

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

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


it('should not unset isHorizontal=true when lane resize action is reverted',
inject(function(commandStack, elementRegistry, modeling) {

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

modeling.resizeLane(lane, { x: 0, y: 0, width: 10, height: 10 });

// when
commandStack.undo();

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

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

});

});

0 comments on commit 39d4f1c

Please sign in to comment.