mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-02-19 20:28:06 +00:00
fix(modeling/BpmnUpdater): restore children di when changing diagram type
closes #253
This commit is contained in:
parent
877cfcca78
commit
6f8999b8ae
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assign = require('lodash/object/assign'),
|
var assign = require('lodash/object/assign'),
|
||||||
|
forEach = require('lodash/collection/forEach'),
|
||||||
inherits = require('inherits');
|
inherits = require('inherits');
|
||||||
|
|
||||||
var Collections = require('diagram-js/lib/util/Collections'),
|
var Collections = require('diagram-js/lib/util/Collections'),
|
||||||
@ -71,6 +72,28 @@ function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) {
|
|||||||
'connection.move',
|
'connection.move',
|
||||||
'connection.delete' ], updateParent);
|
'connection.delete' ], updateParent);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ## Updating Parent
|
||||||
|
*
|
||||||
|
* When morphing a Process into a Collaboration or vice-versa,
|
||||||
|
* make sure that both the *semantic* and *di* parent of each element
|
||||||
|
* is updated.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function updateRoot(event) {
|
||||||
|
var context = event.context,
|
||||||
|
oldRoot = context.oldRoot,
|
||||||
|
children = oldRoot.children;
|
||||||
|
|
||||||
|
forEach(children, function(child) {
|
||||||
|
self.updateParent(child);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.executed([ 'canvas.updateRoot' ], updateRoot);
|
||||||
|
this.reverted([ 'canvas.updateRoot' ], updateRoot);
|
||||||
|
|
||||||
|
|
||||||
// update bounds
|
// update bounds
|
||||||
function updateBounds(e) {
|
function updateBounds(e) {
|
||||||
self.updateBounds(e.context.shape);
|
self.updateBounds(e.context.shape);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var TestHelper = require('../TestHelper');
|
||||||
|
|
||||||
var Modeler = require('../../lib/Modeler');
|
var Modeler = require('../../lib/Modeler');
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
require('../TestHelper');
|
var TestHelper = require('../TestHelper');
|
||||||
|
|
||||||
|
|
||||||
var Viewer = require('../../lib/Viewer');
|
var Viewer = require('../../lib/Viewer');
|
||||||
|
@ -127,7 +127,7 @@ describe('features/modeling - create participant', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('undo', inject(function(modeling, elementFactory, canvas, commandStack) {
|
it('undo', inject(function(modeling, elementFactory, elementRegistry, canvas, commandStack) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var processShape = canvas.getRootElement(),
|
var processShape = canvas.getRootElement(),
|
||||||
@ -138,10 +138,34 @@ describe('features/modeling - create participant', function() {
|
|||||||
// when
|
// when
|
||||||
commandStack.undo();
|
commandStack.undo();
|
||||||
|
|
||||||
|
var startEventElement = elementRegistry.get('StartEvent_1'),
|
||||||
|
startEventDi = startEventElement.businessObject.di,
|
||||||
|
rootElement = canvas.getRootElement(),
|
||||||
|
rootShapeDi = rootElement.businessObject.di;
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(participantShape.children.length).toBe(0);
|
expect(participantShape.children.length).toBe(0);
|
||||||
expect(processShape.children.length).toBe(9);
|
expect(processShape.children.length).toBe(9);
|
||||||
|
|
||||||
|
// children di is wired
|
||||||
|
expect(startEventDi.$parent).toEqual(rootShapeDi);
|
||||||
|
expect(rootShapeDi.planeElement).toContain(startEventDi);
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should detach DI on update canvas root', inject(function(canvas, elementFactory, commandStack, modeling, elementRegistry) {
|
||||||
|
|
||||||
|
// when
|
||||||
|
modeling.makeCollaboration();
|
||||||
|
|
||||||
|
var startEventElement = elementRegistry.get('StartEvent_1'),
|
||||||
|
startEventDi = startEventElement.businessObject.di,
|
||||||
|
rootElement = canvas.getRootElement(),
|
||||||
|
rootShapeDi = rootElement.businessObject.di;
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(startEventDi.$parent).toBeFalsy();
|
||||||
|
expect(rootShapeDi.planeElement).not.toContain(startEventDi);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user