feat(modeling): integrate connection.move

Related to #125
This commit is contained in:
Nico Rehwaldt 2014-08-28 16:17:55 +02:00
parent 5f986dcb3a
commit a301acc4c4
3 changed files with 121 additions and 11 deletions

View File

@ -74,8 +74,8 @@ function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) {
self.updateConnection(e.context.connection);
}
this.executed([ 'connection.create', 'connection.delete' ], updateConnection);
this.reverted([ 'connection.create', 'connection.delete' ], updateConnection);
this.executed([ 'connection.create', 'connection.move', 'connection.delete' ], updateConnection);
this.reverted([ 'connection.create', 'connection.move', 'connection.delete' ], updateConnection);
// update waypoints
@ -83,8 +83,8 @@ function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) {
self.updateConnectionWaypoints(e.context.connection);
}
this.executed([ 'connection.layout' ], updateConnectionWaypoints);
this.reverted([ 'connection.layout' ], updateConnectionWaypoints);
this.executed([ 'connection.layout', 'connection.move' ], updateConnectionWaypoints);
this.reverted([ 'connection.layout', 'connection.move' ], updateConnectionWaypoints);
}
module.exports = BpmnUpdater;

View File

@ -4,18 +4,18 @@ var _ = require('lodash');
var BaseModeling = require('diagram-js/lib/features/modeling/Modeling');
var AppendShapeHandler = require('./cmd/AppendShapeHandler'),
CreateShapeHandler = require('diagram-js/lib/features/modeling/cmd/CreateShapeHandler'),
var CreateShapeHandler = require('diagram-js/lib/features/modeling/cmd/CreateShapeHandler'),
DeleteShapeHandler = require('diagram-js/lib/features/modeling/cmd/DeleteShapeHandler'),
MoveShapeHandler = require('diagram-js/lib/features/modeling/cmd/MoveShapeHandler'),
CreateConnectionHandler = require('diagram-js/lib/features/modeling/cmd/CreateConnectionHandler'),
DeleteConnectionHandler = require('diagram-js/lib/features/modeling/cmd/DeleteConnectionHandler'),
AppendShapeHandler = require('./cmd/AppendShapeHandler'),
CreateLabelHandler = require('diagram-js/lib/features/modeling/cmd/CreateLabelHandler'),
LayoutConnectionHandler = require('diagram-js/lib/features/modeling/cmd/LayoutConnectionHandler'),
MoveShapeHandler = require('diagram-js/lib/features/modeling/cmd/MoveShapeHandler');
CreateConnectionHandler = require('diagram-js/lib/features/modeling/cmd/CreateConnectionHandler'),
DeleteConnectionHandler = require('diagram-js/lib/features/modeling/cmd/DeleteConnectionHandler'),
MoveConnectionHandler = require('diagram-js/lib/features/modeling/cmd/MoveConnectionHandler'),
LayoutConnectionHandler = require('diagram-js/lib/features/modeling/cmd/LayoutConnectionHandler');
/**
@ -46,6 +46,7 @@ Modeling.prototype.registerHandlers = function(commandStack) {
commandStack.registerHandler('connection.create', CreateConnectionHandler);
commandStack.registerHandler('connection.delete', DeleteConnectionHandler);
commandStack.registerHandler('connection.move', MoveConnectionHandler);
commandStack.registerHandler('connection.layout', LayoutConnectionHandler);
};

View File

@ -0,0 +1,109 @@
'use strict';
var Matchers = require('../../../Matchers'),
TestHelper = require('../../../TestHelper');
/* global bootstrapModeler, inject */
var _ = require('lodash');
var fs = require('fs');
var modelingModule = require('../../../../lib/features/modeling'),
drawModule = require('../../../../lib/draw');
describe('features/modeling - move connection', function() {
beforeEach(Matchers.addDeepEquals);
var diagramXML = fs.readFileSync('test/fixtures/bpmn/sequence-flows.bpmn', 'utf-8');
var testModules = [ drawModule, modelingModule ];
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
describe('connection handling', function() {
it('should execute', inject(function(elementRegistry, modeling) {
// given
var sequenceFlowConnection = elementRegistry.getById('SequenceFlow_1'),
sequenceFlow = sequenceFlowConnection.businessObject;
// when
modeling.moveConnection(sequenceFlowConnection, { x: 20, y: 10 });
// then
// expect cropped connection
expect(sequenceFlowConnection.waypoints).toDeepEqual([
{ x: 598, y: 351 },
{ x: 954, y: 351 },
{ x: 954, y: 446 },
{ x: 852, y: 446 }
]);
// expect cropped waypoints in di
expect(sequenceFlow.di.waypoint).toDeepEqual([
{ $type: 'dc:Point', x: 598, y: 351 },
{ $type: 'dc:Point', x: 954, y: 351 },
{ $type: 'dc:Point', x: 954, y: 446 },
{ $type: 'dc:Point', x: 852, y: 446 }
]);
}));
});
describe('undo support', function() {
it('should undo', inject(function(elementRegistry, commandStack, modeling) {
// given
var sequenceFlowConnection = elementRegistry.getById('SequenceFlow_1'),
sequenceFlow = sequenceFlowConnection.businessObject;
var oldWaypoints = sequenceFlowConnection.waypoints,
oldDiWaypoints = sequenceFlow.di.waypoint;
modeling.moveConnection(sequenceFlowConnection, { x: 20, y: 10 });
// when
commandStack.undo();
// then
expect(sequenceFlowConnection.waypoints).toDeepEqual(oldWaypoints);
expect(sequenceFlow.di.waypoint).toDeepEqual(oldDiWaypoints);
}));
});
describe('redo support', function() {
it('should redo', inject(function(elementRegistry, commandStack, modeling) {
// given
var sequenceFlowConnection = elementRegistry.getById('SequenceFlow_1'),
sequenceFlow = sequenceFlowConnection.businessObject;
modeling.moveConnection(sequenceFlowConnection, { x: 20, y: 10 });
var newWaypoints = sequenceFlowConnection.waypoints,
newDiWaypoints = sequenceFlow.di.waypoint;
// when
commandStack.undo();
commandStack.redo();
// then
expect(sequenceFlowConnection.waypoints).toDeepEqual(newWaypoints);
expect(sequenceFlow.di.waypoint).toDeepEqual(newDiWaypoints);
}));
});
});