feat(ordering): add sequence flow + association to correct parent
* remove ModelUtil#getSharedParent because we do proper ordering via BpmnOrderingProvider now. * Cherio! Related to #316
This commit is contained in:
parent
e66f2d92aa
commit
d9788c7f31
|
@ -47,8 +47,6 @@ Modeling.prototype.updateLabel = function(element, newLabel) {
|
|||
};
|
||||
|
||||
|
||||
var getSharedParent = require('./ModelingUtil').getSharedParent;
|
||||
|
||||
Modeling.prototype.connect = function(source, target, attrs) {
|
||||
|
||||
var bpmnRules = this._bpmnRules;
|
||||
|
@ -70,7 +68,7 @@ Modeling.prototype.connect = function(source, target, attrs) {
|
|||
}
|
||||
}
|
||||
|
||||
return this.createConnection(source, target, attrs, getSharedParent(source, target));
|
||||
return this.createConnection(source, target, attrs, source.parent);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var find = require('lodash/collection/find');
|
||||
|
||||
|
||||
function getParents(element) {
|
||||
|
||||
|
@ -18,17 +16,4 @@ function getParents(element) {
|
|||
return parents;
|
||||
}
|
||||
|
||||
module.exports.getParents = getParents;
|
||||
|
||||
|
||||
function getSharedParent(a, b) {
|
||||
|
||||
var parentsA = getParents(a),
|
||||
parentsB = getParents(b);
|
||||
|
||||
return find(parentsA, function(parent) {
|
||||
return parentsB.indexOf(parent) !== -1;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.getSharedParent = getSharedParent;
|
||||
module.exports.getParents = getParents;
|
|
@ -5,8 +5,7 @@ var forEach = require('lodash/collection/forEach'),
|
|||
|
||||
var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
||||
|
||||
var is = require('../../../util/ModelUtil').is,
|
||||
getSharedParent = require('../ModelingUtil').getSharedParent;
|
||||
var is = require('../../../util/ModelUtil').is;
|
||||
|
||||
function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules) {
|
||||
|
||||
|
@ -73,10 +72,10 @@ function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules) {
|
|||
// replace SequenceFlow <> MessageFlow
|
||||
|
||||
if (replacementType) {
|
||||
modeling.createConnection(source, target, {
|
||||
modeling.connect(source, target, {
|
||||
type: replacementType,
|
||||
waypoints: connection.waypoints.slice()
|
||||
}, getSharedParent(source, target));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ var inherits = require('inherits');
|
|||
|
||||
var OrderingProvider = require('diagram-js/lib/features/ordering/OrderingProvider');
|
||||
|
||||
var is = require('../../util/ModelUtil').is;
|
||||
|
||||
var findIndex = require('lodash/array/findIndex');
|
||||
|
||||
|
@ -22,8 +23,28 @@ function BpmnOrderingProvider(eventBus) {
|
|||
|
||||
var orders = [
|
||||
{ type: 'label', order: { level: 7 } },
|
||||
{ type: 'bpmn:SequenceFlow', order: { level: 5 } },
|
||||
{ type: 'bpmn:MessageFlow', order: { level: 6, top: true } },
|
||||
{
|
||||
type: 'bpmn:SequenceFlow',
|
||||
order: {
|
||||
level: 5,
|
||||
containers: [
|
||||
'bpmn:Participant',
|
||||
'bpmn:FlowElementsContainer'
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'bpmn:Association',
|
||||
order: {
|
||||
level: 6,
|
||||
containers: [
|
||||
'bpmn:Participant',
|
||||
'bpmn:FlowElementsContainer',
|
||||
'bpmn:Collaboration'
|
||||
]
|
||||
}
|
||||
},
|
||||
{ type: 'bpmn:MessageFlow', order: { level: 6, containers: [ 'bpmn:Collaboration' ] } },
|
||||
{ type: 'bpmn:BoundaryEvent', order: { level: 4 } },
|
||||
{ type: 'bpmn:Participant', order: { level: -2 } },
|
||||
{ type: 'bpmn:Lane', order: { level: -1 } }
|
||||
|
@ -48,15 +69,41 @@ function BpmnOrderingProvider(eventBus) {
|
|||
return order;
|
||||
}
|
||||
|
||||
var any = require('lodash/collection/any');
|
||||
|
||||
function isAny(element, types) {
|
||||
return any(types, function(t) {
|
||||
return is(element, t);
|
||||
});
|
||||
}
|
||||
|
||||
function findActualParent(element, newParent, containers) {
|
||||
|
||||
var actualParent = newParent;
|
||||
|
||||
while (actualParent) {
|
||||
|
||||
if (isAny(actualParent, containers)) {
|
||||
break;
|
||||
}
|
||||
|
||||
actualParent = actualParent.parent;
|
||||
}
|
||||
|
||||
if (!actualParent) {
|
||||
throw new Error('no parent for ' + element.id + ' in ' + newParent.id);
|
||||
}
|
||||
|
||||
return actualParent;
|
||||
}
|
||||
|
||||
this.getOrdering = function(element, newParent) {
|
||||
|
||||
var elementOrder = getOrder(element);
|
||||
|
||||
|
||||
if (elementOrder.top) {
|
||||
while (newParent.parent) {
|
||||
newParent = newParent.parent;
|
||||
}
|
||||
if (elementOrder.containers) {
|
||||
newParent = findActualParent(element, newParent, elementOrder.containers);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue