feat(editor-actions): add moving all elements to the origin

Related to camunda/camunda-modeler#362
This commit is contained in:
Ricardo Matias 2016-08-18 09:08:00 +02:00 committed by Nico Rehwaldt
parent 810a107262
commit 18d31a7bc1
4 changed files with 85 additions and 7 deletions

View File

@ -8,6 +8,7 @@ var filter = require('lodash/collection/filter');
var is = require('../../util/ModelUtil').is; var is = require('../../util/ModelUtil').is;
var getBBox = require('diagram-js/lib/util/Elements').getBBox;
function BpmnEditorActions( function BpmnEditorActions(
injector, injector,
@ -19,7 +20,8 @@ function BpmnEditorActions(
distributeElements, distributeElements,
alignElements, alignElements,
directEditing, directEditing,
searchPad) { searchPad,
modeling) {
injector.invoke(EditorActions, this); injector.invoke(EditorActions, this);
@ -30,10 +32,12 @@ function BpmnEditorActions(
var rootElement = canvas.getRootElement(); var rootElement = canvas.getRootElement();
var elements = elementRegistry.filter(function(element) { var elements = elementRegistry.filter(function(element) {
return element != rootElement; return element !== rootElement;
}); });
selection.select(elements); selection.select(elements);
return elements;
}, },
spaceTool: function() { spaceTool: function() {
spaceTool.toggle(); spaceTool.toggle();
@ -77,6 +81,25 @@ function BpmnEditorActions(
}, },
find: function() { find: function() {
searchPad.toggle(); searchPad.toggle();
},
moveToOrigin: function() {
var rootElement = canvas.getRootElement(),
boundingBox,
elements;
if (is(rootElement, 'bpmn:Collaboration')) {
elements = elementRegistry.filter(function(element) {
return is(element.parent, 'bpmn:Collaboration');
});
} else {
elements = elementRegistry.filter(function(element) {
return element !== rootElement;
});
}
boundingBox = getBBox(elements);
modeling.moveElements(elements, { x: -boundingBox.x, y: -boundingBox.y }, rootElement);
} }
}); });
} }
@ -93,7 +116,8 @@ BpmnEditorActions.$inject = [
'distributeElements', 'distributeElements',
'alignElements', 'alignElements',
'directEditing', 'directEditing',
'searchPad' 'searchPad',
'modeling'
]; ];
module.exports = BpmnEditorActions; module.exports = BpmnEditorActions;

View File

@ -9,7 +9,8 @@ module.exports = {
require('../copy-paste'), require('../copy-paste'),
require('../distribute-elements'), require('../distribute-elements'),
require('../global-connect'), require('../global-connect'),
require('../search') require('../search'),
require('../modeling')
], ],
editorActions: [ 'type', require('./BpmnEditorActions') ] editorActions: [ 'type', require('./BpmnEditorActions') ]
}; };

View File

@ -0,0 +1,53 @@
'use strict';
require('../../../TestHelper');
/* global bootstrapModeler, inject */
var pick = require('lodash/object/pick');
var getBBox = require('diagram-js/lib/util/Elements').getBBox;
var bpmnEditorActionsModule = require('../../../../lib/features/editor-actions'),
modelingModule = require('../../../../lib/features/modeling'),
coreModule = require('../../../../lib/core');
var basicXML = require('../../../fixtures/bpmn/simple.bpmn'),
collaborationXML = require('../../../fixtures/bpmn/complex.bpmn');
describe('features/editor-actions', function() {
describe('#moveToOrigin', function() {
function testMoveToOrigin(xml) {
return function() {
beforeEach(bootstrapModeler(xml, { modules: [ bpmnEditorActionsModule, modelingModule, coreModule ] }));
it('should move to origin', inject(function(editorActions) {
// given
var elements = editorActions.trigger('selectElements'),
boundingBox;
// when
editorActions.trigger('moveToOrigin');
boundingBox = getBBox(elements);
// then
expect(pick(boundingBox, [ 'x', 'y' ])).to.eql({ x: 0, y: 0 });
}));
};
}
describe('single process', testMoveToOrigin(basicXML));
describe('collaboration', testMoveToOrigin(collaborationXML));
});
});

View File

@ -36,7 +36,7 @@ describe('features - keyboard', function() {
it('should include triggers inside editorActions', inject(function(editorActions) { it('should include triggers inside editorActions', inject(function(editorActions) {
// then // then
expect(editorActions.length()).to.equal(17); expect(editorActions.length()).to.equal(18);
})); }));