fix(rules): disallow circular connection
This temporarily disallows connections from and to the same element because it rendered the connection unusable.. This change can be reverted once proper auto layout for circular connections is implemented. Closes #176
This commit is contained in:
parent
fef6e056a9
commit
d8057a2acc
|
@ -33,7 +33,17 @@ ModelingRules.prototype.init = function() {
|
|||
return false;
|
||||
}
|
||||
|
||||
// See https://github.com/bpmn-io/bpmn-js/issues/178
|
||||
// as a workround we disallow connections with same
|
||||
// target and source element.
|
||||
// This rule must be removed if a auto layout for this
|
||||
// connections is implemented.
|
||||
if (sourceBo === targetBo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (connectionBo && connectionBo.$instanceOf('bpmn:SequenceFlow')) {
|
||||
|
||||
if (!sourceBo.$instanceOf('bpmn:FlowNode') ||
|
||||
!targetBo.$instanceOf('bpmn:FlowNode') ||
|
||||
sourceBo.$instanceOf('bpmn:EndEvent') ||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
module.exports = {
|
||||
__depends__: [
|
||||
require('diagram-js/lib/features/rules')
|
||||
],
|
||||
__init__: [ 'modelingRules' ],
|
||||
modelingRules: [ 'type', require('./ModelingRules') ]
|
||||
};
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
'use strict';
|
||||
|
||||
var Matchers = require('../../../Matchers'),
|
||||
TestHelper = require('../../../TestHelper');
|
||||
|
||||
/* global bootstrapModeler, inject */
|
||||
|
||||
var _ = require('lodash');
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
var modelingModule = require('../../../../lib/features/modeling'),
|
||||
rulesModule = require('../../../../lib/features/modeling/rules'),
|
||||
coreModule = require('../../../../lib/core');
|
||||
|
||||
|
||||
describe('features/ModelingRules', function() {
|
||||
|
||||
beforeEach(Matchers.addDeepEquals);
|
||||
|
||||
|
||||
var diagramXML = fs.readFileSync('test/fixtures/bpmn/sequence-flows.bpmn', 'utf8');
|
||||
|
||||
var testModules = [ coreModule, modelingModule, rulesModule ];
|
||||
|
||||
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
||||
|
||||
|
||||
// See workaround https://github.com/bpmn-io/bpmn-js/issues/176
|
||||
// The wanted behavior until https://github.com/bpmn-io/bpmn-js/issues/176 is fixed
|
||||
describe('connect with source == target', function() {
|
||||
|
||||
it('should not allow connection', inject(function(elementRegistry, modeling, rules) {
|
||||
|
||||
// given
|
||||
var taskShape = elementRegistry.get('Task_1'),
|
||||
task = taskShape.businessObject;
|
||||
|
||||
|
||||
// when
|
||||
var allowed = rules.allowed('connection.create', {
|
||||
connection: null,
|
||||
source: taskShape,
|
||||
target: taskShape
|
||||
});
|
||||
|
||||
// then
|
||||
// connection should not be allowed
|
||||
expect(allowed).toBe(false);
|
||||
}));
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue