Skip to content

Commit

Permalink
Facet / Add meta property to customize label.
Browse files Browse the repository at this point in the history
Add also documentation on how to configure labels when the key used for
the facet is not known.
  • Loading branch information
fxprunayre committed Dec 6, 2024
1 parent 1b6d0fb commit 211b0f5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ When using a generic field like `tag.default` and including only a subset of key
},
```
To translate the label `IDP_TOPICS`, 2 options:
* Use the translation API to add your custom translation in the database for the facet key `facet-IDP_TOPICS` (see the Admin console --> Settings --> Languages).
* Or declare a meta property `labels` in the facet configuration:
``` js
"IDP_TOPICS": {
"terms": {
...
"meta": {
"labels": {
"eng": "IDP topics",
"fre": "Thèmes IDP"
},
```
## Decorate aggregations {#configuring-facet-decorator}
All aggregations can be decorated by an icon or an image in the home page or in other pages. The decorator is configured in the `meta` properties of the facet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@
}
]);

module.service("gnFacetMetaLabel", [
"$translate",
function ($translate) {
this.getFacetLabel = function (facet) {
if (!facet || !facet.meta || !facet.meta.labels) {
return null;
}
var currentLang = $translate.use();
return facet.meta.labels[currentLang] || null;
};
}
]);

module.filter("facetTooltip", [
"$translate",
"$filter",
Expand Down Expand Up @@ -266,7 +279,8 @@
module.directive("esFacets", [
"gnFacetSorter",
"gnSearchSettings",
function (gnFacetSorter, gnSearchSettings) {
"gnFacetMetaLabel",
function (gnFacetSorter, gnSearchSettings, gnFacetMetaLabel) {
return {
restrict: "A",
controllerAs: "ctrl",
Expand All @@ -291,6 +305,7 @@
// Directive tab field property
scope.isTabMode = scope.ctrl.tabField !== undefined;
scope.facetSorter = gnFacetSorter.sortByTranslation;
scope.getFacetLabel = gnFacetMetaLabel.getFacetLabel;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
gn-collapsible="::ctrl.fLvlCollapse[facet.key]"
>
<span class="flex-shrink text-ellipsis"
>{{('facet-' + facet.key) | facetKeyTranslator}}</span
>{{getFacetLabel(facet) || (('facet-' + facet.key) | facetKeyTranslator)}}</span
>
<span
class="fa fa-fw"
Expand Down
6 changes: 5 additions & 1 deletion web-ui/src/main/resources/catalog/js/CatController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,7 @@
"gnExternalViewer",
"gnAlertService",
"gnESFacet",
"gnFacetMetaLabel",
function (
$scope,
$http,
Expand All @@ -1628,7 +1629,8 @@
$cookies,
gnExternalViewer,
gnAlertService,
gnESFacet
gnESFacet,
gnFacetMetaLabel
) {
$scope.version = "0.0.1";
var defaultNode = "srv";
Expand Down Expand Up @@ -1753,6 +1755,8 @@
$scope.isExternalViewerEnabled = gnExternalViewer.isEnabled();
$scope.externalViewerUrl = gnExternalViewer.getBaseUrl();
$scope.publicationOptions = [];
$scope.getFacetLabel = gnFacetMetaLabel.getFacetLabel;


$http.get("../api/records/sharing/options").then(function (response) {
$scope.publicationOptions = response.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ <h1 class="col-md-12">
data-ng-model="homeFacet.key"
data-ng-value="facetKey"
/>
<span data-translate="">{{::('facet-' + facetKey) | facetKeyTranslator}}</span
<span data-translate="">{{::getFacetLabel(agg) || (('facet-' + facetKey) | facetKeyTranslator)}}</span
>&nbsp;
</label>
</div>
Expand All @@ -157,7 +157,7 @@ <h1 class="col-md-12">
<div data-ng-show="searchInfo.aggregations[homeFacet.lastKey].buckets.length > 0">
<div class="row">
<h1 class="col-md-12" data-translate="">
{{('facet-' + homeFacet.lastKey) | facetKeyTranslator}}
{{getFacetLabel(searchInfo.aggregations[homeFacet.lastKey]) || (('facet-' + homeFacet.lastKey) | facetKeyTranslator)}}
</h1>
</div>
<div class="row">
Expand Down

0 comments on commit 211b0f5

Please sign in to comment.