From 2e73f5ab8549f289bc5abe09ad7c22be13a5bbba Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 13 Apr 2015 10:55:17 +0200 Subject: [PATCH] fix(modeling): update id property in diagram-js, too This fixes a bug where updating the id property of an element was not propagated to the diagram. Thus, retrieving the element based on the new id from diagram-js did not work. Closes #238 --- .../modeling/cmd/UpdatePropertiesHandler.js | 15 ++++++++-- .../features/modeling/UpdatePropertiesSpec.js | 29 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/features/modeling/cmd/UpdatePropertiesHandler.js b/lib/features/modeling/cmd/UpdatePropertiesHandler.js index cf1b64ea..580b35db 100644 --- a/lib/features/modeling/cmd/UpdatePropertiesHandler.js +++ b/lib/features/modeling/cmd/UpdatePropertiesHandler.js @@ -5,7 +5,8 @@ var assign = require('lodash/object/assign'), keys = require('lodash/object/keys'); var DEFAULT_FLOW = 'default', - NAME = 'name'; + NAME = 'name', + ID = 'id'; /** @@ -53,6 +54,10 @@ UpdatePropertiesHandler.prototype.execute = function(context) { properties = context.properties, oldProperties = context.oldProperties || pick(businessObject, keys(properties)); + if (ID in properties) { + elementRegistry.updateId(element, properties[ID]); + } + // correctly indicate visual changes on default flow updates if (DEFAULT_FLOW in properties) { @@ -91,9 +96,15 @@ UpdatePropertiesHandler.prototype.execute = function(context) { UpdatePropertiesHandler.prototype.revert = function(context) { var element = context.element, - businessObject = element.businessObject; + oldProperties = context.oldProperties, + businessObject = element.businessObject, + elementRegistry = this._elementRegistry; assign(businessObject, context.oldProperties); + if (ID in oldProperties) { + elementRegistry.updateId(element, oldProperties[ID]); + } + return context.changed; }; \ No newline at end of file diff --git a/test/spec/features/modeling/UpdatePropertiesSpec.js b/test/spec/features/modeling/UpdatePropertiesSpec.js index ae73c255..646db549 100644 --- a/test/spec/features/modeling/UpdatePropertiesSpec.js +++ b/test/spec/features/modeling/UpdatePropertiesSpec.js @@ -85,6 +85,20 @@ describe('features/modeling - update properties', function() { expect(updatedElements).toContain(elementRegistry.get('SequenceFlow_1_label')); })); + + it('updating id', inject(function(elementRegistry, modeling) { + + // given + var flowConnection = elementRegistry.get('SequenceFlow_1'); + + // when + modeling.updateProperties(flowConnection, { id: 'FOO_BAR' }); + + // then + expect(flowConnection.businessObject.id).toBe('FOO_BAR'); + expect(flowConnection.id).toBe('FOO_BAR'); + })); + }); @@ -139,6 +153,21 @@ describe('features/modeling - update properties', function() { expect(updatedElements).toContain(elementRegistry.get('SequenceFlow_1_label')); })); + + it('updating id', inject(function(elementRegistry, commandStack, modeling) { + + // given + var flowConnection = elementRegistry.get('SequenceFlow_1'); + + // when + modeling.updateProperties(flowConnection, { id: 'FOO_BAR' }); + commandStack.undo(); + + // then + expect(flowConnection.businessObject.id).toBe('SequenceFlow_1'); + expect(flowConnection.id).toBe('SequenceFlow_1'); + })); + });