mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 06:53:03 +00:00
55647: FixedFilter fixed
This commit is contained in:
@@ -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 }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -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<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;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user