fix(modeling): properly update sourceRef/targetRef for associations
Related to #90
This commit is contained in:
parent
a8d51a849d
commit
fb86037cdd
|
@ -173,25 +173,26 @@ BpmnUpdater.prototype.updateConnection = function(connection) {
|
||||||
newSource = connection.source && connection.source.businessObject,
|
newSource = connection.source && connection.source.businessObject,
|
||||||
newTarget = connection.target && connection.target.businessObject;
|
newTarget = connection.target && connection.target.businessObject;
|
||||||
|
|
||||||
// don't set incoming / outgoing for associations
|
var inverseSet = businessObject.$instanceOf('bpmn:SequenceFlow');
|
||||||
if(businessObject.$instanceOf('bpmn:Association')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (businessObject.sourceRef !== newSource) {
|
if (businessObject.sourceRef !== newSource) {
|
||||||
Collections.remove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
|
if (inverseSet) {
|
||||||
|
Collections.remove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
|
||||||
|
|
||||||
if (newSource) {
|
if (newSource) {
|
||||||
newSource.get('outgoing').push(businessObject);
|
newSource.get('outgoing').push(businessObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
businessObject.sourceRef = newSource;
|
businessObject.sourceRef = newSource;
|
||||||
}
|
}
|
||||||
if (businessObject.targetRef !== newTarget) {
|
if (businessObject.targetRef !== newTarget) {
|
||||||
Collections.remove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
|
if (inverseSet) {
|
||||||
|
Collections.remove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
|
||||||
|
|
||||||
if (newTarget) {
|
if (newTarget) {
|
||||||
newTarget.get('incoming').push(businessObject);
|
newTarget.get('incoming').push(businessObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
businessObject.targetRef = newTarget;
|
businessObject.targetRef = newTarget;
|
||||||
|
|
|
@ -348,6 +348,58 @@ describe('features/modeling - append shape', function() {
|
||||||
|
|
||||||
describe('bpmn element support', function() {
|
describe('bpmn element support', function() {
|
||||||
|
|
||||||
|
describe('TextAnnotation', function() {
|
||||||
|
|
||||||
|
it('should wire connection source + target', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
||||||
|
|
||||||
|
// when
|
||||||
|
var targetShape = modeling.appendTextAnnotation(startEventShape, 'bpmn:TextAnnotation'),
|
||||||
|
target = targetShape.businessObject;
|
||||||
|
|
||||||
|
var connectingConnection = _.find(targetShape.incoming, function(c) {
|
||||||
|
return c.target === targetShape;
|
||||||
|
});
|
||||||
|
|
||||||
|
var connecting = connectingConnection.businessObject;
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(targetShape).toBeDefined();
|
||||||
|
expect(target.$instanceOf('bpmn:TextAnnotation')).toBe(true);
|
||||||
|
|
||||||
|
expect(connecting.$instanceOf('bpmn:Association')).toBe(true);
|
||||||
|
expect(connecting.sourceRef).toBe(startEventShape.businessObject);
|
||||||
|
expect(connecting.targetRef).toBe(target);
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should undo wire connection source + target', inject(function(elementRegistry, modeling, commandStack) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
||||||
|
|
||||||
|
var targetShape = modeling.appendTextAnnotation(startEventShape, 'bpmn:TextAnnotation'),
|
||||||
|
target = targetShape.businessObject;
|
||||||
|
|
||||||
|
var connectingConnection = _.find(targetShape.incoming, function(c) {
|
||||||
|
return c.target === targetShape;
|
||||||
|
});
|
||||||
|
|
||||||
|
var connecting = connectingConnection.businessObject;
|
||||||
|
|
||||||
|
// when
|
||||||
|
commandStack.undo();
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(connecting.sourceRef).toBe(null);
|
||||||
|
expect(connecting.targetRef).toBe(null);
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('ExclusiveGateway', function() {
|
describe('ExclusiveGateway', function() {
|
||||||
|
|
||||||
it('should append', inject(function(elementRegistry, modeling) {
|
it('should append', inject(function(elementRegistry, modeling) {
|
||||||
|
|
Loading…
Reference in New Issue