Skip to content
Snippets Groups Projects
Commit 8e3e826a authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

55647: FixedFilter fixed

parent d8ce01b2
No related branches found
No related tags found
No related merge requests found
......@@ -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<string>} Emits the current fixed filter as a string
*/
getCurrentFixedFilter(): Observable<string> {
const fixedFilter: Observable<string> = this.routeService.getRouteParameterValue('filter');
return fixedFilter.flatMap((f) => this.fixedFilterService.getQueryByFilterName(f));
}
/**
* @returns {Observable<Params>} 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<string>} Emits the current fixed filter as a partial SearchOptions object
*/
private getFixedFilterPart(): Observable<any> {
return this.getCurrentFixedFilter().map((fixedFilter) => {
return { fixedFilter }
});
}
}
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<string[]> {
return this.route.queryParamMap.map((map) => [...map.getAll(paramName)]).distinctUntilChanged();
return this.route.queryParamMap.map((paramMap) => [...paramMap.getAll(paramName)]).distinctUntilChanged();
}
getQueryParameterValue(paramName: string): Observable<string> {
return this.route.queryParamMap.map((map) => map.get(paramName)).distinctUntilChanged();
return this.route.queryParamMap.map((paramMap) => paramMap.get(paramName)).distinctUntilChanged();
}
hasQueryParam(paramName: string): Observable<boolean> {
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<boolean> {
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<string> {
......@@ -38,26 +38,26 @@ export class RouteService {
getQueryParamsWithPrefix(prefix: string): Observable<Params> {
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;
})
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment