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);
copyPaste.registerDescriptor(function(element, descriptor) {
var businessObject = getBusinessObject(element),
newBusinessObject = bpmnFactory.create(businessObject.$type);
var businessObject = descriptor.oldBusinessObject = getBusinessObject(element);
var properties = getProperties(businessObject.$descriptor),
colors = {};
properties = filter(properties, function(property) {
return IGNORED_PROPERTIES.indexOf(property.replace(/bpmn:/, '')) === -1;
});
descriptor.businessObject = helper.clone(businessObject, newBusinessObject, properties);
var colors = {};
descriptor.type = element.type;
@ -79,11 +71,22 @@ function BpmnCopyPaste(
createdElements = context.createdElements,
parent = descriptor.parent,
rootElement = canvas.getRootElement(),
businessObject,
oldBusinessObject = descriptor.oldBusinessObject,
newBusinessObject,
source,
target,
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') {
return;
}
@ -119,19 +122,17 @@ function BpmnCopyPaste(
}
}
businessObject = descriptor.businessObject;
// remove the id or else we cannot paste multiple times
delete businessObject.id;
delete newBusinessObject.id;
// assign an ID
bpmnFactory._ensureId(businessObject);
bpmnFactory._ensureId(newBusinessObject);
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',
'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) {
// given
var element = elementRegistry.get('SubProcess_1kd6ist'),
@ -70,7 +70,7 @@ describe('features/copy-paste', function() {
copyPaste.paste({
element: rootElement,
point: {
x: 600,
x: 1000,
y: 100
}
});
@ -78,14 +78,19 @@ describe('features/copy-paste', function() {
copyPaste.paste({
element: rootElement,
point: {
x: 600,
x: 1500,
y: 275
}
});
// then
// pasted was only once
expect(rootElement.children).to.have.length(2);
expect(rootElement.children).to.have.length(3);
var pastedElements = elementRegistry.filter(function(e) {
return e !== element && is(e, 'bpmn:SubProcess');
});
expect(pastedElements[0].id).to.not.equal(pastedElements[1].id);
}
));