diff --git a/src/app/+search-page/search-service/search-configuration.service.ts b/src/app/+search-page/search-service/search-configuration.service.ts index b4c06e83f3..edd30ac383 100644 --- a/src/app/+search-page/search-service/search-configuration.service.ts +++ b/src/app/+search-page/search-service/search-configuration.service.ts @@ -13,6 +13,7 @@ import { Subscription } from 'rxjs/Subscription'; import { getSucceededRemoteData } from '../../core/shared/operators'; import { SearchFilter } from '../search-filter.model'; import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model'; +import { SearchFixedFilterService } from '../search-filters/search-filter/search-fixed-filter.service'; /** * Service that performs all actions that have to do with the current search configuration @@ -69,6 +70,7 @@ export class SearchConfigurationService implements OnDestroy { * @param {ActivatedRoute} route */ constructor(private routeService: RouteService, + private fixedFilterService: SearchFixedFilterService, private route: ActivatedRoute) { this.defaults .pipe(getSucceededRemoteData()) @@ -166,6 +168,14 @@ export class SearchConfigurationService implements OnDestroy { }); } + /** + * @returns {Observable} Emits the current fixed filter as a string + */ + getCurrentFixedFilter(): Observable { + const fixedFilter: Observable = this.routeService.getRouteParameterValue('filter'); + return fixedFilter.flatMap((f) => this.fixedFilterService.getQueryByFilterName(f)); + } + /** * @returns {Observable} Emits the current active filters with their values as they are displayed in the frontend URL */ @@ -183,7 +193,8 @@ export class SearchConfigurationService implements OnDestroy { this.getScopePart(defaults.scope), this.getQueryPart(defaults.query), this.getDSOTypePart(), - this.getFiltersPart() + this.getFiltersPart(), + this.getFixedFilterPart() ).subscribe((update) => { const currentValue: SearchOptions = this.searchOptions.getValue(); const updatedValue: SearchOptions = Object.assign(currentValue, update); @@ -203,7 +214,8 @@ export class SearchConfigurationService implements OnDestroy { this.getScopePart(defaults.scope), this.getQueryPart(defaults.query), this.getDSOTypePart(), - this.getFiltersPart() + this.getFiltersPart(), + this.getFixedFilterPart() ).subscribe((update) => { const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue(); const updatedValue: PaginatedSearchOptions = Object.assign(currentValue, update); @@ -289,4 +301,13 @@ export class SearchConfigurationService implements OnDestroy { return { filters } }); } + + /** + * @returns {Observable} Emits the current fixed filter as a partial SearchOptions object + */ + private getFixedFilterPart(): Observable { + return this.getCurrentFixedFilter().map((fixedFilter) => { + return { fixedFilter } + }); + } } diff --git a/src/app/shared/services/route.service.ts b/src/app/shared/services/route.service.ts index f374f63432..d008c11c43 100644 --- a/src/app/shared/services/route.service.ts +++ b/src/app/shared/services/route.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; -import { ActivatedRoute, NavigationEnd, Params, Router, } from '@angular/router'; -import { filter } from 'rxjs/operators'; +import { ActivatedRoute, ActivationEnd, NavigationEnd, Params, Router, } from '@angular/router'; +import { filter, flatMap, map } from 'rxjs/operators'; @Injectable() export class RouteService { @@ -13,19 +13,19 @@ export class RouteService { } getQueryParameterValues(paramName: string): Observable { - return this.route.queryParamMap.map((map) => [...map.getAll(paramName)]).distinctUntilChanged(); + return this.route.queryParamMap.map((paramMap) => [...paramMap.getAll(paramName)]).distinctUntilChanged(); } getQueryParameterValue(paramName: string): Observable { - return this.route.queryParamMap.map((map) => map.get(paramName)).distinctUntilChanged(); + return this.route.queryParamMap.map((paramMap) => paramMap.get(paramName)).distinctUntilChanged(); } hasQueryParam(paramName: string): Observable { - return this.route.queryParamMap.map((map) => map.has(paramName)).distinctUntilChanged(); + return this.route.queryParamMap.map((paramMap) => paramMap.has(paramName)).distinctUntilChanged(); } hasQueryParamWithValue(paramName: string, paramValue: string): Observable { - return this.route.queryParamMap.map((map) => map.getAll(paramName).indexOf(paramValue) > -1).distinctUntilChanged(); + return this.route.queryParamMap.map((paramMap) => paramMap.getAll(paramName).indexOf(paramValue) > -1).distinctUntilChanged(); } getRouteParameterValue(paramName: string): Observable { @@ -38,26 +38,26 @@ export class RouteService { getQueryParamsWithPrefix(prefix: string): Observable { return this.route.queryParamMap - .map((map) => { + .map((paramMap) => { const params = {}; - map.keys + paramMap.keys .filter((key) => key.startsWith(prefix)) .forEach((key) => { - params[key] = [...map.getAll(key)]; + params[key] = [...paramMap.getAll(key)]; }); return params; }).distinctUntilChanged(); } subscribeToRouterParams() { - this.router.events.pipe( - filter((event) => event instanceof NavigationEnd)) - .subscribe(() => { + this.params = this.router.events.pipe( + flatMap((event) => { let active = this.route; while (active.firstChild) { active = active.firstChild; } - this.params = active.params; - }); + return active.params; + }) + ); } }