mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +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 { getSucceededRemoteData } from '../../core/shared/operators';
|
||||||
import { SearchFilter } from '../search-filter.model';
|
import { SearchFilter } from '../search-filter.model';
|
||||||
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.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
|
* 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
|
* @param {ActivatedRoute} route
|
||||||
*/
|
*/
|
||||||
constructor(private routeService: RouteService,
|
constructor(private routeService: RouteService,
|
||||||
|
private fixedFilterService: SearchFixedFilterService,
|
||||||
private route: ActivatedRoute) {
|
private route: ActivatedRoute) {
|
||||||
this.defaults
|
this.defaults
|
||||||
.pipe(getSucceededRemoteData())
|
.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
|
* @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.getScopePart(defaults.scope),
|
||||||
this.getQueryPart(defaults.query),
|
this.getQueryPart(defaults.query),
|
||||||
this.getDSOTypePart(),
|
this.getDSOTypePart(),
|
||||||
this.getFiltersPart()
|
this.getFiltersPart(),
|
||||||
|
this.getFixedFilterPart()
|
||||||
).subscribe((update) => {
|
).subscribe((update) => {
|
||||||
const currentValue: SearchOptions = this.searchOptions.getValue();
|
const currentValue: SearchOptions = this.searchOptions.getValue();
|
||||||
const updatedValue: SearchOptions = Object.assign(currentValue, update);
|
const updatedValue: SearchOptions = Object.assign(currentValue, update);
|
||||||
@@ -203,7 +214,8 @@ export class SearchConfigurationService implements OnDestroy {
|
|||||||
this.getScopePart(defaults.scope),
|
this.getScopePart(defaults.scope),
|
||||||
this.getQueryPart(defaults.query),
|
this.getQueryPart(defaults.query),
|
||||||
this.getDSOTypePart(),
|
this.getDSOTypePart(),
|
||||||
this.getFiltersPart()
|
this.getFiltersPart(),
|
||||||
|
this.getFixedFilterPart()
|
||||||
).subscribe((update) => {
|
).subscribe((update) => {
|
||||||
const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue();
|
const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue();
|
||||||
const updatedValue: PaginatedSearchOptions = Object.assign(currentValue, update);
|
const updatedValue: PaginatedSearchOptions = Object.assign(currentValue, update);
|
||||||
@@ -289,4 +301,13 @@ export class SearchConfigurationService implements OnDestroy {
|
|||||||
return { filters }
|
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 { Injectable } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { ActivatedRoute, NavigationEnd, Params, Router, } from '@angular/router';
|
import { ActivatedRoute, ActivationEnd, NavigationEnd, Params, Router, } from '@angular/router';
|
||||||
import { filter } from 'rxjs/operators';
|
import { filter, flatMap, map } from 'rxjs/operators';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RouteService {
|
export class RouteService {
|
||||||
@@ -13,19 +13,19 @@ export class RouteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getQueryParameterValues(paramName: string): Observable<string[]> {
|
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> {
|
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> {
|
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> {
|
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> {
|
getRouteParameterValue(paramName: string): Observable<string> {
|
||||||
@@ -38,26 +38,26 @@ export class RouteService {
|
|||||||
|
|
||||||
getQueryParamsWithPrefix(prefix: string): Observable<Params> {
|
getQueryParamsWithPrefix(prefix: string): Observable<Params> {
|
||||||
return this.route.queryParamMap
|
return this.route.queryParamMap
|
||||||
.map((map) => {
|
.map((paramMap) => {
|
||||||
const params = {};
|
const params = {};
|
||||||
map.keys
|
paramMap.keys
|
||||||
.filter((key) => key.startsWith(prefix))
|
.filter((key) => key.startsWith(prefix))
|
||||||
.forEach((key) => {
|
.forEach((key) => {
|
||||||
params[key] = [...map.getAll(key)];
|
params[key] = [...paramMap.getAll(key)];
|
||||||
});
|
});
|
||||||
return params;
|
return params;
|
||||||
}).distinctUntilChanged();
|
}).distinctUntilChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToRouterParams() {
|
subscribeToRouterParams() {
|
||||||
this.router.events.pipe(
|
this.params = this.router.events.pipe(
|
||||||
filter((event) => event instanceof NavigationEnd))
|
flatMap((event) => {
|
||||||
.subscribe(() => {
|
|
||||||
let active = this.route;
|
let active = this.route;
|
||||||
while (active.firstChild) {
|
while (active.firstChild) {
|
||||||
active = active.firstChild;
|
active = active.firstChild;
|
||||||
}
|
}
|
||||||
this.params = active.params;
|
return active.params;
|
||||||
});
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user