Skip to content

Commit

Permalink
Merge pull request #19713 from colemanw/searchDisplayParams
Browse files Browse the repository at this point in the history
SearchKit - Take search filters from the url when viewing a standalone display
  • Loading branch information
colemanw authored Mar 5, 2021
2 parents 00037f1 + 2f41f0f commit 5747164
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 11 additions & 2 deletions ext/search/Civi/Api4/Action/SearchDisplay/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ext/search/Civi/Search/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] . '>';
'<' . $type['name'] . ' api-entity="{{:: $ctrl.apiEntity }}" search="$ctrl.searchName" display="$ctrl.display.name" settings="$ctrl.display.settings" filters="$ctrl.filters"></' . $type['name'] . '>';
}
return $partials;
}
Expand Down
8 changes: 6 additions & 2 deletions ext/search/ang/crmSearchPage.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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._);

0 comments on commit 5747164

Please sign in to comment.