From 6f8999b8ae5db17fa8b2cc72d12b06d6cc2cc000 Mon Sep 17 00:00:00 2001 From: Ricardo Matias Date: Mon, 4 May 2015 14:59:26 +0200 Subject: [PATCH] fix(modeling/BpmnUpdater): restore children di when changing diagram type closes #253 --- lib/features/modeling/BpmnUpdater.js | 23 ++++++++++++++++ test/spec/ModelerSpec.js | 1 + test/spec/ViewerSpec.js | 2 +- .../modeling/behavior/CreateBehaviorSpec.js | 26 ++++++++++++++++++- 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/lib/features/modeling/BpmnUpdater.js b/lib/features/modeling/BpmnUpdater.js index 29893111..4bdd7b22 100644 --- a/lib/features/modeling/BpmnUpdater.js +++ b/lib/features/modeling/BpmnUpdater.js @@ -1,6 +1,7 @@ 'use strict'; var assign = require('lodash/object/assign'), + forEach = require('lodash/collection/forEach'), inherits = require('inherits'); var Collections = require('diagram-js/lib/util/Collections'), @@ -71,6 +72,28 @@ function BpmnUpdater(eventBus, bpmnFactory, connectionDocking) { 'connection.move', '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 function updateBounds(e) { self.updateBounds(e.context.shape); diff --git a/test/spec/ModelerSpec.js b/test/spec/ModelerSpec.js index db139861..20de89e8 100644 --- a/test/spec/ModelerSpec.js +++ b/test/spec/ModelerSpec.js @@ -1,5 +1,6 @@ 'use strict'; +var TestHelper = require('../TestHelper'); var Modeler = require('../../lib/Modeler'); diff --git a/test/spec/ViewerSpec.js b/test/spec/ViewerSpec.js index ebe6a94a..3be58b59 100644 --- a/test/spec/ViewerSpec.js +++ b/test/spec/ViewerSpec.js @@ -1,6 +1,6 @@ 'use strict'; -require('../TestHelper'); +var TestHelper = require('../TestHelper'); var Viewer = require('../../lib/Viewer'); diff --git a/test/spec/features/modeling/behavior/CreateBehaviorSpec.js b/test/spec/features/modeling/behavior/CreateBehaviorSpec.js index e36c4607..aa4684e6 100644 --- a/test/spec/features/modeling/behavior/CreateBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/CreateBehaviorSpec.js @@ -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 var processShape = canvas.getRootElement(), @@ -138,10 +138,34 @@ describe('features/modeling - create participant', function() { // when commandStack.undo(); + var startEventElement = elementRegistry.get('StartEvent_1'), + startEventDi = startEventElement.businessObject.di, + rootElement = canvas.getRootElement(), + rootShapeDi = rootElement.businessObject.di; // then expect(participantShape.children.length).toBe(0); 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); })); });