diff --git a/resources/js/api.js b/resources/js/api.js index 809e0c53..5469bc24 100644 --- a/resources/js/api.js +++ b/resources/js/api.js @@ -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, }; }); diff --git a/resources/js/components/EntityDetail.vue b/resources/js/components/EntityDetail.vue index b08c1ebf..a4aedaa8 100644 --- a/resources/js/components/EntityDetail.vue +++ b/resources/js/components/EntityDetail.vue @@ -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; } @@ -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) { diff --git a/resources/js/components/modals/attribute/Edit.vue b/resources/js/components/modals/attribute/Edit.vue index 60a5038b..dd70e726 100644 --- a/resources/js/components/modals/attribute/Edit.vue +++ b/resources/js/components/modals/attribute/Edit.vue @@ -92,14 +92,14 @@ v-show="state.dependency.union" :title="t('global.dependency.modes.union_desc')" > - + {{ t('global.dependency.modes.union') }} - + {{ t('global.dependency.modes.intersect') }} @@ -209,7 +209,7 @@ />
-
+
- + {{ t('global.dependency.modes.union') }} - + {{ t('global.dependency.modes.intersect') }} @@ -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 = {}; @@ -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: [], }]; } @@ -505,6 +509,8 @@ } }; const getOperatorList = datatype => { + const list = defaultOperators.slice(); + console.log(list.map(l => l.operator).join(', ')); switch(datatype) { case 'epoch': case 'timeperiod': @@ -512,12 +518,12 @@ 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': @@ -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') { @@ -589,7 +596,7 @@ state.dependency.groups.push({ rules: [], - union: true, + union: false, }); gotoGroup(state.dependency.groups.length - 1); }; @@ -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: [], }], }, diff --git a/resources/js/i18n/de.json b/resources/js/i18n/de.json index 31c31dba..a1b9f075 100644 --- a/resources/js/i18n/de.json +++ b/resources/js/i18n/de.json @@ -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", diff --git a/resources/js/i18n/en.json b/resources/js/i18n/en.json index e9bc0eda..5dc57382 100644 --- a/resources/js/i18n/en.json +++ b/resources/js/i18n/en.json @@ -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",