SearchKit - display count in tab header if embedded in contact summary tab
authorColeman Watts <coleman@civicrm.org>
Wed, 24 Mar 2021 13:30:39 +0000 (09:30 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 6 Apr 2021 23:21:13 +0000 (19:21 -0400)
ext/search/ang/crmSearchDisplay.module.js
ext/search/ang/crmSearchDisplayList/crmSearchDisplayList.component.js
ext/search/ang/crmSearchDisplayTable/crmSearchDisplayTable.component.js

index 1a27992c4a5edc767bdb64fc03a0d828c6aef62b..8c08cffa0ed09d56af3bba16f7215ae4c91c9a89 100644 (file)
         return crmApi4('SearchDisplay', 'run', getApiParams(ctrl)).then(function(results) {
           ctrl.results = results;
           ctrl.editing = false;
-          if (ctrl.settings.pager && !ctrl.rowCount) {
-            if (results.length < ctrl.settings.limit) {
+          if (!ctrl.rowCount) {
+            if (!ctrl.settings.limit || results.length < ctrl.settings.limit) {
               ctrl.rowCount = results.length;
-            } else {
+            } else if (ctrl.settings.pager) {
               var params = getApiParams(ctrl, 'row_count');
               crmApi4('SearchDisplay', 'run', params).then(function(result) {
                 ctrl.rowCount = result.count;
index 2153e6dc1e920caa8ce802c28a0983f50c321173..fa2d9ea6bbeadb910461139c6f8bcc6c1cbdf46f 100644 (file)
@@ -14,7 +14,7 @@
       afFieldset: '?^^afFieldset'
     },
     templateUrl: '~/crmSearchDisplayList/crmSearchDisplayList.html',
-    controller: function($scope, crmApi4, searchDisplayUtils) {
+    controller: function($scope, $element, crmApi4, searchDisplayUtils) {
       var ts = $scope.ts = CRM.ts('org.civicrm.search'),
         ctrl = this;
 
         this.sort = this.settings.sort ? _.cloneDeep(this.settings.sort) : [];
         $scope.displayUtils = searchDisplayUtils;
 
+        // If search is embedded in contact summary tab, display count in tab-header
+        var contactTab = $element.closest('.crm-contact-page .ui-tabs-panel').attr('id');
+        if (contactTab) {
+          var unwatchCount = $scope.$watch('$ctrl.rowCount', function(rowCount) {
+            if (typeof rowCount === 'number') {
+              unwatchCount();
+              CRM.tabHeader.updateCount(contactTab.replace('contact-', '#tab_'), rowCount);
+            }
+          });
+        }
+
         if (this.afFieldset) {
           $scope.$watch(this.afFieldset.getFieldData, onChangeFilters, true);
         }
index dfc029ab5f63cd09f1e7a40cbd4908699e26bfb2..9b4b9f18ee7697f9db8b02cd969c095a849c2d2c 100644 (file)
@@ -13,7 +13,7 @@
       afFieldset: '?^^afFieldset'
     },
     templateUrl: '~/crmSearchDisplayTable/crmSearchDisplayTable.html',
-    controller: function($scope, crmApi4, searchDisplayUtils) {
+    controller: function($scope, $element, crmApi4, searchDisplayUtils) {
       var ts = $scope.ts = CRM.ts('org.civicrm.search'),
         ctrl = this;
 
         this.sort = this.settings.sort ? _.cloneDeep(this.settings.sort) : [];
         $scope.displayUtils = searchDisplayUtils;
 
+        // If search is embedded in contact summary tab, display count in tab-header
+        var contactTab = $element.closest('.crm-contact-page .ui-tabs-panel').attr('id');
+        if (contactTab) {
+          var unwatchCount = $scope.$watch('$ctrl.rowCount', function(rowCount) {
+            if (typeof rowCount === 'number') {
+              unwatchCount();
+              CRM.tabHeader.updateCount(contactTab.replace('contact-', '#tab_'), rowCount);
+            }
+          });
+        }
+
         if (this.afFieldset) {
           $scope.$watch(this.afFieldset.getFieldData, onChangeFilters, true);
         }