From: Coleman Watts Date: Sat, 15 Apr 2023 19:21:23 +0000 (-0400) Subject: Afform - Allow selecting search operator for filter fields X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7b785806a601d082da8ef70fa503d926f9e8494e;p=civicrm-core.git Afform - Allow selecting search operator for filter fields --- diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField-menu.html b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField-menu.html index 668ec720b7..2ab4c16dfd 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField-menu.html +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField-menu.html @@ -75,6 +75,14 @@ {{:: ts('Search by range') }} +
  • +
    + + +
    +
  • diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js index 66136f86f6..d5fa1149a1 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js @@ -344,6 +344,23 @@ $scope.editingOptions = val; }; + this.searchOperators = { + '': ts('Auto'), + '=': '=', + '!=': '≠', + '>': '>', + '<': '<', + '>=': '≥', + '<=': '≤', + 'CONTAINS': ts('Contains'), + 'IN': ts('Is One Of'), + 'NOT IN': ts('Not One Of'), + 'LIKE': ts('Is Like'), + 'NOT LIKE': ts('Not Like'), + 'REGEXP': ts('Matches Pattern'), + 'NOT REGEXP': ts("Doesn't Match Pattern"), + }; + // Returns a reference to a path n-levels deep within an object function drillDown(parent, path) { var container = parent; diff --git a/ext/afform/core/ang/af/afField.component.js b/ext/afform/core/ang/af/afField.component.js index 9e7ac0e0c8..1e6173d58a 100644 --- a/ext/afform/core/ang/af/afField.component.js +++ b/ext/afform/core/ang/af/afField.component.js @@ -165,7 +165,7 @@ ) { value = value.split(','); } - $scope.dataProvider.getFieldData()[ctrl.fieldName] = value; + $scope.getSetValue(value); } // Get the repeat index of the entity fieldset (not the join) @@ -226,6 +226,26 @@ }; }; + // Getter/Setter function for most fields (except select & entityRef) + $scope.getSetValue = function(val) { + var currentVal = $scope.dataProvider.getFieldData()[ctrl.fieldName]; + // Setter + if (arguments.length) { + if (ctrl.defn.search_operator) { + if (typeof currentVal !== 'object') { + $scope.dataProvider.getFieldData()[ctrl.fieldName] = {}; + } + return ($scope.dataProvider.getFieldData()[ctrl.fieldName][ctrl.defn.search_operator] = val); + } + return ($scope.dataProvider.getFieldData()[ctrl.fieldName] = val); + } + // Getter + if (ctrl.defn.search_operator) { + return (currentVal || {})[ctrl.defn.search_operator]; + } + return currentVal; + }; + // Getter/Setter function for fields of type select or entityRef. $scope.getSetSelect = function(val) { var currentVal = $scope.dataProvider.getFieldData()[ctrl.fieldName]; @@ -241,6 +261,12 @@ else if (ctrl.defn.search_range) { return ($scope.dataProvider.getFieldData()[ctrl.fieldName]['>='] = val); } + else if (ctrl.defn.search_operator) { + if (typeof currentVal !== 'object') { + $scope.dataProvider.getFieldData()[ctrl.fieldName] = {}; + } + return ($scope.dataProvider.getFieldData()[ctrl.fieldName][ctrl.defn.search_operator] = val); + } return ($scope.dataProvider.getFieldData()[ctrl.fieldName] = val); } // Getter @@ -251,6 +277,9 @@ else if (ctrl.defn.search_range) { return currentVal['>=']; } + else if (ctrl.defn.search_operator) { + return (currentVal || {})[ctrl.defn.search_operator]; + } return currentVal; }; diff --git a/ext/afform/core/ang/af/fields/ChainSelect.html b/ext/afform/core/ang/af/fields/ChainSelect.html index ed756897ad..32607f1b8c 100644 --- a/ext/afform/core/ang/af/fields/ChainSelect.html +++ b/ext/afform/core/ang/af/fields/ChainSelect.html @@ -1 +1 @@ - + diff --git a/ext/afform/core/ang/af/fields/CheckBox.html b/ext/afform/core/ang/af/fields/CheckBox.html index 169baa2599..ba9b8aac93 100644 --- a/ext/afform/core/ang/af/fields/CheckBox.html +++ b/ext/afform/core/ang/af/fields/CheckBox.html @@ -4,4 +4,4 @@
  • - + diff --git a/ext/afform/core/ang/af/fields/Date.html b/ext/afform/core/ang/af/fields/Date.html index 2722191d28..bb34e2df84 100644 --- a/ext/afform/core/ang/af/fields/Date.html +++ b/ext/afform/core/ang/af/fields/Date.html @@ -1,4 +1,4 @@ - +
    - diff --git a/ext/afform/core/ang/af/fields/Number.html b/ext/afform/core/ang/af/fields/Number.html index 3980ec65a8..754b4abede 100644 --- a/ext/afform/core/ang/af/fields/Number.html +++ b/ext/afform/core/ang/af/fields/Number.html @@ -1,4 +1,4 @@ - +