diff --git a/lib/features/modeling/BpmnUpdater.js b/lib/features/modeling/BpmnUpdater.js index be23cbbb..a2080324 100644 --- a/lib/features/modeling/BpmnUpdater.js +++ b/lib/features/modeling/BpmnUpdater.js @@ -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; diff --git a/lib/features/modeling/Modeling.js b/lib/features/modeling/Modeling.js index 294965d4..e6b8161e 100644 --- a/lib/features/modeling/Modeling.js +++ b/lib/features/modeling/Modeling.js @@ -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); }; diff --git a/test/spec/features/modeling/MoveConnectionSpec.js b/test/spec/features/modeling/MoveConnectionSpec.js new file mode 100644 index 00000000..a4d5974f --- /dev/null +++ b/test/spec/features/modeling/MoveConnectionSpec.js @@ -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); + })); + + }); + +}); \ No newline at end of file