chore(auto-resize): change behavior on multi-selection move

Related to #354
This commit is contained in:
pedesen 2015-09-23 14:58:37 +02:00 committed by Ricardo Matias
parent 52cd71287d
commit dc78909227
4 changed files with 112 additions and 11 deletions

View File

@ -35,8 +35,26 @@ function AutoResize(eventBus, canvas, modeling){
this.postExecuted([ 'elements.move' ], function(event) {
var context = event.context,
elements = flatten(values(context.closure.topLevel)),
parent = context.parent || context.newParent;
elements = [],
parent = context.parent || context.newParent,
oldParent = context.hints && context.hints.oldParent,
primaryShape = context.hints && context.hints.primaryShape;
forEach(flatten(values(context.closure.topLevel)), function(element) {
/**
* exclude the element, when:
* - the primary selection does not change parent AND
* - the primary selection parent is the new parent AND
* - its parent is different from the new parent
*/
if (oldParent && oldParent === parent &&
primaryShape && primaryShape.parent === parent &&
element.parent !== parent
) {
return;
}
elements.push(element);
});
expand(elements, parent);
});

View File

@ -448,11 +448,6 @@ function canReplace(elements, target) {
function canMove(elements, target) {
// only move if they have the same parent
if (!haveSameParent(elements)) {
return false;
}
// do not move selection containing boundary events
if (any(elements, isBoundaryEvent)) {
return false;
@ -554,7 +549,3 @@ function canInsert(shape, flow, position) {
canDrop(shape, flow.parent, position);
}
function haveSameParent(elements) {
return size(groupBy(elements, function(e) { return e.parent && e.parent.id; })) === 1;
}

View File

@ -0,0 +1,22 @@
<?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" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:subProcess id="SubProcess_1">
<bpmn:task id="Task_1" />
</bpmn:subProcess>
<bpmn:task id="Task_2" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="SubProcess_1_di" bpmnElement="SubProcess_1" isExpanded="true">
<dc:Bounds x="94" y="197" width="350" height="200" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_2_di" bpmnElement="Task_2">
<dc:Bounds x="320" y="90" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
<dc:Bounds x="319" y="224" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -418,6 +418,76 @@ describe('features/auto-resize', function() {
});
describe('after moving multiple elements', function() {
var diagramXML = require('./AutoResize.multi-selection.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
var taskShape_1,
taskShape_2,
subProcessShape_1,
rootShape;
beforeEach(inject(function(elementRegistry, canvas) {
taskShape_1 = elementRegistry.get('Task_1');
taskShape_2 = elementRegistry.get('Task_2');
subProcessShape_1 = elementRegistry.get('SubProcess_1');
rootShape = canvas.getRootElement();
}));
it('should not expand, if elements keep their parents (different original parents)',
inject(function(modeling) {
// given
var originalBounds = getBounds(subProcessShape_1);
// when
modeling.moveElements([ taskShape_1, taskShape_2 ],
{ x: -100, y: 0 }, subProcessShape_1, { primaryShape: taskShape_1 });
// then
expect(subProcessShape_1).to.have.bounds(originalBounds);
}));
it('should expand, if elements keep their parents (same original parent)', inject(function(modeling) {
// given
var originalBounds = getBounds(subProcessShape_1);
modeling.moveElements([ taskShape_2 ], { x: -110, y: 135 }, subProcessShape_1);
// when
modeling.moveElements([ taskShape_1, taskShape_2 ],
{ x: -110, y: 0 }, subProcessShape_1, { primaryShape: taskShape_1 });
// then
var expectedBounds = assign(originalBounds, { x: 0, width: 444 });
expect(subProcessShape_1).to.have.bounds(expectedBounds);
}));
it('should expand, if primary shape changes parent', inject(function(modeling){
// given
var originalBounds = getBounds(subProcessShape_1);
// when
modeling.moveElements([ taskShape_1, taskShape_2 ],
{ x: 0, y: 50 }, subProcessShape_1, { primaryShape: taskShape_2 });
// then
var expectedBounds = assign(originalBounds, { y: 80, height: 317 });
expect(subProcessShape_1).to.have.bounds(expectedBounds);
}));
});
describe('nested sub processes', function() {
var diagramXML = require('./AutoResize.nested-sub-processes.bpmn');