From a4321c5db9c2c707f9182c24c1209bffa04d75bb Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 2 Mar 2021 15:37:16 -0500 Subject: [PATCH 1/2] SearchKit - Take search filters from the url when viewing a standalone searchDisplay This passes through all query params from the url fragment as search filters to the display. --- ext/search/Civi/Search/Display.php | 2 +- ext/search/ang/crmSearchPage.module.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ext/search/Civi/Search/Display.php b/ext/search/Civi/Search/Display.php index 1e784ea38a7d..302164de0663 100644 --- a/ext/search/Civi/Search/Display.php +++ b/ext/search/Civi/Search/Display.php @@ -24,7 +24,7 @@ public static function getPartials($moduleName, $module) { $partials = []; foreach (self::getDisplayTypes(['id', 'name']) as $type) { $partials["~/$moduleName/displayType/{$type['id']}.html"] = - '<' . $type['name'] . ' api-entity="{{:: $ctrl.apiEntity }}" search="$ctrl.searchName" display="$ctrl.display.name" settings="$ctrl.display.settings">'; + '<' . $type['name'] . ' api-entity="{{:: $ctrl.apiEntity }}" search="$ctrl.searchName" display="$ctrl.display.name" settings="$ctrl.display.settings" filters="$ctrl.filters">'; } return $partials; } diff --git a/ext/search/ang/crmSearchPage.module.js b/ext/search/ang/crmSearchPage.module.js index 42e429e85e33..6a1947395497 100644 --- a/ext/search/ang/crmSearchPage.module.js +++ b/ext/search/ang/crmSearchPage.module.js @@ -25,11 +25,15 @@ }) // Controller for displaying a search - .controller('crmSearchPageDisplay', function($scope, $routeParams, $location, display) { + .controller('crmSearchPageDisplay', function($scope, $location, display) { + var ctrl = $scope.$ctrl = this; this.display = display; this.searchName = display['saved_search.name']; this.apiEntity = display['saved_search.api_entity']; - $scope.$ctrl = this; + + $scope.$watch(function() {return $location.search();}, function(params) { + ctrl.filters = params; + }); }); })(angular, CRM.$, CRM._); From 2f41f0fa5b236c11b966df159183120cc310c54e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 4 Mar 2021 12:58:15 -0500 Subject: [PATCH 2/2] SearchKit - Allow variations of field suffix in display filters --- ext/search/Civi/Api4/Action/SearchDisplay/Run.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ext/search/Civi/Api4/Action/SearchDisplay/Run.php b/ext/search/Civi/Api4/Action/SearchDisplay/Run.php index 875b10652728..9a890b6aa882 100644 --- a/ext/search/Civi/Api4/Action/SearchDisplay/Run.php +++ b/ext/search/Civi/Api4/Action/SearchDisplay/Run.php @@ -237,13 +237,22 @@ private function getOrderByFromSort() { } /** - * Returns an array of field names or aliases from the SELECT clause + * Returns an array of field names or aliases + allowed suffixes from the SELECT clause * @return string[] */ private function getSelectAliases() { - return array_map(function($select) { + $result = []; + $selectAliases = array_map(function($select) { return array_slice(explode(' AS ', $select), -1)[0]; }, $this->savedSearch['api_params']['select']); + foreach ($selectAliases as $alias) { + [$alias] = explode(':', $alias); + $result[] = $alias; + foreach (['name', 'label', 'abbr'] as $allowedSuffix) { + $result[] = $alias . ':' . $allowedSuffix; + } + } + return $result; } /**