From: Vincent Vanwaelscappel Date: Thu, 3 Apr 2025 10:25:39 +0000 (+0200) Subject: wip #7434 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9d88cae5fe15fbee97cdc07d51efba1d2405b1bb;p=cubist_cms-back.git wip #7434 --- diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index 40d97ae..5eacfd0 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -421,6 +421,7 @@ class Field implements \ArrayAccess protected function when(): bool|string { $defaultOperator = '='; + $defaultLogicalOperator = 'AND'; if (!$this->hasAttribute('when')) { return false; } @@ -429,7 +430,7 @@ class Field implements \ArrayAccess $res = []; foreach ($when as $attr => $w) { if (is_scalar($w)) { - $w = ['values' => [$w], 'operator' => $defaultOperator]; + $w = ['values' => [$w], 'operator' => $defaultOperator, 'logical_operator' => $defaultLogicalOperator]; } else { if (isset($w['value'])) { $w['values'] = $w['value']; @@ -443,8 +444,11 @@ class Field implements \ArrayAccess if (!isset($w['operator'])) { $w['operator'] = $defaultOperator; } + if (!isset($w['logical_operator'])) { + $w['logical_operator'] = $defaultLogicalOperator; + } } else { - $w = ['values' => $w, 'operator' => $defaultOperator]; + $w = ['values' => $w, 'operator' => $defaultOperator, 'logical_operator' => $defaultLogicalOperator]; } } $res[$attr] = $w; diff --git a/src/resources/views/when.blade.php b/src/resources/views/when.blade.php index 66e3002..b1feb42 100644 --- a/src/resources/views/when.blade.php +++ b/src/resources/views/when.blade.php @@ -66,9 +66,11 @@ order = Math.min(order, condition.order); } }); - if (matchproperty === false) { - match = false - return false; + + if (conditions.logical_operator === 'AND') { + match = match && matchproperty; + } else if (conditions.logical_operator === 'OR') { + match = match || matchproperty; } }); @@ -83,7 +85,7 @@ function checkCondition(condition, operator, val) { try { - if(val==='/index.html') { + if (val === '/index.html') { console.log(condition, operator, val); } if (condition.id === undefined) {