-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modeling): set isHorizontal=true for partipant/lane DIs
Closes #934
- Loading branch information
1 parent
762b3d2
commit 39d4f1c
Showing
4 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
237
test/spec/features/modeling/behavior/IsHorizontalFixSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}) | ||
); | ||
|
||
}); | ||
|
||
}); |