Skip to content

Commit ca43885

Browse files
aliaksandr.kryvasheyeuAndrea Barbasso
authored andcommitted
Merged in DSC-1385-add-configuration-name-to-i-18-n-labels-for-facet-search-filters (pull request DSpace#1036)
DSC-1385 add configuration name to i 18 n labels for facet search filters Approved-by: Andrea Barbasso
2 parents 7808451 + e71f32c commit ca43885

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
[routerLink]="[searchLink]"
44
[queryParams]="addQueryParams" queryParamsHandling="merge">
55
<label class="mb-0 d-flex w-100">
6-
<input type="checkbox" [checked]="false" class="my-1 align-self-stretch filter-checkbox"/>
6+
<input type="checkbox" [checked]="false" class="my-1 align-self-stretch"/>
77
<span class="w-100 pl-1 break-facet">
8-
<span class="float-right badge badge-secondary badge-pill mt-1 ml-1">{{filterValue.count | dsShortNumber}}</span>
9-
{{ 'search.filters.' + filterConfig.name + '.' + filterValue.value | translate: {default: filterValue.value} }}
8+
{{ labelTranslation | dsCapitalize}}
9+
({{filterValue.count}})
1010
</span>
1111
</label>
1212

src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
33
import { FormsModule } from '@angular/forms';
44
import { By } from '@angular/platform-browser';
55
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
6-
import { Router } from '@angular/router';
6+
import { ActivatedRoute, Router } from '@angular/router';
77
import { TranslateModule } from '@ngx-translate/core';
88
import { of as observableOf } from 'rxjs';
99
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
@@ -19,6 +19,8 @@ import { PaginationComponentOptions } from '../../../../../pagination/pagination
1919
import { PaginationService } from '../../../../../../core/pagination/pagination.service';
2020
import { PaginationServiceStub } from '../../../../../testing/pagination-service.stub';
2121
import { ShortNumberPipe } from '../../../../../utils/short-number.pipe';
22+
import { MockActivatedRoute } from '../../../../../mocks/active-router.mock';
23+
import { CapitalizePipe } from '../../../../../utils/capitalize.pipe';
2224

2325
describe('SearchFacetOptionComponent', () => {
2426
let comp: SearchFacetOptionComponent;
@@ -90,9 +92,10 @@ describe('SearchFacetOptionComponent', () => {
9092
beforeEach(waitForAsync(() => {
9193
TestBed.configureTestingModule({
9294
imports: [TranslateModule.forRoot(), NoopAnimationsModule, FormsModule],
93-
declarations: [SearchFacetOptionComponent, ShortNumberPipe],
95+
declarations: [SearchFacetOptionComponent, ShortNumberPipe, CapitalizePipe],
9496
providers: [
9597
{ provide: SearchService, useValue: new SearchServiceStub(searchLink) },
98+
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
9699
{ provide: Router, useValue: new RouterStub() },
97100
{ provide: PaginationService, useValue: paginationService },
98101
{

src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
22
import { map } from 'rxjs/operators';
33
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
4-
import { Router } from '@angular/router';
4+
import { ActivatedRoute, Router } from '@angular/router';
55
import { FacetValue } from '../../../../models/facet-value.model';
66
import { SearchFilterConfig } from '../../../../models/search-filter-config.model';
77
import { SearchService } from '../../../../../../core/shared/search/search.service';
@@ -11,6 +11,7 @@ import { hasValue } from '../../../../../empty.util';
1111
import { currentPath } from '../../../../../utils/route.utils';
1212
import { getFacetValueForType } from '../../../../search.utils';
1313
import { PaginationService } from '../../../../../../core/pagination/pagination.service';
14+
import { TranslateService } from '@ngx-translate/core';
1415

1516
@Component({
1617
selector: 'ds-search-facet-option',
@@ -63,18 +64,27 @@ export class SearchFacetOptionComponent implements OnInit, OnDestroy {
6364

6465
paginationId: string;
6566

67+
configuration: string;
68+
labelTranslation: string;
69+
6670
constructor(protected searchService: SearchService,
6771
protected filterService: SearchFilterService,
6872
protected searchConfigService: SearchConfigurationService,
6973
protected router: Router,
70-
protected paginationService: PaginationService
74+
protected activatedRoute: ActivatedRoute,
75+
protected paginationService: PaginationService,
76+
protected translateService: TranslateService
7177
) {
7278
}
7379

7480
/**
7581
* Initializes all observable instance variables and starts listening to them
7682
*/
7783
ngOnInit(): void {
84+
this.configuration = this.activatedRoute?.snapshot?.queryParams?.configuration;
85+
86+
this.handleTranslation();
87+
7888
this.paginationId = this.searchConfigService.paginationID;
7989
this.searchLink = this.getSearchLink();
8090
this.isVisible = this.isChecked().pipe(map((checked: boolean) => !checked));
@@ -84,6 +94,27 @@ export class SearchFacetOptionComponent implements OnInit, OnDestroy {
8494
});
8595
}
8696

97+
/**
98+
* Handles translation of the label
99+
*/
100+
handleTranslation() {
101+
let translation = '';
102+
const labelWithConfiguration = `search.filters.${this.configuration}.${this.filterConfig.name}.${this.filterValue.value}`;
103+
104+
translation = this.translateService.instant(labelWithConfiguration);
105+
if (translation !== labelWithConfiguration) {
106+
this.labelTranslation = translation;
107+
} else {
108+
const labelWithoutConfiguration = `search.filters.${this.filterConfig.name}.${this.filterValue.value}`;
109+
translation = this.translateService.instant(labelWithoutConfiguration);
110+
if (translation !== labelWithoutConfiguration) {
111+
this.labelTranslation = translation;
112+
} else {
113+
this.labelTranslation = this.filterValue.value;
114+
}
115+
}
116+
}
117+
87118
/**
88119
* Checks if a value for this filter is currently active
89120
*/

0 commit comments

Comments
 (0)