feat(modeling): update bpmn model on remove
On removeShape/removeConnection the BPMN model is updated accordingly. related to #106
This commit is contained in:
parent
88fbe05ae4
commit
470e0f88ba
|
@ -48,8 +48,16 @@ function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) {
|
||||||
self.updateShapeParent(e.context.shape || e.context.connection);
|
self.updateShapeParent(e.context.shape || e.context.connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.executed([ 'shape.move', 'shape.create', 'connection.create' ], updateShapeParent);
|
this.executed([ 'shape.move',
|
||||||
this.reverted([ 'shape.move', 'shape.create', 'connection.create' ], updateShapeParent);
|
'shape.create',
|
||||||
|
'shape.delete',
|
||||||
|
'connection.create',
|
||||||
|
'connection.delete' ], updateShapeParent);
|
||||||
|
this.reverted([ 'shape.move',
|
||||||
|
'shape.create',
|
||||||
|
'shape.delete',
|
||||||
|
'connection.create',
|
||||||
|
'connection.delete' ], updateShapeParent);
|
||||||
|
|
||||||
|
|
||||||
// update bounds
|
// update bounds
|
||||||
|
@ -66,8 +74,8 @@ function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) {
|
||||||
self.updateConnection(e.context.connection);
|
self.updateConnection(e.context.connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.executed([ 'connection.create' ], updateConnection);
|
this.executed([ 'connection.create', 'connection.delete' ], updateConnection);
|
||||||
this.reverted([ 'connection.create' ], updateConnection);
|
this.reverted([ 'connection.create', 'connection.delete' ], updateConnection);
|
||||||
|
|
||||||
|
|
||||||
// update waypoints
|
// update waypoints
|
||||||
|
|
|
@ -6,7 +6,11 @@ var BaseModeling = require('diagram-js/lib/features/modeling/Modeling');
|
||||||
|
|
||||||
var AppendShapeHandler = require('./cmd/AppendShapeHandler'),
|
var AppendShapeHandler = require('./cmd/AppendShapeHandler'),
|
||||||
CreateShapeHandler = require('diagram-js/lib/features/modeling/cmd/CreateShapeHandler'),
|
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'),
|
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'),
|
CreateLabelHandler = require('diagram-js/lib/features/modeling/cmd/CreateLabelHandler'),
|
||||||
|
|
||||||
LayoutConnectionHandler = require('diagram-js/lib/features/modeling/cmd/LayoutConnectionHandler'),
|
LayoutConnectionHandler = require('diagram-js/lib/features/modeling/cmd/LayoutConnectionHandler'),
|
||||||
|
@ -33,6 +37,7 @@ module.exports = Modeling;
|
||||||
|
|
||||||
Modeling.prototype.registerHandlers = function(commandStack) {
|
Modeling.prototype.registerHandlers = function(commandStack) {
|
||||||
commandStack.registerHandler('shape.create', CreateShapeHandler);
|
commandStack.registerHandler('shape.create', CreateShapeHandler);
|
||||||
|
commandStack.registerHandler('shape.delete', DeleteShapeHandler);
|
||||||
commandStack.registerHandler('shape.move', MoveShapeHandler);
|
commandStack.registerHandler('shape.move', MoveShapeHandler);
|
||||||
|
|
||||||
commandStack.registerHandler('shape.append', AppendShapeHandler);
|
commandStack.registerHandler('shape.append', AppendShapeHandler);
|
||||||
|
@ -40,6 +45,7 @@ Modeling.prototype.registerHandlers = function(commandStack) {
|
||||||
commandStack.registerHandler('label.create', CreateLabelHandler);
|
commandStack.registerHandler('label.create', CreateLabelHandler);
|
||||||
|
|
||||||
commandStack.registerHandler('connection.create', CreateConnectionHandler);
|
commandStack.registerHandler('connection.create', CreateConnectionHandler);
|
||||||
|
commandStack.registerHandler('connection.delete', DeleteConnectionHandler);
|
||||||
commandStack.registerHandler('connection.layout', LayoutConnectionHandler);
|
commandStack.registerHandler('connection.layout', LayoutConnectionHandler);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -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();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue