Skip to content

Commit

Permalink
working on more operators
Browse files Browse the repository at this point in the history
Signed-off-by: Vinzenz Rosenkranz <[email protected]>
  • Loading branch information
v1r0x committed Dec 23, 2024
1 parent d6f9c71 commit ea0e65f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 31 deletions.
2 changes: 1 addition & 1 deletion resources/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ export async function updateAttributeDependency(etid, aid, dependency) {
group.rules = group.rules.map(rule => {
return {
attribute: rule.attribute.id,
operator: rule.operator.label,
operator: rule.operator.operator,
value: rule.value.value || rule.value,
};
});
Expand Down
16 changes: 15 additions & 1 deletion resources/js/components/EntityDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@
if(type == 'string-sc') {
tmpMatch = refValue?.id != rule.value;
} else if(type == 'string-mc') {
tmpMatch = refValue && refValue.every(mc => mc.id != rule.value);
tmpMatch = Array.isArray(refValue) && refValue.every(mc => mc.id != rule.value);
} else {
tmpMatch = refValue != rule.value;
}
Expand All @@ -747,6 +747,20 @@
case '>':
tmpMatch = refValue > rule.value;
break;
case '?':
case '!?':
if(type == 'string-sc') {
tmpMatch = refValue?.id !== undefined;
} else if(type == 'string-mc') {
tmpMatch = Array.isArray(refValue) && refValue.length > 0;
} else {
tmpMatch = refValue != undefined && refValue != null;
}
// !? is the exact opposite of ?
if(rule.operator == '!?') {
tmpMatch = !tmpMatch;
}
break;
}
if(matchAllRules && !tmpMatch) {
Expand Down
74 changes: 49 additions & 25 deletions resources/js/components/modals/attribute/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@
v-show="state.dependency.union"
:title="t('global.dependency.modes.union_desc')"
>
<i class="fas fa-fw fa-object-group" />
<i class="fas fa-fw fa-object-ungroup" />
{{ t('global.dependency.modes.union') }}
</span>
<span
v-show="!state.dependency.union"
:title="t('global.dependency.modes.intersect_desc')"
>
<i class="fas fa-fw fa-object-ungroup" />
<i class="fas fa-fw fa-object-group" />
{{ t('global.dependency.modes.intersect') }}
</span>
</button>
Expand Down Expand Up @@ -209,7 +209,7 @@
/>
</div>
<div class="col-4">
<div v-if="itm.attribute?.id && itm.operator?.id">
<div v-if="itm.attribute?.id && itm.operator?.id && !itm.operator.no_parameter">
<div
v-if="getInputTypeClass(itm.attribute.datatype) == 'boolean'"
class="form-check form-switch"
Expand Down Expand Up @@ -289,14 +289,14 @@
v-show="state.dependency.groups[state.currentDependencyGroupId].union"
:title="t('global.dependency.modes.union_desc')"
>
<i class="fas fa-fw fa-object-group" />
<i class="fas fa-fw fa-object-ungroup" />
{{ t('global.dependency.modes.union') }}
</span>
<span
v-show="!state.dependency.groups[state.currentDependencyGroupId].union"
:title="t('global.dependency.modes.intersect_desc')"
>
<i class="fas fa-fw fa-object-ungroup" />
<i class="fas fa-fw fa-object-group" />
{{ t('global.dependency.modes.intersect') }}
</span>
</button>
Expand Down Expand Up @@ -399,7 +399,11 @@
const validateDependencyRule = rule => {
return rule.attribute?.id &&
rule.operator?.id &&
!!rule.value;
(
(!rule.operator.no_parameter && !!rule.value)
||
(rule.operator.no_parameter && !rule.value)
);
};
const formatDependency = dependencyRules => {
const formattedRules = {};
Expand All @@ -422,9 +426,9 @@
return formattedGroup;
});
} else if(Object.keys(dependencyRules).length == 0) {
formattedRules.union = false;
formattedRules.union = true;
formattedRules.groups = [{
union: true,
union: false,
rules: [],
}];
}
Expand Down Expand Up @@ -505,19 +509,21 @@
}
};
const getOperatorList = datatype => {
const list = defaultOperators.slice();
console.log(list.map(l => l.operator).join(', '));
switch(datatype) {
case 'epoch':
case 'timeperiod':
case 'dimension':
case 'list':
case 'table':
case 'sql':
return [];
break;
// TODO handle entity attributes
case 'entity':
case 'entity-mc':
case 'userlist':
return [];
break;
case 'string':
case 'stringf':
case 'richtext':
Expand All @@ -527,42 +533,43 @@
case 'iconclass':
case 'rism':
case 'serial':
return operators.filter(o => {
operators.forEach(o => {
switch(o.id) {
case 1:
case 2:
return true;
default:
return false;
list.push(o);
break;
}
});
break;
case 'double':
case 'integer':
case 'date':
case 'percentage':
return operators.filter(o => {
operators.forEach(o => {
switch(o.id) {
case 1:
case 2:
case 3:
case 4:
return true;
default:
return false;
list.push(o);
break;
}
});
break;
case 'boolean':
return operators.filter(o => {
operators.forEach(o => {
switch(o.id) {
case 1:
return true;
default:
return false;
list.push(o);
break;
}
});
break;
default:
throw new Error(`Unsupported datatype ${datatype}`);
}
return list;
};
const getDependantOptions = (aid, datatype) => {
if(getInputTypeClass(datatype) == 'select') {
Expand All @@ -589,7 +596,7 @@
state.dependency.groups.push({
rules: [],
union: true,
union: false,
});
gotoGroup(state.dependency.groups.length - 1);
};
Expand All @@ -615,27 +622,44 @@
const operators = [
{
id: 1,
operator: '=',
label: '=',
},
{
id: 2,
operator: '!=',
label: '!=',
},
{
id: 3,
operator: '<',
label: '<',
},
{
id: 4,
operator: '>',
label: '>',
},
{
id: 5,
operator: '?',
label: 'Set',
no_parameter: true,
},
{
id: 6,
operator: '!?',
label: 'Unset',
no_parameter: true,
},
];
const defaultOperators = operators.filter(o => o.operator == '?' || o.operator == '!?');
const state = reactive({
currentDependencyGroupId: 0,
dependency: {
union: false,
union: true,
groups: [{
union: true,
union: false,
rules: [],
}],
},
Expand Down
4 changes: 2 additions & 2 deletions resources/js/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@
"no_rules_defined": "Noch keine Abhängigkeitsregeln für diese Gruppe definiert.",
"modes": {
"union": "Vereinigung",
"union_desc": "Alle Gruppen müssen erfüllt sein",
"union_desc": "Mindestens eine Gruppe muss erfüllt sein",
"intersect": "Schnitt",
"intersect_desc": "Mindestens eine Gruppe muss erfüllt sein"
"intersect_desc": "Alle Gruppen müssen erfüllt sein"
},
"depends_on": {
"title": "Hängt ab von",
Expand Down
4 changes: 2 additions & 2 deletions resources/js/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@
"no_rules_defined": "No dependency rules defined for this group yet.",
"modes": {
"union": "Union",
"union_desc": "All groups must evaluate to true",
"union_desc": "Any group must evaluate to true",
"intersect": "Intersect",
"intersect_desc": "Any group must evaluate to true"
"intersect_desc": "All groups must evaluate to true"
},
"depends_on": {
"title": "Depends on",
Expand Down

0 comments on commit ea0e65f

Please sign in to comment.