parent
81de98f786
commit
d1072471c4
|
@ -8,11 +8,18 @@ var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
||||||
|
|
||||||
var getApproxIntersection = require('diagram-js/lib/util/LineIntersection').getApproxIntersection;
|
var getApproxIntersection = require('diagram-js/lib/util/LineIntersection').getApproxIntersection;
|
||||||
|
|
||||||
|
|
||||||
function copy(obj) {
|
function copy(obj) {
|
||||||
return assign({}, obj);
|
return assign({}, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMid(bounds) {
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: Math.round(bounds.x + bounds.width / 2),
|
||||||
|
y: Math.round(bounds.y + bounds.height / 2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function DropOnFlow(eventBus, bpmnRules, modeling) {
|
function DropOnFlow(eventBus, bpmnRules, modeling) {
|
||||||
|
|
||||||
CommandInterceptor.call(this, eventBus);
|
CommandInterceptor.call(this, eventBus);
|
||||||
|
@ -59,35 +66,38 @@ function DropOnFlow(eventBus, bpmnRules, modeling) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eventBus.on('shape.move.move', 250, function(event) {
|
this.preExecute('elements.move', function(context) {
|
||||||
|
|
||||||
var context = event.context,
|
var parent = context.newParent,
|
||||||
target = context.target,
|
shapes = context.shapes,
|
||||||
targetFlow = context.targetFlow,
|
shape,
|
||||||
shape = context.shape,
|
shapeMid,
|
||||||
shapes = context.shapes;
|
delta = context.delta;
|
||||||
|
|
||||||
if (shapes.length === 1 && bpmnRules.canInsert(shape, target)) {
|
if (bpmnRules.canInsert(shapes, parent)) {
|
||||||
context.targetFlow = target;
|
|
||||||
context.target = target.parent;
|
shape = shapes[0];
|
||||||
} else if (targetFlow) {
|
shapeMid = getMid(shape);
|
||||||
context.targetFlow = context.flowParent = null;
|
|
||||||
|
context.targetFlow = parent;
|
||||||
|
context.newParent = parent.parent;
|
||||||
|
context.position = {
|
||||||
|
x: shapeMid.x + delta.x,
|
||||||
|
y: shapeMid.y + delta.y
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
}, true);
|
||||||
|
|
||||||
eventBus.on('shape.move.end', 250, function(event) {
|
this.postExecuted('elements.move', function(context) {
|
||||||
|
|
||||||
var context = event.context,
|
var shapes = context.shapes,
|
||||||
shape = context.shape,
|
|
||||||
targetFlow = context.targetFlow,
|
targetFlow = context.targetFlow,
|
||||||
position = {
|
position = context.position;
|
||||||
x: shape.x + (shape.width / 2),
|
|
||||||
y: shape.y + (shape.height / 2)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (targetFlow) {
|
if (targetFlow) {
|
||||||
insertShape(shape, targetFlow, position);
|
insertShape(shapes[0], targetFlow, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
this.preExecute('shape.create', function(context) {
|
this.preExecute('shape.create', function(context) {
|
||||||
|
|
|
@ -283,7 +283,7 @@ describe('modeling/behavior - drop on connection', function() {
|
||||||
// no incoming connection
|
// no incoming connection
|
||||||
expect(startEventShape.incoming.length).to.equal(0);
|
expect(startEventShape.incoming.length).to.equal(0);
|
||||||
|
|
||||||
// no outgoing edges
|
// 1 outgoing connection
|
||||||
expect(startEventShape.outgoing.length).to.equal(1);
|
expect(startEventShape.outgoing.length).to.equal(1);
|
||||||
expect(startEventShape.outgoing[0]).to.eql(sequenceFlow);
|
expect(startEventShape.outgoing[0]).to.eql(sequenceFlow);
|
||||||
|
|
||||||
|
@ -294,6 +294,45 @@ describe('modeling/behavior - drop on connection', function() {
|
||||||
]));
|
]));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should undo',
|
||||||
|
inject(function(modeling, elementRegistry, dragging, selection, move, commandStack) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var startEventShape = elementRegistry.get('StartEvent_foo');
|
||||||
|
|
||||||
|
var sequenceFlow = elementRegistry.get('SequenceFlow'),
|
||||||
|
sequenceFlowGfx = elementRegistry.getGraphics(sequenceFlow),
|
||||||
|
originalWaypoints = sequenceFlow.waypoints;
|
||||||
|
|
||||||
|
selection.select(startEventShape);
|
||||||
|
|
||||||
|
move.start(canvasEvent({ x: 0, y: 0 }), startEventShape);
|
||||||
|
|
||||||
|
dragging.hover({
|
||||||
|
element: sequenceFlow,
|
||||||
|
gfx: sequenceFlowGfx
|
||||||
|
});
|
||||||
|
|
||||||
|
dragging.move(canvasEvent({ x: -215, y: 0 }));
|
||||||
|
|
||||||
|
dragging.end();
|
||||||
|
|
||||||
|
// when
|
||||||
|
commandStack.undo();
|
||||||
|
|
||||||
|
// then
|
||||||
|
|
||||||
|
// no incoming connection
|
||||||
|
expect(startEventShape.incoming.length).to.equal(0);
|
||||||
|
|
||||||
|
// no outgoing edges
|
||||||
|
expect(startEventShape.outgoing.length).to.equal(0);
|
||||||
|
|
||||||
|
// split target at insertion point
|
||||||
|
expect(sequenceFlow).to.have.waypoints(flatten([ originalWaypoints ]));
|
||||||
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue