Commits
lotte authored 7c39bf4b5f1
1 1 | import { Component, Input, OnInit } from '@angular/core'; |
2 2 | import { Observable } from 'rxjs'; |
3 - | import { Params } from '@angular/router'; |
3 + | import { Params, Router } from '@angular/router'; |
4 4 | import { map } from 'rxjs/operators'; |
5 5 | import { hasValue, isNotEmpty } from '../../../empty.util'; |
6 6 | import { SearchService } from '../../../../core/shared/search/search.service'; |
7 + | import { currentPath } from '../../../utils/route.utils'; |
7 8 | |
8 9 | @Component({ |
9 10 | selector: 'ds-search-label', |
10 11 | templateUrl: './search-label.component.html', |
11 12 | }) |
12 13 | |
13 14 | /** |
14 15 | * Component that represents the label containing the currently active filters |
15 16 | */ |
16 17 | export class SearchLabelComponent implements OnInit { |
17 18 | @Input() key: string; |
18 19 | @Input() value: string; |
19 20 | @Input() inPlaceSearch: boolean; |
20 21 | @Input() appliedFilters: Observable<Params>; |
21 22 | searchLink: string; |
22 23 | removeParameters: Observable<Params>; |
23 24 | |
24 25 | /** |
25 26 | * Initialize the instance variable |
26 27 | */ |
27 28 | constructor( |
28 - | private searchService: SearchService) { |
29 + | private searchService: SearchService, |
30 + | private router: Router) { |
29 31 | } |
30 32 | |
31 33 | ngOnInit(): void { |
32 34 | this.searchLink = this.getSearchLink(); |
33 35 | this.removeParameters = this.getRemoveParams(); |
34 36 | } |
35 37 | |
36 38 | /** |
37 39 | * Calculates the parameters that should change if a given value for the given filter would be removed from the active filters |
38 40 | * @returns {Observable<Params>} The changed filter parameters |
48 50 | }; |
49 51 | }) |
50 52 | ) |
51 53 | } |
52 54 | |
53 55 | /** |
54 56 | * @returns {string} The base path to the search page, or the current page when inPlaceSearch is true |
55 57 | */ |
56 58 | private getSearchLink(): string { |
57 59 | if (this.inPlaceSearch) { |
58 - | return './'; |
60 + | return currentPath(this.router); |
59 61 | } |
60 62 | return this.searchService.getSearchLink(); |
61 63 | } |
62 64 | |
63 65 | /** |
64 66 | * TODO to review after https://github.com/DSpace/dspace-angular/issues/368 is resolved |
65 67 | * Strips authority operator from filter value |
66 68 | * e.g. 'test ,authority' => 'test' |
67 69 | * |
68 70 | * @param value |