fix(copy-paste): create new business object on paste

* fixes pasted elements having same business object
* removes temporary fix that prevents pasting twice

Closes #686
Closes camunda/camunda-modeler#561
This commit is contained in:
Philipp Fromme 2017-06-20 15:51:19 +02:00
parent a5008381b3
commit 114da17403
2 changed files with 28 additions and 29 deletions

View File

@ -37,17 +37,9 @@ function BpmnCopyPaste(
var helper = new ModelCloneHelper(eventBus); var helper = new ModelCloneHelper(eventBus);
copyPaste.registerDescriptor(function(element, descriptor) { copyPaste.registerDescriptor(function(element, descriptor) {
var businessObject = getBusinessObject(element), var businessObject = descriptor.oldBusinessObject = getBusinessObject(element);
newBusinessObject = bpmnFactory.create(businessObject.$type);
var properties = getProperties(businessObject.$descriptor), var colors = {};
colors = {};
properties = filter(properties, function(property) {
return IGNORED_PROPERTIES.indexOf(property.replace(/bpmn:/, '')) === -1;
});
descriptor.businessObject = helper.clone(businessObject, newBusinessObject, properties);
descriptor.type = element.type; descriptor.type = element.type;
@ -79,11 +71,22 @@ function BpmnCopyPaste(
createdElements = context.createdElements, createdElements = context.createdElements,
parent = descriptor.parent, parent = descriptor.parent,
rootElement = canvas.getRootElement(), rootElement = canvas.getRootElement(),
businessObject, oldBusinessObject = descriptor.oldBusinessObject,
newBusinessObject,
source, source,
target, target,
canConnect; canConnect;
newBusinessObject = bpmnFactory.create(oldBusinessObject.$type);
var properties = getProperties(oldBusinessObject.$descriptor);
properties = filter(properties, function(property) {
return IGNORED_PROPERTIES.indexOf(property.replace(/bpmn:/, '')) === -1;
});
descriptor.businessObject = helper.clone(oldBusinessObject, newBusinessObject, properties);
if (descriptor.type === 'label') { if (descriptor.type === 'label') {
return; return;
} }
@ -119,19 +122,17 @@ function BpmnCopyPaste(
} }
} }
businessObject = descriptor.businessObject;
// remove the id or else we cannot paste multiple times // remove the id or else we cannot paste multiple times
delete businessObject.id; delete newBusinessObject.id;
// assign an ID // assign an ID
bpmnFactory._ensureId(businessObject); bpmnFactory._ensureId(newBusinessObject);
if (descriptor.type === 'bpmn:Participant' && descriptor.processRef) { if (descriptor.type === 'bpmn:Participant' && descriptor.processRef) {
descriptor.processRef = businessObject.processRef = bpmnFactory.create('bpmn:Process'); descriptor.processRef = newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
} }
setProperties(businessObject, descriptor, [ setProperties(newBusinessObject, descriptor, [
'isExpanded', 'isExpanded',
'triggeredByEvent' 'triggeredByEvent'
]); ]);
@ -141,13 +142,6 @@ function BpmnCopyPaste(
]); ]);
}); });
eventBus.on('commandStack.elements.paste.postExecuted', function() {
// temporarily disable multi paste until #686
// is addressed
clipboard.clear();
});
} }

View File

@ -58,7 +58,7 @@ describe('features/copy-paste', function() {
}); });
it('should forbid multi paste', inject( it('should paste twice', inject(
function(elementRegistry, canvas, copyPaste) { function(elementRegistry, canvas, copyPaste) {
// given // given
var element = elementRegistry.get('SubProcess_1kd6ist'), var element = elementRegistry.get('SubProcess_1kd6ist'),
@ -70,7 +70,7 @@ describe('features/copy-paste', function() {
copyPaste.paste({ copyPaste.paste({
element: rootElement, element: rootElement,
point: { point: {
x: 600, x: 1000,
y: 100 y: 100
} }
}); });
@ -78,14 +78,19 @@ describe('features/copy-paste', function() {
copyPaste.paste({ copyPaste.paste({
element: rootElement, element: rootElement,
point: { point: {
x: 600, x: 1500,
y: 275 y: 275
} }
}); });
// then // then
// pasted was only once expect(rootElement.children).to.have.length(3);
expect(rootElement.children).to.have.length(2);
var pastedElements = elementRegistry.filter(function(e) {
return e !== element && is(e, 'bpmn:SubProcess');
});
expect(pastedElements[0].id).to.not.equal(pastedElements[1].id);
} }
)); ));