fix(modeling): sequence flow can be reconnected to participant
Closes #315
This commit is contained in:
parent
8c6c920482
commit
363ce892c9
|
@ -7,6 +7,9 @@ var assign = require('lodash/object/assign'),
|
|||
var Collections = require('diagram-js/lib/util/Collections'),
|
||||
Model = require('diagram-js/lib/model');
|
||||
|
||||
var getBusinessObject = require('../../util/ModelUtil').getBusinessObject,
|
||||
is = require('../../util/ModelUtil').is;
|
||||
|
||||
var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
||||
|
||||
|
||||
|
@ -75,7 +78,7 @@ function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) {
|
|||
/*
|
||||
* ## Updating Parent
|
||||
*
|
||||
* When morphing a Process into a Collaboration or vice-versa,
|
||||
* When morphing a Process into a Collaboration or vice-versa,
|
||||
* make sure that both the *semantic* and *di* parent of each element
|
||||
* is updated.
|
||||
*
|
||||
|
@ -193,7 +196,7 @@ BpmnUpdater.prototype.updateBounds = function(shape) {
|
|||
|
||||
BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
|
||||
|
||||
if (parentDi && !parentDi.$instanceOf('bpmndi:BPMNPlane')) {
|
||||
if (parentDi && !is(parentDi, 'bpmndi:BPMNPlane')) {
|
||||
parentDi = parentDi.$parent;
|
||||
}
|
||||
|
||||
|
@ -213,7 +216,7 @@ BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
|
|||
};
|
||||
|
||||
function getDefinitions(element) {
|
||||
while (element && !element.$instanceOf('bpmn:Definitions')) {
|
||||
while (element && !is(element, 'bpmn:Definitions')) {
|
||||
element = element.$parent;
|
||||
}
|
||||
|
||||
|
@ -228,9 +231,9 @@ BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent)
|
|||
return;
|
||||
}
|
||||
|
||||
if (businessObject.$instanceOf('bpmn:FlowElement')) {
|
||||
if (is(businessObject, 'bpmn:FlowElement')) {
|
||||
|
||||
if (newParent && newParent.$instanceOf('bpmn:Participant')) {
|
||||
if (newParent && is(newParent, 'bpmn:Participant')) {
|
||||
newParent = newParent.processRef;
|
||||
}
|
||||
|
||||
|
@ -238,14 +241,14 @@ BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent)
|
|||
|
||||
} else
|
||||
|
||||
if (businessObject.$instanceOf('bpmn:Artifact')) {
|
||||
if (is(businessObject, 'bpmn:Artifact')) {
|
||||
|
||||
while (newParent &&
|
||||
!newParent.$instanceOf('bpmn:Process') &&
|
||||
!newParent.$instanceOf('bpmn:SubProcess') &&
|
||||
!newParent.$instanceOf('bpmn:Collaboration')) {
|
||||
!is(newParent, 'bpmn:Process') &&
|
||||
!is(newParent, 'bpmn:SubProcess') &&
|
||||
!is(newParent, 'bpmn:Collaboration')) {
|
||||
|
||||
if (newParent.$instanceOf('bpmn:Participant')) {
|
||||
if (is(newParent, 'bpmn:Participant')) {
|
||||
newParent = newParent.processRef;
|
||||
break;
|
||||
} else {
|
||||
|
@ -256,12 +259,12 @@ BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent)
|
|||
containment = 'artifacts';
|
||||
} else
|
||||
|
||||
if (businessObject.$instanceOf('bpmn:MessageFlow')) {
|
||||
if (is(businessObject, 'bpmn:MessageFlow')) {
|
||||
containment = 'messageFlows';
|
||||
|
||||
} else
|
||||
|
||||
if (businessObject.$instanceOf('bpmn:Participant')) {
|
||||
if (is(businessObject, 'bpmn:Participant')) {
|
||||
containment = 'participants';
|
||||
|
||||
// make sure the participants process is properly attached / detached
|
||||
|
@ -316,17 +319,17 @@ BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
|
|||
|
||||
BpmnUpdater.prototype.updateConnection = function(connection) {
|
||||
|
||||
var businessObject = connection.businessObject,
|
||||
newSource = connection.source && connection.source.businessObject,
|
||||
newTarget = connection.target && connection.target.businessObject;
|
||||
var businessObject = getBusinessObject(connection),
|
||||
newSource = getBusinessObject(connection.source),
|
||||
newTarget = getBusinessObject(connection.target);
|
||||
|
||||
var inverseSet = businessObject.$instanceOf('bpmn:SequenceFlow');
|
||||
var inverseSet = is(businessObject, 'bpmn:SequenceFlow');
|
||||
|
||||
if (businessObject.sourceRef !== newSource) {
|
||||
if (inverseSet) {
|
||||
Collections.remove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
|
||||
|
||||
if (newSource) {
|
||||
if (newSource && newSource.get('outgoing')) {
|
||||
newSource.get('outgoing').push(businessObject);
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +340,7 @@ BpmnUpdater.prototype.updateConnection = function(connection) {
|
|||
if (inverseSet) {
|
||||
Collections.remove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
|
||||
|
||||
if (newTarget) {
|
||||
if (newTarget && newTarget.get('incoming')) {
|
||||
newTarget.get('incoming').push(businessObject);
|
||||
}
|
||||
}
|
||||
|
@ -357,4 +360,4 @@ BpmnUpdater.prototype._getLabel = function(di) {
|
|||
}
|
||||
|
||||
return di.label;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -50,13 +50,16 @@ describe('features/modeling - replace connection', function() {
|
|||
|
||||
it('sequence flow to another task', inject(function(elementRegistry, modeling){
|
||||
|
||||
// given
|
||||
var task4Shape = element('Task_4');
|
||||
var connection = element('SequenceFlow_1');
|
||||
|
||||
var newWaypoints = [connection.waypoints[0], {x: task4Shape.x+30, y: task4Shape.y}];
|
||||
var newWaypoints = [connection.waypoints[0], { x: task4Shape.x+30, y: task4Shape.y }];
|
||||
|
||||
// when
|
||||
modeling.reconnectEnd(connection, task4Shape, newWaypoints);
|
||||
|
||||
// then
|
||||
expectConnected(element('Task_2'), task4Shape, 'bpmn:MessageFlow');
|
||||
|
||||
}));
|
||||
|
@ -64,17 +67,58 @@ describe('features/modeling - replace connection', function() {
|
|||
|
||||
it('message flow to another task', inject(function(elementRegistry, modeling){
|
||||
|
||||
// given
|
||||
var task4Shape = element('Task_4');
|
||||
var connection = element('MessageFlow_1');
|
||||
|
||||
var newWaypoints = [connection.waypoints[0], {x: task4Shape.x, y: task4Shape.y+20}];
|
||||
var newWaypoints = [connection.waypoints[0], { x: task4Shape.x, y: task4Shape.y+20 }];
|
||||
|
||||
// when
|
||||
modeling.reconnectEnd(connection, task4Shape, newWaypoints);
|
||||
|
||||
// then
|
||||
expectConnected(element('Task_3'), task4Shape, 'bpmn:SequenceFlow');
|
||||
|
||||
}));
|
||||
|
||||
|
||||
it('sequence flow to a participant', inject(function(elementRegistry, modeling){
|
||||
|
||||
// given
|
||||
var participant2 = element('Participant_2');
|
||||
var connection = element('SequenceFlow_1');
|
||||
|
||||
var newWaypoints = [connection.waypoints[0], { x: participant2.x, y: participant2.y }];
|
||||
|
||||
// when
|
||||
modeling.reconnectEnd(connection, participant2, newWaypoints);
|
||||
|
||||
// then
|
||||
expectConnected(element('Task_2'), participant2, 'bpmn:MessageFlow');
|
||||
|
||||
}));
|
||||
|
||||
|
||||
it('sequence flow from a participant', inject(function(elementRegistry, modeling){
|
||||
|
||||
// given
|
||||
var participant2 = element('Participant_2'),
|
||||
subProcess1 = element('SubProcess_1'),
|
||||
connection = element('SequenceFlow_1');
|
||||
|
||||
var newWaypoints = [
|
||||
{ x: participant2.x+200 , y: participant2.y },
|
||||
{ x: subProcess1.x, y: subProcess1.y+50 }
|
||||
];
|
||||
|
||||
// when
|
||||
modeling.reconnectStart(connection, participant2, newWaypoints);
|
||||
|
||||
// then
|
||||
expectConnected(participant2, subProcess1, 'bpmn:MessageFlow');
|
||||
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
describe('moving single shape', function() {
|
||||
|
|
Loading…
Reference in New Issue