feat(modeling/UpdateProperties): unclaim old business object id
This commit is contained in:
parent
6d86dc9e27
commit
188487ebdc
|
@ -18,11 +18,12 @@ var DEFAULT_FLOW = 'default',
|
|||
* Use respective diagram-js provided handlers if you would
|
||||
* like to perform automated modeling.
|
||||
*/
|
||||
function UpdatePropertiesHandler(elementRegistry) {
|
||||
function UpdatePropertiesHandler(elementRegistry, moddle) {
|
||||
this._elementRegistry = elementRegistry;
|
||||
this._moddle = moddle;
|
||||
}
|
||||
|
||||
UpdatePropertiesHandler.$inject = [ 'elementRegistry' ];
|
||||
UpdatePropertiesHandler.$inject = [ 'elementRegistry', 'moddle' ];
|
||||
|
||||
module.exports = UpdatePropertiesHandler;
|
||||
|
||||
|
@ -63,13 +64,16 @@ UpdatePropertiesHandler.prototype.execute = function(context) {
|
|||
throw new Error('element required');
|
||||
}
|
||||
|
||||
var elementRegistry = this._elementRegistry;
|
||||
var elementRegistry = this._elementRegistry,
|
||||
ids = this._moddle.ids;
|
||||
|
||||
var businessObject = element.businessObject,
|
||||
properties = context.properties,
|
||||
oldProperties = context.oldProperties || getProperties(businessObject, keys(properties));
|
||||
|
||||
if (ID in properties) {
|
||||
ids.unclaim(businessObject[ID]);
|
||||
|
||||
elementRegistry.updateId(element, properties[ID]);
|
||||
}
|
||||
|
||||
|
@ -113,14 +117,18 @@ UpdatePropertiesHandler.prototype.execute = function(context) {
|
|||
UpdatePropertiesHandler.prototype.revert = function(context) {
|
||||
|
||||
var element = context.element,
|
||||
properties = context.properties,
|
||||
oldProperties = context.oldProperties,
|
||||
businessObject = element.businessObject,
|
||||
elementRegistry = this._elementRegistry;
|
||||
elementRegistry = this._elementRegistry,
|
||||
ids = this._moddle.ids;
|
||||
|
||||
// update properties
|
||||
setProperties(businessObject, oldProperties);
|
||||
|
||||
if (ID in oldProperties) {
|
||||
if (ID in properties) {
|
||||
ids.unclaim(properties[ID]);
|
||||
|
||||
elementRegistry.updateId(element, oldProperties[ID]);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
"karma-sinon-chai": "~0.3.0",
|
||||
"load-grunt-tasks": "^0.3.0",
|
||||
"mocha": "^2.2.5",
|
||||
"mocha-test-container-support": "~0.1.0",
|
||||
"mocha-test-container-support": "0.2.0",
|
||||
"source-map-concat": "^0.4.0",
|
||||
"stringify": "^3.1.0",
|
||||
"sinon": "~1.14.1",
|
||||
|
|
|
@ -122,11 +122,15 @@ describe('features/modeling - update properties', function() {
|
|||
|
||||
// given
|
||||
var flowConnection = elementRegistry.get('SequenceFlow_1');
|
||||
var ids = flowConnection.businessObject.$model.ids;
|
||||
|
||||
// when
|
||||
modeling.updateProperties(flowConnection, { id: 'FOO_BAR' });
|
||||
|
||||
// then
|
||||
expect(ids.assigned('FOO_BAR')).to.exist;
|
||||
expect(ids.assigned('SequenceFlow_1')).to.be.false;
|
||||
|
||||
expect(flowConnection.businessObject.id).to.equal('FOO_BAR');
|
||||
expect(flowConnection.id).to.equal('FOO_BAR');
|
||||
}));
|
||||
|
@ -222,12 +226,16 @@ describe('features/modeling - update properties', function() {
|
|||
|
||||
// given
|
||||
var flowConnection = elementRegistry.get('SequenceFlow_1');
|
||||
var ids = flowConnection.businessObject.$model.ids;
|
||||
|
||||
// when
|
||||
modeling.updateProperties(flowConnection, { id: 'FOO_BAR' });
|
||||
commandStack.undo();
|
||||
|
||||
// then
|
||||
expect(ids.assigned('FOO_BAR')).to.be.false;
|
||||
expect(ids.assigned('SequenceFlow_1')).to.exist;
|
||||
|
||||
expect(flowConnection.businessObject.id).to.equal('SequenceFlow_1');
|
||||
expect(flowConnection.id).to.equal('SequenceFlow_1');
|
||||
}));
|
||||
|
|
Loading…
Reference in New Issue