parent
fed7aefabe
commit
1cdce93f5b
|
@ -11,16 +11,16 @@ var isEventSubProcess = require('../../../util/DiUtil').isEventSubProcess;
|
|||
/**
|
||||
* Defines the behavior when a start event is moved
|
||||
*/
|
||||
function MoveStartEventBehavior(eventBus, bpmnReplace, bpmnRules, elementRegistry) {
|
||||
|
||||
function MoveStartEventBehavior(eventBus, bpmnReplace, bpmnRules, elementRegistry, selection) {
|
||||
CommandInterceptor.call(this, eventBus);
|
||||
|
||||
this.postExecuted([ 'elements.move' ], function(event) {
|
||||
|
||||
var target = event.context.newParent,
|
||||
var context = event.context,
|
||||
target = context.newParent,
|
||||
elements = [];
|
||||
|
||||
forEach(event.context.closure.topLevel, function(topLevelElements) {
|
||||
forEach(context.closure.topLevel, function(topLevelElements) {
|
||||
if (isEventSubProcess(topLevelElements)) {
|
||||
elements = elements.concat(topLevelElements.children);
|
||||
} else {
|
||||
|
@ -30,17 +30,27 @@ function MoveStartEventBehavior(eventBus, bpmnReplace, bpmnRules, elementRegistr
|
|||
|
||||
var canReplace = bpmnRules.canReplace(elements, target);
|
||||
|
||||
forEach(canReplace.replace, function(newElementData) {
|
||||
forEach(canReplace.replace, function(replacements) {
|
||||
|
||||
var newElement = {
|
||||
type: newElementData.type
|
||||
type: replacements.newElementType
|
||||
};
|
||||
|
||||
bpmnReplace.replaceElement(elementRegistry.get(newElementData.id), newElement);
|
||||
var oldElement = elementRegistry.get(replacements.oldElementId);
|
||||
|
||||
var idx = elements.indexOf(oldElement);
|
||||
elements[idx] = bpmnReplace.replaceElement(oldElement, newElement, { select: false });
|
||||
|
||||
});
|
||||
|
||||
if (canReplace.replace) {
|
||||
selection.select(elements);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
MoveStartEventBehavior.$inject = [ 'eventBus', 'bpmnReplace', 'bpmnRules', 'elementRegistry' ];
|
||||
MoveStartEventBehavior.$inject = [ 'eventBus', 'bpmnReplace', 'bpmnRules', 'elementRegistry', 'selection' ];
|
||||
|
||||
inherits(MoveStartEventBehavior, CommandInterceptor);
|
||||
|
||||
|
|
|
@ -431,8 +431,8 @@ function canReplace(elements, target) {
|
|||
canDrop(element, target)) {
|
||||
|
||||
canExecute.replace.push({
|
||||
id: element.id,
|
||||
type: 'bpmn:StartEvent'
|
||||
oldElementId: element.id,
|
||||
newElementType: 'bpmn:StartEvent'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ function BpmnReplacePreview(eventBus, elementRegistry, elementFactory, canvas, m
|
|||
|
||||
var replacements = context.canExecute.replace;
|
||||
|
||||
forEach(replacements, function(newElementData) {
|
||||
forEach(replacements, function(replacement) {
|
||||
|
||||
var id = newElementData.id;
|
||||
var id = replacement.oldElementId;
|
||||
|
||||
var newElement = {
|
||||
type: newElementData.type
|
||||
type: replacement.newElementType
|
||||
};
|
||||
|
||||
// if the visual of the element is already replaced
|
||||
|
|
|
@ -54,9 +54,12 @@ function BpmnReplace(bpmnFactory, moddle, popupMenu, replace, selection, modelin
|
|||
*
|
||||
* @param {djs.model.Base} element
|
||||
* @param {Object} target
|
||||
* @param {Object} [hints]
|
||||
* @return {djs.model.Base} the newly created element
|
||||
*/
|
||||
function replaceElement(element, target) {
|
||||
function replaceElement(element, target, hints) {
|
||||
|
||||
hints = hints || {};
|
||||
|
||||
var type = target.type,
|
||||
oldBusinessObject = element.businessObject,
|
||||
|
@ -103,7 +106,9 @@ function BpmnReplace(bpmnFactory, moddle, popupMenu, replace, selection, modelin
|
|||
|
||||
newElement = replace.replaceElement(element, newElement);
|
||||
|
||||
selection.select(newElement);
|
||||
if (hints.select !== false) {
|
||||
selection.select(newElement);
|
||||
}
|
||||
|
||||
return newElement;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ var replacePreviewModule = require('../../../../../lib/features/replace-preview'
|
|||
var is = require('../../../../../lib/util/ModelUtil').is,
|
||||
Events = require('diagram-js/test/util/Events');
|
||||
|
||||
describe.only('features/modeling - move start event behavior', function() {
|
||||
describe('features/modeling - move start event behavior', function() {
|
||||
|
||||
var testModules = [ replacePreviewModule, modelingModule, coreModule ];
|
||||
|
||||
|
@ -60,6 +60,36 @@ describe.only('features/modeling - move start event behavior', function() {
|
|||
|
||||
// then
|
||||
expect(selection.get()).to.include(replacement);
|
||||
expect(selection.get()).not.to.include(startEvent);
|
||||
|
||||
}));
|
||||
|
||||
|
||||
it('should select all moved shapes after some of them got replaced',
|
||||
inject(function(elementRegistry, canvas, dragging, move, selection) {
|
||||
|
||||
// given
|
||||
var startEvent1 = elementRegistry.get('StartEvent_1'),
|
||||
startEvent2 = elementRegistry.get('StartEvent_2'),
|
||||
startEvent3 = elementRegistry.get('StartEvent_3'),
|
||||
rootElement = canvas.getRootElement();
|
||||
|
||||
// when
|
||||
selection.select([ startEvent1, startEvent2, startEvent3 ]);
|
||||
moveShape(startEvent1, rootElement, { x: 140, y: 250 });
|
||||
|
||||
dragging.end();
|
||||
|
||||
var replacements = elementRegistry.filter(function(element) {
|
||||
if(is(element, 'bpmn:StartEvent') && element.type !== 'label') {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// then
|
||||
expect(selection.get()).to.include(replacements[0]);
|
||||
expect(selection.get()).to.include(replacements[1]);
|
||||
expect(selection.get()).to.include(replacements[2]);
|
||||
|
||||
}));
|
||||
|
||||
|
|
Loading…
Reference in New Issue