feat(ModelingFeedback): add tooltip when pasting is disallowed

Only in the case of pasting outside of collaboration.

Closes camunda/camunda-modeler#252
This commit is contained in:
Ricardo Matias 2016-04-26 15:04:24 +02:00 committed by Nico Rehwaldt
parent e3f27ea1d5
commit c586c908b2
4 changed files with 60 additions and 9 deletions

View File

@ -2,6 +2,7 @@
var is = require('../../../util/ModelUtil').is; var is = require('../../../util/ModelUtil').is;
var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants';
function ModelingFeedback(eventBus, tooltips, translate) { function ModelingFeedback(eventBus, tooltips, translate) {
@ -18,16 +19,24 @@ function ModelingFeedback(eventBus, tooltips, translate) {
} }
eventBus.on([ 'shape.move.rejected', 'create.rejected' ], function(event) { eventBus.on([ 'shape.move.rejected', 'create.rejected' ], function(event) {
var context = event.context, var context = event.context,
shape = context.shape, shape = context.shape,
target = context.target; target = context.target;
if (is(target, 'bpmn:Collaboration') && is(shape, 'bpmn:FlowNode')) { if (is(target, 'bpmn:Collaboration') && is(shape, 'bpmn:FlowNode')) {
showError(event, translate('flow elements must be children of pools/participants')); showError(event, translate(COLLAB_ERR_MSG));
} }
}); });
eventBus.on([ 'elements.paste.rejected' ], function(event) {
var context = event.context,
position = context.position,
target = context.target;
if (is(target, 'bpmn:Collaboration')) {
showError(position, translate(COLLAB_ERR_MSG));
}
});
} }

View File

@ -2,6 +2,7 @@
var find = require('lodash/collection/find'), var find = require('lodash/collection/find'),
any = require('lodash/collection/any'), any = require('lodash/collection/any'),
every = require('lodash/collection/every'),
filter = require('lodash/collection/filter'), filter = require('lodash/collection/filter'),
forEach = require('lodash/collection/forEach'), forEach = require('lodash/collection/forEach'),
inherits = require('inherits'); inherits = require('inherits');
@ -114,9 +115,10 @@ BpmnRules.prototype.init = function() {
}); });
this.addRule('elements.paste', function(context) { this.addRule('elements.paste', function(context) {
var target = context.target; var tree = context.tree,
target = context.target;
return canPaste(target); return canPaste(tree, target);
}); });
this.addRule([ 'elements.delete' ], function(context) { this.addRule([ 'elements.delete' ], function(context) {
@ -424,7 +426,14 @@ function canDrop(element, target, position) {
return false; return false;
} }
function canPaste(target) { function canPaste(tree, target) {
var topLevel = tree[0];
if (is(target, 'bpmn:Collaboration')) {
return every(topLevel, function(e) {
return e.type === 'bpmn:Participant';
});
}
// disallow to create elements on collapsed pools // disallow to create elements on collapsed pools
if (is(target, 'bpmn:Participant') && !isExpanded(target)) { if (is(target, 'bpmn:Participant') && !isExpanded(target)) {

View File

@ -2,10 +2,11 @@
var TestHelper = require('../../../TestHelper'); var TestHelper = require('../../../TestHelper');
/* global bootstrapModeler, inject */ /* global bootstrapModeler, inject, sinon */
var bpmnCopyPasteModule = require('../../../../lib/features/copy-paste'), var bpmnCopyPasteModule = require('../../../../lib/features/copy-paste'),
copyPasteModule = require('diagram-js/lib/features/copy-paste'), copyPasteModule = require('diagram-js/lib/features/copy-paste'),
tooltipsModule = require('diagram-js/lib/features/tooltips'),
modelingModule = require('../../../../lib/features/modeling'), modelingModule = require('../../../../lib/features/modeling'),
coreModule = require('../../../../lib/core'); coreModule = require('../../../../lib/core');
@ -40,7 +41,7 @@ function expectCollection(collA, collB, contains) {
describe('features/copy-paste', function() { describe('features/copy-paste', function() {
var testModules = [ bpmnCopyPasteModule, copyPasteModule, modelingModule, coreModule ]; var testModules = [ bpmnCopyPasteModule, copyPasteModule, tooltipsModule, modelingModule, coreModule ];
var basicXML = require('../../../fixtures/bpmn/features/copy-paste/basic.bpmn'), var basicXML = require('../../../fixtures/bpmn/features/copy-paste/basic.bpmn'),
collaborationXML = require('../../../fixtures/bpmn/features/copy-paste/collaboration.bpmn'), collaborationXML = require('../../../fixtures/bpmn/features/copy-paste/collaboration.bpmn'),
@ -321,6 +322,38 @@ describe('features/copy-paste', function() {
expect(tree.getLength()).to.equal(0); expect(tree.getLength()).to.equal(0);
})); }));
it('pasting on a collaboration is disallowed when NOT every element is a Participant',
inject(function(copyPaste, elementRegistry, canvas, tooltips, eventBus) {
var task = elementRegistry.get('Task_13xbgyg'),
participant = elementRegistry.get('Participant_145muai'),
collaboration = canvas.getRootElement(),
tree;
var pasteRejected = sinon.spy(function() {});
// when
copyPaste.copy([ task, participant ]);
tree = new DescriptorTree(copyPaste._tree);
// then
expect(tree.getDepthLength(0)).to.equal(2);
// when
eventBus.on('elements.paste.rejected', pasteRejected);
copyPaste.paste({
element: collaboration,
point: {
x: 1000,
y: 1000
}
});
expect(pasteRejected).to.have.been.called;
}));
}); });
}); });