Skip to content

Commit

Permalink
fix operator handling; add i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
v1r0x committed Dec 23, 2024
1 parent ea0e65f commit a264f1b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
18 changes: 14 additions & 4 deletions app/Http/Controllers/EditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,20 @@ public function patchDependency(Request $request, $etid, $aid) {
$dependsOn = [
'union' => $dependencyData['union'],
];
$operators = ['<', '>', '=', '!='];
$operators = [
'<' => true,
'>' => true,
'=' => true,
'!=' => true,
'?' => false,
'!?' => false,
];
foreach($dependencyData['groups'] as $group) {
if(count($group['rules']) > 0) {
$hasData = true;
$groupRules = [];
foreach($group['rules'] as $rule) {
if(!in_array($rule['operator'], $operators)) {
if(!in_array($rule['operator'], array_keys($operators))) {
return response()->json([
'error' => __('Operator mismatch')
], 400);

Check warning on line 525 in app/Http/Controllers/EditorController.php

View check run for this annotation

Codecov / codecov/patch

app/Http/Controllers/EditorController.php#L523-L525

Added lines #L523 - L525 were not covered by tests
Expand All @@ -523,11 +530,14 @@ public function patchDependency(Request $request, $etid, $aid) {
], 400);

Check warning on line 530 in app/Http/Controllers/EditorController.php

View check run for this annotation

Codecov / codecov/patch

app/Http/Controllers/EditorController.php#L528-L530

Added lines #L528 - L530 were not covered by tests
}

$groupRules[] = [
$formattedRule = [
'operator' => $rule['operator'],
'value' => $rule['value'],
'on' => $rule['attribute'],
];
if($operators[$rule['operator']]) {
$formattedRule['value'] = $rule['value'];
}
$groupRules[] = $formattedRule;
}
$dependsOn['groups'][] = [
'union' => $group['union'],
Expand Down
9 changes: 7 additions & 2 deletions resources/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,16 @@ export async function updateAttributeDependency(etid, aid, dependency) {
dependencyData.union = dependency.union;
dependencyData.groups = dependency.groups.map(group => {
group.rules = group.rules.map(rule => {
return {
const formattedRule = {
attribute: rule.attribute.id,
operator: rule.operator.operator,
value: rule.value.value || rule.value,
};

if(!rule.operator.no_parameter) {
formattedRule.value = rule.value.value || rule.value;
}

return formattedRule;
});
return group;
});
Expand Down
7 changes: 4 additions & 3 deletions resources/js/components/EntityDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,11 @@
attributeTriggers.forEach(dependantId => {
const attributeDependencies = state.entityTypeDependencies[dependantId];
const matchAllGroups = attributeDependencies.union;
const matchAllGroups = !attributeDependencies.union;
let dependencyMatch = matchAllGroups;
attributeDependencies.groups.forEach(group => {
const matchAllRules = group.union;
const matchAllRules = !group.union;
let ruleMatch = matchAllRules;
group.rules.forEach(rule => {
Expand Down Expand Up @@ -754,7 +754,8 @@
} else if(type == 'string-mc') {
tmpMatch = Array.isArray(refValue) && refValue.length > 0;
} else {
tmpMatch = refValue != undefined && refValue != null;
tmpMatch = refValue != undefined && refValue != null && refValue != '' &&
refValue?.value != undefined && refValue?.value != null && refValue?.value != '';
}
// !? is the exact opposite of ?
if(rule.operator == '!?') {
Expand Down
15 changes: 7 additions & 8 deletions resources/js/components/modals/attribute/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@
value: null,
};
converted.attribute = getAttribute(rule.on);
converted.operator = operators.find(o => o.label == rule.operator);
converted.operator = operators.find(o => o.operator == rule.operator);
converted.value = rule.value;
return converted;
});
Expand Down Expand Up @@ -510,7 +510,6 @@
};
const getOperatorList = datatype => {
const list = defaultOperators.slice();
console.log(list.map(l => l.operator).join(', '));
switch(datatype) {
case 'epoch':
case 'timeperiod':
Expand Down Expand Up @@ -623,33 +622,33 @@
{
id: 1,
operator: '=',
label: '=',
label: t('global.dependency.operators.equal'),
},
{
id: 2,
operator: '!=',
label: '!=',
label: t('global.dependency.operators.not_equal'),
},
{
id: 3,
operator: '<',
label: '<',
label: t('global.dependency.operators.less'),
},
{
id: 4,
operator: '>',
label: '>',
label: t('global.dependency.operators.greater'),
},
{
id: 5,
operator: '?',
label: 'Set',
label: t('global.dependency.operators.set'),
no_parameter: true,
},
{
id: 6,
operator: '!?',
label: 'Unset',
label: t('global.dependency.operators.not_set'),
no_parameter: true,
},
];
Expand Down
8 changes: 8 additions & 0 deletions resources/js/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@
"add_rule": "Neue Regel hinzufügen",
"remove_rule": "Regel entfernen",
"no_rules_defined": "Noch keine Abhängigkeitsregeln für diese Gruppe definiert.",
"operators": {
"equal": "entspricht",
"not_equal": "entspricht nicht",
"greater": "größer als",
"less": "kleiner als",
"set": "gesetzt",
"not_set": "nicht gesetzt"
},
"modes": {
"union": "Vereinigung",
"union_desc": "Mindestens eine Gruppe muss erfüllt sein",
Expand Down
8 changes: 8 additions & 0 deletions resources/js/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@
"add_rule": "Add Dependency Rule",
"remove_rule": "Remove Rule",
"no_rules_defined": "No dependency rules defined for this group yet.",
"operators": {
"equal": "equals",
"not_equal": "does not equal",
"greater": "greater than",
"less": "less than",
"set": "set",
"not_set": "not set"
},
"modes": {
"union": "Union",
"union_desc": "Any group must evaluate to true",
Expand Down

0 comments on commit a264f1b

Please sign in to comment.