feat(modeling): add feedback on invalid modeling action

This commit adds the ModelingFeedback component. It hooks into
modeling action rejected events and displays error messages
to the user.

The current behavior is to show an error message when dropping
a flow node outside a participant in a collaboration.

Related to #203
This commit is contained in:
Nico Rehwaldt 2015-05-08 15:27:39 +02:00
parent 45a4cf9140
commit 7b712d8428
3 changed files with 46 additions and 2 deletions

View File

@ -0,0 +1,36 @@
'use strict';
var is = require('../../../util/ModelUtil').is;
function ModelingFeedback(eventBus, tooltips) {
function showError(position, message) {
tooltips.add({
position: {
x: position.x + 5,
y: position.y + 5
},
type: 'error',
timeout: 2000,
html: '<div>' + message + '</div>'
});
}
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, 'flow elements must be children of pools/participants');
}
});
}
ModelingFeedback.$inject = [ 'eventBus', 'tooltips' ];
module.exports = ModelingFeedback;

View File

@ -1,7 +1,14 @@
module.exports = {
__init__: [ 'appendBehavior', 'dropBehavior', 'createBehavior', 'removeBehavior' ],
__init__: [
'appendBehavior',
'createBehavior',
'dropBehavior',
'removeBehavior',
'modelingFeedback'
],
appendBehavior: [ 'type', require('./AppendBehavior') ],
dropBehavior: [ 'type', require('./DropBehavior') ],
createBehavior: [ 'type', require('./CreateBehavior') ],
removeBehavior: [ 'type', require('./RemoveBehavior') ],
dropBehavior: [ 'type', require('./DropBehavior') ]
modelingFeedback: [ 'type', require('./ModelingFeedback') ]
};

View File

@ -5,6 +5,7 @@ module.exports = {
require('./rules'),
require('./behavior'),
require('diagram-js/lib/command'),
require('diagram-js/lib/features/tooltips'),
require('diagram-js/lib/features/change-support')
],
bpmnFactory: [ 'type', require('./BpmnFactory') ],