feat(context-pad): open the replace menu after creating a shape

Closes camunda/camunda-modeler#327
This commit is contained in:
Ricardo Matias 2016-08-18 15:23:19 +02:00
parent 13a9d24e84
commit 810a107262
2 changed files with 66 additions and 7 deletions

View File

@ -14,7 +14,7 @@ var assign = require('lodash/object/assign'),
/** /**
* A provider for BPMN 2.0 elements context pad * A provider for BPMN 2.0 elements context pad
*/ */
function ContextPadProvider(contextPad, modeling, elementFactory, function ContextPadProvider(eventBus, contextPad, modeling, elementFactory,
connect, create, popupMenu, connect, create, popupMenu,
canvas, rules, translate) { canvas, rules, translate) {
@ -31,9 +31,20 @@ function ContextPadProvider(contextPad, modeling, elementFactory,
this._canvas = canvas; this._canvas = canvas;
this._rules = rules; this._rules = rules;
this._translate = translate; this._translate = translate;
eventBus.on('create.end', 250, function(context) {
var shape = context.shape,
entries = contextPad.getEntries(shape);
if (entries.replace) {
entries.replace.action.click(context, shape);
}
});
} }
ContextPadProvider.$inject = [ ContextPadProvider.$inject = [
'eventBus',
'contextPad', 'contextPad',
'modeling', 'modeling',
'elementFactory', 'elementFactory',

View File

@ -8,6 +8,8 @@ var domQuery = require('min-dom/lib/query');
var is = require('../../../../lib/util/ModelUtil').is; var is = require('../../../../lib/util/ModelUtil').is;
var canvasEvent = require('../../../util/MockEvents').createCanvasEvent;
/* global bootstrapModeler, inject */ /* global bootstrapModeler, inject */
@ -16,6 +18,7 @@ var contextPadModule = require('../../../../lib/features/context-pad'),
coreModule = require('../../../../lib/core'), coreModule = require('../../../../lib/core'),
modelingModule = require('../../../../lib/features/modeling'), modelingModule = require('../../../../lib/features/modeling'),
replaceMenuModule = require('../../../../lib/features/popup-menu'), replaceMenuModule = require('../../../../lib/features/popup-menu'),
createModule = require('diagram-js/lib/features/create'),
customRulesModule = require('../../../util/custom-rules'); customRulesModule = require('../../../util/custom-rules');
@ -26,7 +29,8 @@ describe('features - context-pad', function() {
modelingModule, modelingModule,
contextPadModule, contextPadModule,
replaceMenuModule, replaceMenuModule,
customRulesModule customRulesModule,
createModule
]; ];
@ -332,8 +336,7 @@ describe('features - context-pad', function() {
// then // then
expect(padEntry(padNode, 'replace')).not.to.exist; expect(padEntry(padNode, 'replace')).not.to.exist;
}) }));
);
it('should include control if replacement is allowed', it('should include control if replacement is allowed',
@ -354,8 +357,53 @@ describe('features - context-pad', function() {
// then // then
expect(padEntry(padNode, 'replace')).to.exist; expect(padEntry(padNode, 'replace')).to.exist;
}) }));
);
it('should open the replace menu after an element is created',
inject(function(create, dragging, canvas, elementFactory) {
// given
var rootShape = canvas.getRootElement(),
startEvent = elementFactory.createShape({ type: 'bpmn:StartEvent' }),
replaceMenu;
// when
create.start(canvasEvent({ x: 0, y: 0 }), startEvent);
dragging.move(canvasEvent({ x: 50, y: 50 }));
dragging.hover({ element: rootShape });
dragging.move(canvasEvent({ x: 75, y: 75 }));
dragging.end();
replaceMenu = domQuery('.bpmn-replace', container);
// then
expect(replaceMenu).to.exist;
}));
it('should not open the replace menu after an element is created when there is none',
inject(function(create, dragging, canvas, elementFactory) {
// given
var rootShape = canvas.getRootElement(),
dataObject = elementFactory.createShape({ type: 'bpmn:DataObjectReference' }),
replaceMenu;
// when
create.start(canvasEvent({ x: 0, y: 0 }), dataObject);
dragging.move(canvasEvent({ x: 50, y: 50 }));
dragging.hover({ element: rootShape });
dragging.move(canvasEvent({ x: 75, y: 75 }));
dragging.end();
replaceMenu = domQuery('.bpmn-replace', container);
// then
expect(replaceMenu).to.not.exist;
}));
}); });