Skip to content

Commit

Permalink
Merge pull request #22356 from colemanw/searchKitLinks
Browse files Browse the repository at this point in the history
SearchKit - Allow aggregate columns to be links
  • Loading branch information
colemanw authored Jan 4, 2022
2 parents c5321bd + 20a03eb commit ed5524a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@
return arg.field && arg.field.type !== 'Pseudo';
};

// Aggregate functions (COUNT, AVG, MAX) cannot display as links, except for GROUP_CONCAT
// Aggregate functions (COUNT, AVG, MAX) cannot autogenerate links, except for GROUP_CONCAT
// which gets special treatment in APIv4 to convert it to an array.
this.canBeLink = function(col) {
var expr = ctrl.getExprFromSelect(col.key),
function canUseLinks(colKey) {
var expr = ctrl.getExprFromSelect(colKey),
info = searchMeta.parseExpr(expr);
return !info.fn || info.fn.category !== 'aggregate' || info.fn.name === 'GROUP_CONCAT';
};
}

var linkProps = ['path', 'entity', 'action', 'join', 'target'];

Expand Down Expand Up @@ -237,11 +237,14 @@

this.getLinks = function(columnKey) {
if (!ctrl.links) {
ctrl.links = {'*': ctrl.crmSearchAdmin.buildLinks()};
ctrl.links = {'*': ctrl.crmSearchAdmin.buildLinks(), '0': []};
}
if (!columnKey) {
return ctrl.links['*'];
}
if (!canUseLinks(columnKey)) {
return ctrl.links['0'];
}
var expr = ctrl.getExprFromSelect(columnKey),
info = searchMeta.parseExpr(expr),
joinEntity = searchMeta.getJoinEntity(info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{:: ts('Image') }}
</label>
</div>
<div class="form-inline crm-search-admin-flex-row" ng-if=":: $ctrl.parent.canBeLink(col)">
<div class="form-inline crm-search-admin-flex-row" >
<label title="{{:: ts('Display as clickable link') }}" >
<input type="checkbox" ng-checked="col.link" ng-click="$ctrl.parent.toggleLink(col)" >
{{:: ts('Link') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<crm-search-admin-token-select api-entity="$ctrl.apiEntity" api-params="$ctrl.apiParams" model="col.image" field="alt"></crm-search-admin-token-select>
</div>
</div>
<div class="form-inline crm-search-admin-flex-row" ng-if=":: $ctrl.parent.canBeLink(col)">
<div class="form-inline crm-search-admin-flex-row" >
<label title="{{:: ts('Display as clickable link') }}" >
<input type="checkbox" ng-checked="col.link" ng-click="$ctrl.parent.toggleLink(col)" >
{{:: ts('Link') }}
Expand Down

0 comments on commit ed5524a

Please sign in to comment.