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:
parent
e3f27ea1d5
commit
c586c908b2
|
@ -2,6 +2,7 @@
|
|||
|
||||
var is = require('../../../util/ModelUtil').is;
|
||||
|
||||
var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants';
|
||||
|
||||
function ModelingFeedback(eventBus, tooltips, translate) {
|
||||
|
||||
|
@ -18,16 +19,24 @@ function ModelingFeedback(eventBus, tooltips, translate) {
|
|||
}
|
||||
|
||||
eventBus.on([ 'shape.move.rejected', 'create.rejected' ], function(event) {
|
||||
|
||||
var context = event.context,
|
||||
shape = context.shape,
|
||||
target = context.target;
|
||||
|
||||
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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
var find = require('lodash/collection/find'),
|
||||
any = require('lodash/collection/any'),
|
||||
every = require('lodash/collection/every'),
|
||||
filter = require('lodash/collection/filter'),
|
||||
forEach = require('lodash/collection/forEach'),
|
||||
inherits = require('inherits');
|
||||
|
@ -114,9 +115,10 @@ BpmnRules.prototype.init = function() {
|
|||
});
|
||||
|
||||
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) {
|
||||
|
@ -424,7 +426,14 @@ function canDrop(element, target, position) {
|
|||
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
|
||||
if (is(target, 'bpmn:Participant') && !isExpanded(target)) {
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
var TestHelper = require('../../../TestHelper');
|
||||
|
||||
/* global bootstrapModeler, inject */
|
||||
/* global bootstrapModeler, inject, sinon */
|
||||
|
||||
var bpmnCopyPasteModule = require('../../../../lib/features/copy-paste'),
|
||||
copyPasteModule = require('diagram-js/lib/features/copy-paste'),
|
||||
tooltipsModule = require('diagram-js/lib/features/tooltips'),
|
||||
modelingModule = require('../../../../lib/features/modeling'),
|
||||
coreModule = require('../../../../lib/core');
|
||||
|
||||
|
@ -40,7 +41,7 @@ function expectCollection(collA, collB, contains) {
|
|||
|
||||
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'),
|
||||
collaborationXML = require('../../../fixtures/bpmn/features/copy-paste/collaboration.bpmn'),
|
||||
|
@ -321,6 +322,38 @@ describe('features/copy-paste', function() {
|
|||
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;
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue