fix(modeling): update association parent on source or target move
Closes #683
This commit is contained in:
parent
7ad31ae3dc
commit
c8412c27f2
|
@ -0,0 +1,35 @@
|
|||
import inherits from 'inherits';
|
||||
|
||||
import { is } from '../../../util/ModelUtil';
|
||||
|
||||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
||||
|
||||
import {
|
||||
filter,
|
||||
forEach
|
||||
} from 'min-dash';
|
||||
|
||||
|
||||
export default function AssociationBehavior(injector, modeling) {
|
||||
injector.invoke(CommandInterceptor, this);
|
||||
|
||||
this.postExecute('shape.move', function(context) {
|
||||
var newParent = context.newParent,
|
||||
shape = context.shape;
|
||||
|
||||
var associations = filter(shape.incoming.concat(shape.outgoing), function(connection) {
|
||||
return is(connection, 'bpmn:Association');
|
||||
});
|
||||
|
||||
forEach(associations, function(association) {
|
||||
modeling.moveConnection(association, { x: 0, y: 0 }, newParent);
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
inherits(AssociationBehavior, CommandInterceptor);
|
||||
|
||||
AssociationBehavior.$inject = [
|
||||
'injector',
|
||||
'modeling'
|
||||
];
|
|
@ -1,5 +1,6 @@
|
|||
import AdaptiveLabelPositioningBehavior from './AdaptiveLabelPositioningBehavior';
|
||||
import AppendBehavior from './AppendBehavior';
|
||||
import AssociationBehavior from './AssociationBehavior';
|
||||
import AttachEventBehavior from './AttachEventBehavior';
|
||||
import BoundaryEventBehavior from './BoundaryEventBehavior';
|
||||
import CreateBehavior from './CreateBehavior';
|
||||
|
@ -33,6 +34,7 @@ export default {
|
|||
__init__: [
|
||||
'adaptiveLabelPositioningBehavior',
|
||||
'appendBehavior',
|
||||
'associationBehavior',
|
||||
'attachEventBehavior',
|
||||
'boundaryEventBehavior',
|
||||
'createBehavior',
|
||||
|
@ -64,6 +66,7 @@ export default {
|
|||
],
|
||||
adaptiveLabelPositioningBehavior: [ 'type', AdaptiveLabelPositioningBehavior ],
|
||||
appendBehavior: [ 'type', AppendBehavior ],
|
||||
associationBehavior: [ 'type', AssociationBehavior ],
|
||||
attachEventBehavior: [ 'type', AttachEventBehavior ],
|
||||
boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
|
||||
createBehavior: [ 'type', CreateBehavior ],
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?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" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0jqn0aw" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.3.5">
|
||||
<bpmn:process id="Process_1" isExecutable="true">
|
||||
<bpmn:subProcess id="SubProcess_1">
|
||||
<bpmn:startEvent id="StartEvent_1" />
|
||||
<bpmn:textAnnotation id="TextAnnotation_1" />
|
||||
<bpmn:association id="Association_1" sourceRef="StartEvent_1" targetRef="TextAnnotation_1" />
|
||||
</bpmn:subProcess>
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
|
||||
<bpmndi:BPMNShape id="SubProcess_1mgowm5_di" bpmnElement="SubProcess_1" isExpanded="true">
|
||||
<dc:Bounds x="-15" y="130" width="230" height="120" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="StartEvent_1k5d2l6_di" bpmnElement="StartEvent_1">
|
||||
<dc:Bounds x="7" y="172" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="TextAnnotation_0o5s7yu_di" bpmnElement="TextAnnotation_1">
|
||||
<dc:Bounds x="85" y="175" width="100" height="30" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge id="Association_0chc4mv_di" bpmnElement="Association_1">
|
||||
<di:waypoint x="43" y="190" />
|
||||
<di:waypoint x="85" y="190" />
|
||||
</bpmndi:BPMNEdge>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
|
@ -0,0 +1,45 @@
|
|||
import {
|
||||
bootstrapModeler,
|
||||
inject
|
||||
} from 'test/TestHelper';
|
||||
|
||||
import modelingModule from 'lib/features/modeling';
|
||||
|
||||
|
||||
describe('modeling/behavior - AssociationBehavior', function() {
|
||||
|
||||
var diagramXML = require('./AssociationBehavior.bpmn');
|
||||
|
||||
beforeEach(bootstrapModeler(diagramXML, { modules: modelingModule }));
|
||||
|
||||
|
||||
it('should move to new parent on source move', inject(function(modeling, elementRegistry) {
|
||||
|
||||
// given
|
||||
var association = elementRegistry.get('Association_1'),
|
||||
process = elementRegistry.get('Process_1'),
|
||||
startEvent = elementRegistry.get('StartEvent_1');
|
||||
|
||||
// when
|
||||
modeling.moveElements([ startEvent ], { x: 100, y: 100 }, process);
|
||||
|
||||
// then
|
||||
expect(association.parent).to.equal(process);
|
||||
}));
|
||||
|
||||
|
||||
it('should move to new parent on target move', inject(function(modeling, elementRegistry) {
|
||||
|
||||
// given
|
||||
var association = elementRegistry.get('Association_1'),
|
||||
process = elementRegistry.get('Process_1'),
|
||||
textAnnotation = elementRegistry.get('TextAnnotation_1');
|
||||
|
||||
// when
|
||||
modeling.moveElements([ textAnnotation ], { x: 100, y: 100 }, process);
|
||||
|
||||
// then
|
||||
expect(association.parent).to.equal(process);
|
||||
}));
|
||||
|
||||
});
|
Loading…
Reference in New Issue