feat(modeling): drop new intermediateThrowEvents on sequenceFlows
Related to #232
This commit is contained in:
parent
247594dbbf
commit
58f5965335
|
@ -25,6 +25,11 @@ function CreateBehavior(eventBus, modeling) {
|
|||
shape = context.shape,
|
||||
position = context.position;
|
||||
|
||||
if (is(parent, 'bpmn:SequenceFlow')){
|
||||
context.insertTarget = parent;
|
||||
context.parent = context.parent.parent;
|
||||
}
|
||||
|
||||
if (is(parent, 'bpmn:Process') && is(shape, 'bpmn:Participant')) {
|
||||
|
||||
// this is going to detach the process root
|
||||
|
@ -75,6 +80,20 @@ function CreateBehavior(eventBus, modeling) {
|
|||
var processChildren = processRoot.children.slice();
|
||||
modeling.moveShapes(processChildren, { x: 0, y: 0 }, shape);
|
||||
}
|
||||
|
||||
if (context.insertTarget) {
|
||||
|
||||
var initialTarget = context.insertTarget.target;
|
||||
var insertShape = context.shape;
|
||||
|
||||
// reconnecting end to inserted shape
|
||||
modeling.reconnectEnd(context.insertTarget, insertShape, context.position);
|
||||
|
||||
// create new connection between inserted shape and initial target
|
||||
modeling.createConnection(insertShape, initialTarget, {
|
||||
type: context.insertTarget.type,
|
||||
}, context.parent);
|
||||
}
|
||||
}, true);
|
||||
|
||||
}
|
||||
|
|
|
@ -339,6 +339,10 @@ function canCreate(shape, target, source) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (canInsert(shape, target)){
|
||||
return true;
|
||||
}
|
||||
|
||||
return canDrop(shape, target);
|
||||
}
|
||||
|
||||
|
@ -386,3 +390,21 @@ function canConnectSequenceFlow(source, target) {
|
|||
isSameScope(source, target) &&
|
||||
!(is(source, 'bpmn:EventBasedGateway') && !isEventBasedTarget(target));
|
||||
}
|
||||
|
||||
function canInsert(shape, target) {
|
||||
|
||||
var startEvent = target.source;
|
||||
var endEvent = target.target;
|
||||
|
||||
if (!is(target, 'bpmn:SequenceFlow')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(is(shape, 'bpmn:IntermediateThrowEvent') &&
|
||||
is(startEvent, 'bpmn:FlowElement') &&
|
||||
is(endEvent, 'bpmn:FlowElement')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
'use strict';
|
||||
|
||||
var TestHelper = require('../../../TestHelper');
|
||||
|
||||
describe('drop on conection', function(){
|
||||
|
||||
var bpmnRules = require('../../../../lib/features/modeling/rules');
|
||||
var diagramXML = require('./diagram.bpmn');
|
||||
|
||||
beforeEach(bootstrapModeler(diagramXML, {modules: bpmnRules}));
|
||||
|
||||
it('should be allowed for an IntermediateThrowEvent', inject(function(elementRegistry, bpmnRules, elementFactory) {
|
||||
var sequenceFlow = elementRegistry.get('SequenceFlow_0lk9mnl');
|
||||
var intermediateThrowEvent = elementFactory.createShape({ type: 'bpmn:IntermediateThrowEvent' });
|
||||
|
||||
expect(bpmnRules.canCreate(intermediateThrowEvent, sequenceFlow)).toBe(true);
|
||||
}));
|
||||
|
||||
it('should rearrange connections', inject(function(modeling, elementRegistry, elementFactory){
|
||||
var intermediateThrowEvent = elementFactory.createShape({ type: 'bpmn:IntermediateThrowEvent' });
|
||||
var startEvent = elementRegistry.get('StartEvent_1');
|
||||
var sequenceFlow = elementRegistry.get('SequenceFlow_0lk9mnl');
|
||||
var task = elementRegistry.get('Task_195jx60');
|
||||
var position = {x: startEvent.x + startEvent.height/2 + 100,
|
||||
y: startEvent.y + startEvent.width/2};
|
||||
|
||||
// create new intermediateThrowEvent onto sequenceFlow
|
||||
modeling.createShape(intermediateThrowEvent, position, sequenceFlow);
|
||||
|
||||
// check rearragned connection
|
||||
expect(startEvent.outgoing[0].id).toBe(intermediateThrowEvent.incoming[0].id);
|
||||
|
||||
// check newly created connection
|
||||
expect(intermediateThrowEvent.outgoing[0].id).toBe(task.incoming[0].id);
|
||||
}));
|
||||
});
|
|
@ -0,0 +1,29 @@
|
|||
<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
|
||||
<bpmn:process id="Process_1" isExecutable="false">
|
||||
<bpmn:startEvent id="StartEvent_1">
|
||||
<bpmn:outgoing>SequenceFlow_0lk9mnl</bpmn:outgoing>
|
||||
</bpmn:startEvent>
|
||||
<bpmn:task id="Task_195jx60">
|
||||
<bpmn:incoming>SequenceFlow_0lk9mnl</bpmn:incoming>
|
||||
</bpmn:task>
|
||||
<bpmn:sequenceFlow id="SequenceFlow_0lk9mnl" sourceRef="StartEvent_1" targetRef="Task_195jx60" />
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
|
||||
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
|
||||
<dc:Bounds x="173" y="102" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Task_195jx60_di" bpmnElement="Task_195jx60">
|
||||
<dc:Bounds x="476" y="80" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_0lk9mnl_di" bpmnElement="SequenceFlow_0lk9mnl">
|
||||
<di:waypoint xsi:type="dc:Point" x="209" y="120" />
|
||||
<di:waypoint xsi:type="dc:Point" x="476" y="120" />
|
||||
<bpmndi:BPMNLabel>
|
||||
<dc:Bounds x="297.5" y="110" width="90" height="20" />
|
||||
</bpmndi:BPMNLabel>
|
||||
</bpmndi:BPMNEdge>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
Loading…
Reference in New Issue