diff --git a/resources/i18n/en.json b/resources/i18n/en.json index 5e30d08ed0..afd1c48e94 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -145,6 +145,24 @@ } }, "search": { + "journal": { + "title": "DSpace Angular :: Journal Search", + "results": { + "head": "Journal Search Results" + } + }, + "person": { + "title": "DSpace Angular :: Person Search", + "results": { + "head": "Person Search Results" + } + }, + "publication": { + "title": "DSpace Angular :: Publication Search", + "results": { + "head": "Publication Search Results" + } + }, "title": "DSpace Angular :: Search", "description": "", "form": { diff --git a/src/app/+search-page/filtered-search-page.guard.ts b/src/app/+search-page/filtered-search-page.guard.ts new file mode 100644 index 0000000000..7d022b81da --- /dev/null +++ b/src/app/+search-page/filtered-search-page.guard.ts @@ -0,0 +1,18 @@ +import { Injectable } from '@angular/core'; +import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; + +@Injectable() + +export class FilteredSearchPageGuard implements CanActivate { + canActivate( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot): Observable | Promise | boolean { + const filter = route.params.filter; + + const newTitle = route.data.title + filter + '.title'; + + route.data = { title: newTitle }; + return true; + } +} diff --git a/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts b/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts index 26eb961c53..6a112fef1c 100644 --- a/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts +++ b/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts @@ -10,6 +10,7 @@ import { import { SearchFiltersState } from './search-filter.reducer'; import { SearchFilterConfig } from '../../search-service/search-filter-config.model'; import { FilterType } from '../../search-service/filter-type.model'; +import { SearchFixedFilterService } from './search-fixed-filter.service'; describe('SearchFilterService', () => { let service: SearchFilterService; @@ -21,6 +22,12 @@ describe('SearchFilterService', () => { isOpenByDefault: false, pageSize: 2 }); + + const mockFixedFilterService: SearchFixedFilterService = { + getQueryByFilterName: (filter: string) => { + return Observable.of(undefined) + } + } as SearchFixedFilterService const value1 = 'random value'; // const value2 = 'another value'; const store: Store = jasmine.createSpyObj('store', { @@ -50,7 +57,7 @@ describe('SearchFilterService', () => { }; beforeEach(() => { - service = new SearchFilterService(store, routeServiceStub); + service = new SearchFilterService(store, routeServiceStub, mockFixedFilterService); }); describe('when the initialCollapse method is triggered', () => { diff --git a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts index 252e4b101e..fe46417e59 100644 --- a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts +++ b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts @@ -12,6 +12,7 @@ import { ResponseParsingService } from '../../../core/data/parsing.service'; import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { FilteredDiscoveryPageResponseParsingService } from '../../../core/data/filtered-discovery-page-response-parsing.service'; import { hasValue } from '../../../shared/empty.util'; +import { configureRequest } from '../../../core/shared/operators'; @Injectable() export class SearchFixedFilterService { @@ -30,12 +31,14 @@ export class SearchFixedFilterService { map((url: string) => { url += ('/' + filterName); const request = new GetRequest(this.requestService.generateRequestId(), url); + console.log(url); return Object.assign(request, { getResponseParser(): GenericConstructor { return FilteredDiscoveryPageResponseParsingService; } }); }), + configureRequest(this.requestService) ); const responseCacheObs = requestObs.pipe( diff --git a/src/app/+search-page/search-page-routing.module.ts b/src/app/+search-page/search-page-routing.module.ts index 84cb0c31bb..8c138c0d52 100644 --- a/src/app/+search-page/search-page-routing.module.ts +++ b/src/app/+search-page/search-page-routing.module.ts @@ -3,12 +3,13 @@ import { RouterModule } from '@angular/router'; import { SearchPageComponent } from './search-page.component'; import { FilteredSearchPageComponent } from './filtered-search-page.component'; +import { FilteredSearchPageGuard } from './filtered-search-page.guard'; @NgModule({ imports: [ RouterModule.forChild([ { path: '', component: SearchPageComponent, data: { title: 'search.title' } }, - { path: ':filter', component: FilteredSearchPageComponent, data: { title: 'search.title.:filter' } } + { path: ':filter', component: FilteredSearchPageComponent, canActivate: [FilteredSearchPageGuard], data: { title: 'search.' }} ]) ] }) diff --git a/src/app/+search-page/search-page.component.html b/src/app/+search-page/search-page.component.html index 1a1f379920..478403388e 100644 --- a/src/app/+search-page/search-page.component.html +++ b/src/app/+search-page/search-page.component.html @@ -30,7 +30,7 @@ + [searchConfig]="searchOptions$ | async" [sortConfig]="sortConfig" [fixedFilter]="fixedFilter | async"> diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index b38386d44c..e347688072 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -47,7 +47,7 @@ export class SearchPageComponent implements OnInit { query: '', scope: '' }; - title; + fixedFilter; constructor(protected service: SearchService, protected communityService: CommunityDataService, @@ -68,6 +68,7 @@ export class SearchPageComponent implements OnInit { this.resultsRD$ = this.searchOptions$.pipe( flatMap((searchOptions) => this.service.search(searchOptions)) ); + this.fixedFilter = this.routeService.getRouteParameterValue('filter'); } public closeSidebar(): void { diff --git a/src/app/+search-page/search-page.module.ts b/src/app/+search-page/search-page.module.ts index 206d18267d..25d4b561c3 100644 --- a/src/app/+search-page/search-page.module.ts +++ b/src/app/+search-page/search-page.module.ts @@ -23,6 +23,7 @@ import { SearchFacetFilterComponent } from './search-filters/search-filter/searc import { SearchFilterService } from './search-filters/search-filter/search-filter.service'; import { FilteredSearchPageComponent } from './filtered-search-page.component'; import { SearchFixedFilterService } from './search-filters/search-filter/search-fixed-filter.service'; +import { FilteredSearchPageGuard } from './filtered-search-page.guard'; const effects = [ SearchSidebarEffects @@ -57,7 +58,8 @@ const effects = [ SearchService, SearchSidebarService, SearchFilterService, - SearchFixedFilterService + SearchFixedFilterService, + FilteredSearchPageGuard ], entryComponents: [ ItemSearchResultListElementComponent, diff --git a/src/app/+search-page/search-result.model.ts b/src/app/+search-page/search-result.model.ts index 2298f453e1..cc2bd8cd58 100644 --- a/src/app/+search-page/search-result.model.ts +++ b/src/app/+search-page/search-result.model.ts @@ -1,6 +1,5 @@ import { DSpaceObject } from '../core/shared/dspace-object.model'; import { Metadatum } from '../core/shared/metadatum.model'; -import { hasNoValue, isEmpty } from '../shared/empty.util'; import { ListableObject } from '../shared/object-collection/shared/listable-object.model'; export class SearchResult implements ListableObject { diff --git a/src/app/+search-page/search-results/search-results.component.html b/src/app/+search-page/search-results/search-results.component.html index ed6fc18d9c..a9b54a4601 100644 --- a/src/app/+search-page/search-results/search-results.component.html +++ b/src/app/+search-page/search-results/search-results.component.html @@ -1,4 +1,4 @@ -

{{ 'search.results.head' | translate }}

+

{{ getTitleKey() | translate }}

{ let service: RouteService; @@ -28,12 +30,15 @@ describe('RouteService', () => { queryParamMap: Observable.of(convertToParamMap(paramObject)) }, }, + { + provide: Router, useClass: RouterStub + } ] }); })); beforeEach(() => { - service = new RouteService(TestBed.get(ActivatedRoute)); + service = new RouteService(TestBed.get(ActivatedRoute), TestBed.get(Router)); }); describe('hasQueryParam', () => { diff --git a/src/app/shared/route.service.ts b/src/app/shared/route.service.ts index 3eb629e60c..f374f63432 100644 --- a/src/app/shared/route.service.ts +++ b/src/app/shared/route.service.ts @@ -1,11 +1,15 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; -import { ActivatedRoute, Params, } from '@angular/router'; +import { ActivatedRoute, NavigationEnd, Params, Router, } from '@angular/router'; +import { filter } from 'rxjs/operators'; @Injectable() export class RouteService { + params: Observable; + + constructor(private route: ActivatedRoute, private router: Router) { + this.subscribeToRouterParams(); - constructor(private route: ActivatedRoute) { } getQueryParameterValues(paramName: string): Observable { @@ -25,7 +29,7 @@ export class RouteService { } getRouteParameterValue(paramName: string): Observable { - return this.route.params.map((params) => params[paramName]).distinctUntilChanged(); + return this.params.map((params) => params[paramName]).distinctUntilChanged(); } getRouteDataValue(datafield: string): Observable { @@ -44,4 +48,16 @@ export class RouteService { return params; }).distinctUntilChanged(); } + + subscribeToRouterParams() { + this.router.events.pipe( + filter((event) => event instanceof NavigationEnd)) + .subscribe(() => { + let active = this.route; + while (active.firstChild) { + active = active.firstChild; + } + this.params = active.params; + }); + } }