From a899df2a122238a9b0700a6cd4bdc1508946fc8c Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Thu, 29 Jan 2015 14:03:17 +0100 Subject: [PATCH] chore(modeling/rules): reduce complexity Related to #176 --- lib/features/modeling/rules/ModelingRules.js | 31 +++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/features/modeling/rules/ModelingRules.js b/lib/features/modeling/rules/ModelingRules.js index 164f7fa8..65ef1e2e 100644 --- a/lib/features/modeling/rules/ModelingRules.js +++ b/lib/features/modeling/rules/ModelingRules.js @@ -17,31 +17,40 @@ ModelingRules.prototype = Object.create(RuleProvider.prototype); ModelingRules.prototype.init = function() { + function nonExistantOrLabel(element) { + return !element || element.labelTarget; + } + + function isSame(a, b) { + return a === b; + } + // rules function canConnect(source, target, connection) { - if (!source || source.labelTarget || !target || target.labelTarget) { + if (nonExistantOrLabel(source) || nonExistantOrLabel(target)) { return null; } - var sourceBo = source.businessObject, - targetBo = target.businessObject, - connectionBo = connection && connection.businessObject; - - if (sourceBo.$parent !== targetBo.$parent) { - 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) { + if (isSame(source, target)) { return false; } + // only move between the same parent + if (!isSame(source.parent, target.parent)) { + return false; + } + + var sourceBo = source.businessObject, + targetBo = target.businessObject, + connectionBo = connection && connection.businessObject; + if (connectionBo && connectionBo.$instanceOf('bpmn:SequenceFlow')) { if (!sourceBo.$instanceOf('bpmn:FlowNode') || @@ -165,7 +174,7 @@ ModelingRules.prototype.init = function() { // into source var t = target; while (t) { - if (t === source) { + if (isSame(t, source)) { return false; }