feat(modeling): ignore lanes when connecting message flows
Closes #950 Related to camunda/camunda-modeler#1213
This commit is contained in:
parent
055fdf75e1
commit
19be51abc7
|
@ -44,6 +44,52 @@ export default function FixHoverBehavior(elementRegistry, eventBus, canvas) {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
eventBus.on([
|
||||
'connect.hover',
|
||||
'global-connect.hover'
|
||||
], HIGH_PRIORITY, function(event) {
|
||||
var hover = event.hover;
|
||||
|
||||
// ensure connections start/end on bpmn:Participant,
|
||||
// not the underlying bpmn:Lane
|
||||
if (is(hover, 'bpmn:Lane')) {
|
||||
event.hover = getLanesRoot(hover) || hover;
|
||||
event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
eventBus.on([
|
||||
'bendpoint.move.hover'
|
||||
], HIGH_PRIORITY, function(event) {
|
||||
var context = event.context,
|
||||
type = context.type,
|
||||
hover = event.hover;
|
||||
|
||||
// ensure reconnect start/end on bpmn:Participant,
|
||||
// not the underlying bpmn:Lane
|
||||
if (is(hover, 'bpmn:Lane') && /reconnect/.test(type)) {
|
||||
event.hover = getLanesRoot(hover) || hover;
|
||||
event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
eventBus.on([
|
||||
'connect.start'
|
||||
], HIGH_PRIORITY, function(event) {
|
||||
|
||||
var context = event.context,
|
||||
source = context.source;
|
||||
|
||||
// ensure connect start on bpmn:Participant,
|
||||
// not the underlying bpmn:Lane
|
||||
if (is(source, 'bpmn:Lane')) {
|
||||
context.source = getLanesRoot(source) || source;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
FixHoverBehavior.$inject = [
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="4.0.0-beta.1">
|
||||
<collaboration id="Collaboration_07d1e5q">
|
||||
<participant id="Participant_No_Lanes" processRef="Process_1" />
|
||||
<participant id="Participant_Lanes" processRef="Process_2" />
|
||||
<messageFlow id="MessageFlow_1" sourceRef="Participant_No_Lanes" targetRef="Participant_Lanes" />
|
||||
<messageFlow id="MessageFlow_2" sourceRef="Participant_Lanes" targetRef="Participant_No_Lanes" />
|
||||
</collaboration>
|
||||
<process id="Process_1" isExecutable="false">
|
||||
<task id="Task" />
|
||||
</process>
|
||||
<process id="Process_2">
|
||||
<laneSet id="LaneSet_1hz9u1w">
|
||||
<lane id="Lane_1" />
|
||||
<lane id="Lane_2" />
|
||||
</laneSet>
|
||||
</process>
|
||||
<bpmndi:BPMNDiagram id="BpmnDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Collaboration_07d1e5q">
|
||||
<bpmndi:BPMNShape id="Participant_No_Lanes_di" bpmnElement="Participant_No_Lanes" isHorizontal="true">
|
||||
<omgdc:Bounds x="180" y="90" width="460" height="140" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Task_di" bpmnElement="Task">
|
||||
<omgdc:Bounds x="330" y="120" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Participant_Lanes_di" bpmnElement="Participant_Lanes" isHorizontal="true">
|
||||
<omgdc:Bounds x="180" y="280" width="460" height="240" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Lane_1_di" bpmnElement="Lane_1" isHorizontal="true">
|
||||
<omgdc:Bounds x="210" y="280" width="430" height="120" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Lane_2_di" bpmnElement="Lane_2" isHorizontal="true">
|
||||
<omgdc:Bounds x="210" y="400" width="430" height="120" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge id="MessageFlow_1_di" bpmnElement="MessageFlow_1">
|
||||
<di:waypoint x="510" y="230" />
|
||||
<di:waypoint x="510" y="280" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="MessageFlow_2_di" bpmnElement="MessageFlow_2">
|
||||
<di:waypoint x="540" y="280" />
|
||||
<di:waypoint x="540" y="230" />
|
||||
</bpmndi:BPMNEdge>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</definitions>
|
|
@ -7,9 +7,13 @@ 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 globalConnectModule from 'diagram-js/lib/features/global-connect';
|
||||
import bendpointsModule from 'diagram-js/lib/features/bendpoints';
|
||||
|
||||
import { createCanvasEvent as canvasEvent } from '../../../../util/MockEvents';
|
||||
|
||||
/* global sinon */
|
||||
var spy = sinon.spy;
|
||||
|
||||
var testModules = [
|
||||
coreModule,
|
||||
|
@ -18,6 +22,7 @@ var testModules = [
|
|||
modelingModule
|
||||
];
|
||||
|
||||
|
||||
describe('features/modeling/behavior - fix hover', function() {
|
||||
|
||||
describe('drop on lane', function() {
|
||||
|
@ -205,4 +210,176 @@ describe('features/modeling/behavior - fix hover', function() {
|
|||
|
||||
});
|
||||
|
||||
|
||||
describe('connect lane', function() {
|
||||
|
||||
var diagramXML = require('./FixHoverBehavior.lane-connect.bpmn');
|
||||
|
||||
beforeEach(bootstrapModeler(diagramXML, {
|
||||
modules: testModules.concat([
|
||||
globalConnectModule,
|
||||
bendpointsModule
|
||||
])
|
||||
}));
|
||||
|
||||
beforeEach(inject(function(dragging) {
|
||||
dragging.setOptions({ manual: true });
|
||||
}));
|
||||
|
||||
|
||||
it('should set global connect source to participant', inject(
|
||||
function(globalConnect, elementRegistry, eventBus, dragging) {
|
||||
|
||||
// given
|
||||
var participant_lanes = elementRegistry.get('Participant_Lanes');
|
||||
var lane_1 = elementRegistry.get('Lane_1');
|
||||
|
||||
var connectSpy = spy(function(event) {
|
||||
expect(event.context.startTarget).to.eql(participant_lanes);
|
||||
});
|
||||
|
||||
eventBus.once('global-connect.end', connectSpy);
|
||||
|
||||
// when
|
||||
globalConnect.start(canvasEvent({ x: 0, y: 0 }));
|
||||
|
||||
dragging.move(canvasEvent({ x: 150, y: 130 }));
|
||||
dragging.hover(canvasEvent({ x: 150, y: 130 }, { element: lane_1 }));
|
||||
dragging.end(canvasEvent({ x: 0, y: 0 }));
|
||||
|
||||
// then
|
||||
expect(connectSpy).to.have.been.called;
|
||||
}
|
||||
));
|
||||
|
||||
|
||||
describe('reconnect', function() {
|
||||
|
||||
it('should set start to participant', inject(
|
||||
function(bendpointMove, elementRegistry, eventBus, dragging) {
|
||||
|
||||
// given
|
||||
var participant_lanes = elementRegistry.get('Participant_Lanes');
|
||||
var lane_1 = elementRegistry.get('Lane_1');
|
||||
|
||||
var messageFlow = elementRegistry.get('MessageFlow_2');
|
||||
|
||||
var connectSpy = spy(function(event) {
|
||||
expect(event.context.target).to.eql(participant_lanes);
|
||||
});
|
||||
|
||||
eventBus.once('bendpoint.move.end', connectSpy);
|
||||
|
||||
// when
|
||||
bendpointMove.start(canvasEvent({ x: 240, y: 200 }), messageFlow, 0);
|
||||
dragging.move(canvasEvent({ x: 240, y: 280 }));
|
||||
|
||||
dragging.hover({ element: lane_1, gfx: elementRegistry.getGraphics(lane_1) });
|
||||
dragging.end();
|
||||
|
||||
// then
|
||||
expect(connectSpy).to.have.been.called;
|
||||
}
|
||||
));
|
||||
|
||||
|
||||
it('should set end to participant', inject(
|
||||
function(bendpointMove, elementRegistry, eventBus, dragging) {
|
||||
|
||||
// given
|
||||
var participant_lanes = elementRegistry.get('Participant_Lanes');
|
||||
var lane_1 = elementRegistry.get('Lane_1');
|
||||
|
||||
var messageFlow = elementRegistry.get('MessageFlow_1');
|
||||
|
||||
var connectSpy = spy(function(event) {
|
||||
expect(event.context.target).to.eql(participant_lanes);
|
||||
});
|
||||
|
||||
eventBus.once('bendpoint.move.end', connectSpy);
|
||||
|
||||
// when
|
||||
bendpointMove.start(canvasEvent({ x: 240, y: 200 }), messageFlow, 1);
|
||||
dragging.move(canvasEvent({ x: 240, y: 280 }));
|
||||
|
||||
dragging.hover({ element: lane_1, gfx: elementRegistry.getGraphics(lane_1) });
|
||||
dragging.end();
|
||||
|
||||
// then
|
||||
expect(connectSpy).to.have.been.called;
|
||||
}
|
||||
));
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('connect', function() {
|
||||
|
||||
it('should set start to participant', inject(
|
||||
function(connect, dragging, elementRegistry, eventBus) {
|
||||
|
||||
// given
|
||||
var participant_lanes = elementRegistry.get('Participant_Lanes');
|
||||
var participant_no_lanes = elementRegistry.get('Participant_No_Lanes');
|
||||
var lane_1 = elementRegistry.get('Lane_1');
|
||||
|
||||
var connectSpy = spy(function(event) {
|
||||
|
||||
var context = event.context,
|
||||
source = context.source;
|
||||
|
||||
expect(source).to.eql(participant_lanes);
|
||||
});
|
||||
|
||||
eventBus.once('connect.end', connectSpy);
|
||||
|
||||
// when
|
||||
connect.start(canvasEvent({ x: 240, y: 300 }), lane_1);
|
||||
|
||||
dragging.move(canvasEvent({ x: 240, y: 0 }));
|
||||
|
||||
dragging.hover(canvasEvent({ x: 240, y: 0 }, { element: participant_no_lanes }));
|
||||
dragging.end();
|
||||
|
||||
// then
|
||||
expect(connectSpy).to.have.been.called;
|
||||
}
|
||||
));
|
||||
|
||||
|
||||
it('should set end to participant', inject(
|
||||
function(connect, dragging, elementRegistry, eventBus) {
|
||||
|
||||
// given
|
||||
var participant_lanes = elementRegistry.get('Participant_Lanes');
|
||||
var participant_no_lanes = elementRegistry.get('Participant_No_Lanes');
|
||||
var lane_1 = elementRegistry.get('Lane_1');
|
||||
|
||||
var connectSpy = spy(function(event) {
|
||||
|
||||
var context = event.context,
|
||||
target = context.target;
|
||||
|
||||
expect(target).to.eql(participant_lanes);
|
||||
});
|
||||
|
||||
eventBus.once('connect.end', connectSpy);
|
||||
|
||||
// when
|
||||
connect.start(canvasEvent({ x: 240, y: 0 }), participant_no_lanes);
|
||||
|
||||
dragging.move(canvasEvent({ x: 240, y: 300 }));
|
||||
|
||||
dragging.hover(canvasEvent({ x: 240, y: 300 }, { element: lane_1 }));
|
||||
dragging.end();
|
||||
|
||||
// then
|
||||
expect(connectSpy).to.have.been.called;
|
||||
}
|
||||
));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue