From 470e0f88baeb420235ddd9c7c8e04f26da13dedc Mon Sep 17 00:00:00 2001 From: jdotzki Date: Fri, 22 Aug 2014 15:20:48 +0200 Subject: [PATCH] feat(modeling): update bpmn model on remove On removeShape/removeConnection the BPMN model is updated accordingly. related to #106 --- lib/features/modeling/BpmnUpdater.js | 16 +++- lib/features/modeling/Modeling.js | 6 ++ .../features/modeling/DeleteConnectionSpec.js | 83 +++++++++++++++++++ .../spec/features/modeling/DeleteShapeSpec.js | 83 +++++++++++++++++++ 4 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 test/spec/features/modeling/DeleteConnectionSpec.js create mode 100644 test/spec/features/modeling/DeleteShapeSpec.js diff --git a/lib/features/modeling/BpmnUpdater.js b/lib/features/modeling/BpmnUpdater.js index 9fd9adb3..be23cbbb 100644 --- a/lib/features/modeling/BpmnUpdater.js +++ b/lib/features/modeling/BpmnUpdater.js @@ -48,8 +48,16 @@ function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) { self.updateShapeParent(e.context.shape || e.context.connection); } - this.executed([ 'shape.move', 'shape.create', 'connection.create' ], updateShapeParent); - this.reverted([ 'shape.move', 'shape.create', 'connection.create' ], updateShapeParent); + this.executed([ 'shape.move', + 'shape.create', + 'shape.delete', + 'connection.create', + 'connection.delete' ], updateShapeParent); + this.reverted([ 'shape.move', + 'shape.create', + 'shape.delete', + 'connection.create', + 'connection.delete' ], updateShapeParent); // update bounds @@ -66,8 +74,8 @@ function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) { self.updateConnection(e.context.connection); } - this.executed([ 'connection.create' ], updateConnection); - this.reverted([ 'connection.create' ], updateConnection); + this.executed([ 'connection.create', 'connection.delete' ], updateConnection); + this.reverted([ 'connection.create', 'connection.delete' ], updateConnection); // update waypoints diff --git a/lib/features/modeling/Modeling.js b/lib/features/modeling/Modeling.js index 126c6b3b..294965d4 100644 --- a/lib/features/modeling/Modeling.js +++ b/lib/features/modeling/Modeling.js @@ -6,7 +6,11 @@ var BaseModeling = require('diagram-js/lib/features/modeling/Modeling'); var AppendShapeHandler = require('./cmd/AppendShapeHandler'), CreateShapeHandler = require('diagram-js/lib/features/modeling/cmd/CreateShapeHandler'), + DeleteShapeHandler = require('diagram-js/lib/features/modeling/cmd/DeleteShapeHandler'), + CreateConnectionHandler = require('diagram-js/lib/features/modeling/cmd/CreateConnectionHandler'), + DeleteConnectionHandler = require('diagram-js/lib/features/modeling/cmd/DeleteConnectionHandler'), + CreateLabelHandler = require('diagram-js/lib/features/modeling/cmd/CreateLabelHandler'), LayoutConnectionHandler = require('diagram-js/lib/features/modeling/cmd/LayoutConnectionHandler'), @@ -33,6 +37,7 @@ module.exports = Modeling; Modeling.prototype.registerHandlers = function(commandStack) { commandStack.registerHandler('shape.create', CreateShapeHandler); + commandStack.registerHandler('shape.delete', DeleteShapeHandler); commandStack.registerHandler('shape.move', MoveShapeHandler); commandStack.registerHandler('shape.append', AppendShapeHandler); @@ -40,6 +45,7 @@ Modeling.prototype.registerHandlers = function(commandStack) { commandStack.registerHandler('label.create', CreateLabelHandler); commandStack.registerHandler('connection.create', CreateConnectionHandler); + commandStack.registerHandler('connection.delete', DeleteConnectionHandler); commandStack.registerHandler('connection.layout', LayoutConnectionHandler); }; diff --git a/test/spec/features/modeling/DeleteConnectionSpec.js b/test/spec/features/modeling/DeleteConnectionSpec.js new file mode 100644 index 00000000..e6c73a48 --- /dev/null +++ b/test/spec/features/modeling/DeleteConnectionSpec.js @@ -0,0 +1,83 @@ +'use strict'; + +/* global bootstrapModeler, inject */ + +var Matchers = require('../../../Matchers'), + TestHelper = require('../../../TestHelper'); + +var _ = require('lodash'); + +var fs = require('fs'); + +var modelingModule = require('../../../../lib/features/modeling'), + drawModule = require('../../../../lib/draw'); + + +describe('features/modeling - #removeConnection', 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('shape handling', function() { + + it('should execute', inject(function(elementRegistry, modeling) { + + // given + var sequenceFlowShape = elementRegistry.getById('SequenceFlow_2'), + sequenceFlow = sequenceFlowShape.businessObject; + + // when + modeling.removeConnection(sequenceFlowShape); + + // then + expect(sequenceFlow.$parent).toBeNull(); + })); + }); + + + describe('undo support', function() { + + it('should undo', inject(function(elementRegistry, modeling, commandStack) { + + // given + var sequenceFlowShape = elementRegistry.getById('SequenceFlow_2'), + sequenceFlow = sequenceFlowShape.businessObject, + parent = sequenceFlow.$parent; + + // when + modeling.removeConnection(sequenceFlowShape); + commandStack.undo(); + + // then + expect(sequenceFlow.$parent).toBe(parent); + })); + }); + + + describe('redo support', function() { + + it('redo', inject(function(elementRegistry, modeling, commandStack) { + + // given + var sequenceFlowShape = elementRegistry.getById('SequenceFlow_2'), + sequenceFlow = sequenceFlowShape.businessObject, + parent = sequenceFlow.$parent; + + // when + modeling.removeConnection(sequenceFlowShape); + commandStack.undo(); + commandStack.redo(); + + // then + expect(sequenceFlow.$parent).toBeNull(); + })); + }); + +}); diff --git a/test/spec/features/modeling/DeleteShapeSpec.js b/test/spec/features/modeling/DeleteShapeSpec.js new file mode 100644 index 00000000..b353d36d --- /dev/null +++ b/test/spec/features/modeling/DeleteShapeSpec.js @@ -0,0 +1,83 @@ +'use strict'; + +/* global bootstrapModeler, inject */ + +var Matchers = require('../../../Matchers'), + TestHelper = require('../../../TestHelper'); + +var _ = require('lodash'); + +var fs = require('fs'); + +var modelingModule = require('../../../../lib/features/modeling'), + drawModule = require('../../../../lib/draw'); + + +describe('features/modeling - #removeShape', 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('shape handling', function() { + + it('should execute', inject(function(elementRegistry, modeling) { + + // given + var taskShape = elementRegistry.getById('Task_1'), + task = taskShape.businessObject; + + // when + modeling.removeShape(taskShape); + + // then + expect(task.$parent).toBeNull(); + })); + }); + + + describe('undo support', function() { + + it('should undo', inject(function(elementRegistry, modeling, commandStack) { + + // given + var taskShape = elementRegistry.getById('Task_1'), + task = taskShape.businessObject, + parent = task.$parent; + + // when + modeling.removeShape(taskShape); + commandStack.undo(); + + // then + expect(task.$parent).toBe(parent); + })); + }); + + + describe('redo support', function() { + + it('redo', inject(function(elementRegistry, modeling, commandStack) { + + // given + var taskShape = elementRegistry.getById('Task_1'), + task = taskShape.businessObject, + parent = task.$parent; + + // when + modeling.removeShape(taskShape); + commandStack.undo(); + commandStack.redo(); + + // then + expect(task.$parent).toBeNull(); + })); + }); + +});