Skip to content

Commit

Permalink
Add functioning Spacetool and tests (#162)
Browse files Browse the repository at this point in the history
* Add functioning Spacetool and tests

* Add space tool tests to visual tests

Co-authored-by: jan.ladleif <jan.ladleif@hpi.uni-potsdam.de>
  • Loading branch information
yT0n1 and jan.ladleif authored Oct 29, 2020
1 parent 8239b9c commit 9446d38
Show file tree
Hide file tree
Showing 13 changed files with 686 additions and 36 deletions.
6 changes: 6 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ module.exports = function(karma) {

browsers: ['ChromeHeadless'],

client: {
mocha: {
ui: 'bdd',
}
},

browserNoActivityTimeout: 30000,

singleRun: true,
Expand Down
4 changes: 3 additions & 1 deletion lib/Modeler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import RulesModule from './features/rules';
import CopyPasteModule from './features/copy-paste';
import SwitchModule from './features/switch';
import BpmnDiOrdering from './features/di-ordering';
import ChoreoSpaceToolModule from './features/space-tool';

import {
displayChoreography
Expand Down Expand Up @@ -59,6 +60,7 @@ Modeler.prototype._modules = [].concat(
RulesModule,
CopyPasteModule,
SwitchModule,
BpmnDiOrdering
BpmnDiOrdering,
ChoreoSpaceToolModule,
]
);
28 changes: 0 additions & 28 deletions lib/features/modeling/ChoreoModeling.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import SwapInitiatingParticipantHandler from './cmd/SwapInitiatingParticipantHan
import ChoreoAppendShapeHandler from './cmd/ChoreoAppendShapeHandler';
import LinkCallChoreoHandler from './cmd/LinkCallChoreoHandler';
import LinkCallChoreoParticipantHandler from './cmd/LinkCallChoreoParticipantHandler';
import { is } from 'bpmn-js/lib/util/ModelUtil';

/**
* Component that manages choreography specific modeling moves that attach to the
Expand Down Expand Up @@ -140,30 +139,3 @@ ChoreoModeling.prototype.unlinkCallChoreoParticipants = function(element) {
outerParticipant: pa.outerParticipantRef
}));
};

/**
* This function overwrites the one from diagram-js. Crucially we need to filter out all the participants
* or else they are moved twice, as they are nested in the activity and then moved again separately.
* Info: Alternatively this issue could be fixed by overwriting space tool handler, but we decided not to
* do this as it would require an additional file.
* Additionally, the spaceTool is only ever called via the modeling object.
* @param movingShapes
* @param resizingShapes
* @param delta
* @param direction
* @param start
*/
ChoreoModeling.prototype.createSpace = function(movingShapes, resizingShapes, delta, direction, start) {
if (direction === 'n' || direction === 's') {
movingShapes = movingShapes.filter(s => !is(s, 'bpmn:Participant'));
}
var context = {
movingShapes: movingShapes,
resizingShapes: resizingShapes,
delta: delta,
direction: direction,
start: start
};

this._commandStack.execute('spaceTool', context);
};
29 changes: 29 additions & 0 deletions lib/features/modeling/behavior/ChoreoSpaceToolBehavior.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { forEach } from 'min-dash';
import { is } from 'bpmn-js/lib/util/ModelUtil';

export default function ChoreoSpaceToolBehavior(eventBus, resize) {
// This overwrites an event listener in SpaceToolBehavior in BpmnJS (due to the higher priority).
// We need to set a different minSize for participants as BpmnJS has the sizes for lanes.
// We also add minDimensions for ChoreoActivities.
eventBus.on('spaceTool.getMinDimensions', 3000, function(context) {
const shapes = context.shapes;
const minDimensions = {};

forEach(shapes, function(shape) {
const id = shape.id;
if (is(shape, 'bpmn:ChoreographyActivity')) {
minDimensions[ id ] = resize.computeMinResizeBox({ shape: shape, direction: context.direction });
}
if (is(shape, 'bpmn:Participant')) {
minDimensions[ id ] = { width: 0, height: 0 };
}
});

return minDimensions;
});
}

ChoreoSpaceToolBehavior.$inject = [
'eventBus',
'resize'
];
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function ResizeParticipantBandBehavior(injector, modeling) {
let oldBounds = context.oldBounds;

if (is(shape, 'bpmn:ChoreographyActivity')) {
let delta = {
const delta = {
x: newBounds.x - oldBounds.x,
y: newBounds.y - oldBounds.y,
};
Expand All @@ -62,8 +62,8 @@ export default function ResizeParticipantBandBehavior(injector, modeling) {

let messageShape = getMessageShape(bandShape);
if (messageShape) {
delta = calculateDelta(getAttachedMessageBounds(bandShape), messageShape);
modeling.moveShape(messageShape, delta);
const messageDelta = calculateDelta(getAttachedMessageBounds(bandShape), messageShape);
modeling.moveShape(messageShape, messageDelta);
}
});
}
Expand All @@ -75,4 +75,4 @@ ResizeParticipantBandBehavior.$inject = [
'modeling'
];

inherits(ResizeParticipantBandBehavior, CommandInterceptor);
inherits(ResizeParticipantBandBehavior, CommandInterceptor);
10 changes: 7 additions & 3 deletions lib/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ import RemoveParticipantBehavior from './RemoveParticipantBehavior';
import ResizeParticipantBandBehavior from './ResizeParticipantBandBehavior';
import DeleteMessageBehavior from './DeleteMessageBehavior';
import ToggleChoreoCollapseBehaviour from './ToggleChoreoCollapseBehavior';
import ChoreoSpaceToolBehavior from './ChoreoSpaceToolBehavior';

export default {
__init__: [
'createChoreoTaskBehavior',
'removeParticipantBehavior',
'resizeParticipantBehavior',
'deleteMessageBehavior',
'toggleChoreoCollapseBehavior'
'toggleChoreoCollapseBehavior',
'choreoSpaceToolBehavior'
],
createChoreoTaskBehavior: [ 'type', CreateChoreoTaskBehavior ],
removeParticipantBehavior: [ 'type', RemoveParticipantBehavior ],
resizeParticipantBehavior: [ 'type', ResizeParticipantBandBehavior ],
deleteMessageBehavior: [ 'type', DeleteMessageBehavior ],
toggleChoreoCollapseBehavior: [ 'type', ToggleChoreoCollapseBehaviour ]
};
toggleChoreoCollapseBehavior: [ 'type', ToggleChoreoCollapseBehaviour ],
choreoSpaceToolBehavior: [ 'type', ChoreoSpaceToolBehavior ]

};
Loading

0 comments on commit 9446d38

Please sign in to comment.