From: Coleman Watts Date: Wed, 24 Mar 2021 13:30:39 +0000 (-0400) Subject: SearchKit - display count in tab header if embedded in contact summary tab X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=54a03b7b04997e805cce6b797ec880ab6e4bdeda;p=civicrm-core.git SearchKit - display count in tab header if embedded in contact summary tab --- diff --git a/ext/search/ang/crmSearchDisplay.module.js b/ext/search/ang/crmSearchDisplay.module.js index 1a27992c4a..8c08cffa0e 100644 --- a/ext/search/ang/crmSearchDisplay.module.js +++ b/ext/search/ang/crmSearchDisplay.module.js @@ -81,10 +81,10 @@ 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; diff --git a/ext/search/ang/crmSearchDisplayList/crmSearchDisplayList.component.js b/ext/search/ang/crmSearchDisplayList/crmSearchDisplayList.component.js index 2153e6dc1e..fa2d9ea6bb 100644 --- a/ext/search/ang/crmSearchDisplayList/crmSearchDisplayList.component.js +++ b/ext/search/ang/crmSearchDisplayList/crmSearchDisplayList.component.js @@ -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; @@ -25,6 +25,17 @@ 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); } diff --git a/ext/search/ang/crmSearchDisplayTable/crmSearchDisplayTable.component.js b/ext/search/ang/crmSearchDisplayTable/crmSearchDisplayTable.component.js index dfc029ab5f..9b4b9f18ee 100644 --- a/ext/search/ang/crmSearchDisplayTable/crmSearchDisplayTable.component.js +++ b/ext/search/ang/crmSearchDisplayTable/crmSearchDisplayTable.component.js @@ -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; @@ -26,6 +26,17 @@ 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); }