Skip to content

Commit

Permalink
chore(bpmn-snapping): move create behavior to seperate behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed May 23, 2019
1 parent 20672f6 commit 3f42925
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/features/modeling/behavior/CreateBehavior.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getLanesRoot } from '../util/LaneUtil';

import { is } from '../../../util/ModelUtil';

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

var HIGH_PRIORITY = 1500;

/**
* Ensure hovering participant during create and move.
*
* @param {ElementRegistry} elementRegistry
* @param {EventBus} eventBus
*/
export default function CreateBehavior(elementRegistry, eventBus) {
eventBus.on([
'create.hover',
'create.move',
'create.end',
'shape.move.hover',
'shape.move.move',
'shape.move.end'
], HIGH_PRIORITY, function(event) {
var context = event.context,
shape = context.shape,
hover = event.hover;

if (is(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
event.hover = getLanesRoot(hover);
event.hoverGfx = elementRegistry.getGraphics(event.hover);
}
});
}

CreateBehavior.$inject = [
'elementRegistry',
'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 @@ -2,6 +2,7 @@ import AdaptiveLabelPositioningBehavior from './AdaptiveLabelPositioningBehavior
import AppendBehavior from './AppendBehavior';
import BoundaryEventBehavior from './BoundaryEventBehavior';
import CopyPasteBehavior from './CopyPasteBehavior';
import CreateBehavior from './CreateBehavior';
import CreateBoundaryEventBehavior from './CreateBoundaryEventBehavior';
import CreateDataObjectBehavior from './CreateDataObjectBehavior';
import CreateParticipantBehavior from './CreateParticipantBehavior';
Expand Down Expand Up @@ -33,6 +34,7 @@ export default {
'appendBehavior',
'boundaryEventBehavior',
'copyPasteBehavior',
'createBehavior',
'createBoundaryEventBehavior',
'createDataObjectBehavior',
'dataStoreBehavior',
Expand Down Expand Up @@ -62,6 +64,7 @@ export default {
appendBehavior: [ 'type', AppendBehavior ],
boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
copyPasteBehavior: [ 'type', CopyPasteBehavior ],
createBehavior: [ 'type', CreateBehavior ],
createBoundaryEventBehavior: [ 'type', CreateBoundaryEventBehavior ],
createDataObjectBehavior: [ 'type', CreateDataObjectBehavior ],
createParticipantBehavior: [ 'type', CreateParticipantBehavior ],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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" id="Definitions_033nbwh" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.1.0">
<bpmn:collaboration id="Collaboration_1hb173f">
<bpmn:participant id="Participant_1" processRef="Process_1" />
</bpmn:collaboration>
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:laneSet id="LaneSet_01fnrsu">
<bpmn:lane id="Lane_1">
<bpmn:flowNodeRef>Task_1</bpmn:flowNodeRef>
</bpmn:lane>
<bpmn:lane id="Lane_2" />
</bpmn:laneSet>
<bpmn:task id="Task_1" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1hb173f">
<bpmndi:BPMNShape id="Participant_00m5vpq_di" bpmnElement="Participant_1" isHorizontal="true">
<dc:Bounds x="100" y="100" width="600" height="370" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Lane_0wx2ruq_di" bpmnElement="Lane_1" isHorizontal="true">
<dc:Bounds x="130" y="100" width="570" height="250" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Lane_1guzz8c_di" bpmnElement="Lane_2" isHorizontal="true">
<dc:Bounds x="130" y="350" width="570" height="120" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_1dr11gk_di" bpmnElement="Task_1">
<dc:Bounds x="400" y="200" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
93 changes: 93 additions & 0 deletions test/spec/features/modeling/behavior/CreateBehaviorSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {
bootstrapModeler,
inject
} from 'test/TestHelper';

import coreModule from 'lib/core';
import createModule from 'diagram-js/lib/features/create';
import modelingModule from 'lib/features/modeling';
import moveModule from 'diagram-js/lib/features/move';

import { createCanvasEvent as canvasEvent } from '../../../../util/MockEvents';


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

var testModules = [
coreModule,
createModule,
moveModule,
modelingModule
];

var diagramXML = require('./CreateBehavior.participant.bpmn');

beforeEach(bootstrapModeler(diagramXML, {
modules: testModules
}));

beforeEach(inject(function(dragging) {
dragging.setOptions({ manual: true });
}));

var lane,
laneGfx,
participant;

beforeEach(inject(function(elementRegistry) {
participant = elementRegistry.get('Participant_1');

lane = elementRegistry.get('Lane_1');
laneGfx = elementRegistry.getGraphics(lane);
}));

describe('create', function() {

it('should ensure hovering participant', inject(
function(create, dragging, elementFactory) {

// given
var task = elementFactory.createShape({ type: 'bpmn:Task' });

create.start(canvasEvent({ x: 0, y: 0 }), task, true);

// when
dragging.hover({ element: lane, gfx: laneGfx });

dragging.move(canvasEvent({ x: 200, y: 200 }));

dragging.end();

// then
expect(task.parent).to.equal(participant);
}
));

});


describe('move', function() {

it('should ensure hovering participant', inject(
function(dragging, elementRegistry, move) {

// given
var task = elementRegistry.get('Task_1');

move.start(canvasEvent({ x: 440, y: 220 }), task, true);

// when
dragging.hover({ element: lane, gfx: laneGfx });

dragging.move(canvasEvent({ x: 240, y: 220 }));

dragging.end();

// then
expect(task.parent).to.equal(participant);
}
));

});

});

0 comments on commit 3f42925

Please sign in to comment.