-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modeling): add isHorizontal=true to participant/lane di shapes
Closes #934
- Loading branch information
Showing
4 changed files
with
180 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,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' ]; |
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> |
104 changes: 104 additions & 0 deletions
104
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,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; | ||
})); | ||
|
||
}); | ||
|
||
}); |