Afform - Support date range filters for search displays
authorColeman Watts <coleman@civicrm.org>
Fri, 19 Feb 2021 01:59:40 +0000 (20:59 -0500)
committerColeman Watts <coleman@civicrm.org>
Fri, 19 Feb 2021 01:59:40 +0000 (20:59 -0500)
ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php
ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js
ext/afform/core/Civi/Afform/AfformMetadataInjector.php

index c62c8482eef2534535ec5546e3a55578c236c1e4..3b8a0614e8041b7daa9cc2c38247a6aadb801af2 100644 (file)
@@ -234,6 +234,8 @@ class AfformAdminMeta {
       ];
     }
 
+    $data['dateRanges'] = \CRM_Utils_Array::makeNonAssociative(\CRM_Core_OptionGroup::values('relative_date_filters'), 'id', 'label');
+
     return $data;
   }
 
index 1534dafb29dd0540b18527087268fa1a62b8c342..950722e4952293b8ef7e802680ae5d69b45c2b48 100644 (file)
@@ -52,6 +52,9 @@
         if (ctrl.node.defn && ctrl.node.defn.options) {
           return ctrl.node.defn.options;
         }
+        if (_.includes(['Date', 'Timestamp'], $scope.getProp('data_type'))) {
+          return CRM.afGuiEditor.dateRanges;
+        }
         return ctrl.getDefn().options || ($scope.getProp('input_type') === 'CheckBox' ? null : yesNo);
       };
 
         switch (type) {
           case 'CheckBox':
           case 'Radio':
+            return defn.options || defn.data_type === 'Boolean';
+
           case 'Select':
-            return !(!defn.options && defn.data_type !== 'Boolean');
+            return defn.options || defn.data_type === 'Boolean' || defn.input_type === 'Date';
+
+          case 'Date':
+            return defn.input_type === 'Date';
 
           case 'TextArea':
           case 'RichTextEditor':
             return (defn.data_type === 'Text' || defn.data_type === 'String');
+
+          case 'ChainSelect':
+            return defn.input_type === 'ChainSelect';
+
+          default:
+            return true;
         }
-        return true;
       };
 
       // Returns a value from either the local field defn or the base defn
index a25a3a4c37f0bdafad40bda5369ce1aa6e77e15b..7ac941fedfc29a069c3d7150b66afd6dfa739128 100644 (file)
@@ -113,6 +113,12 @@ class AfformMetadataInjector {
       }
 
       $fieldDefn = $existingFieldDefn ? \CRM_Utils_JS::getRawProps($existingFieldDefn) : [];
+
+      if ('Date' === $fieldInfo['input_type'] && !empty($fieldDefn['input_type']) && \CRM_Utils_JS::decode($fieldDefn['input_type']) === 'Select') {
+        $fieldInfo['input_attrs']['placeholder'] = ts('Select');
+        $fieldInfo['options'] = \CRM_Utils_Array::makeNonAssociative(\CRM_Core_OptionGroup::values('relative_date_filters'), 'id', 'label');
+      }
+
       foreach ($fieldInfo as $name => $prop) {
         // Merge array props 1 level deep
         if (in_array($name, $deep) && !empty($fieldDefn[$name])) {