mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
111731: Display the authority label in the search facets
This commit is contained in:
17
src/app/shared/search/models/applied-filter.model.ts
Normal file
17
src/app/shared/search/models/applied-filter.model.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { autoserialize } from 'cerialize';
|
||||||
|
|
||||||
|
export class AppliedFilter {
|
||||||
|
|
||||||
|
@autoserialize
|
||||||
|
filter: string;
|
||||||
|
|
||||||
|
@autoserialize
|
||||||
|
operator: string;
|
||||||
|
|
||||||
|
@autoserialize
|
||||||
|
value: string;
|
||||||
|
|
||||||
|
@autoserialize
|
||||||
|
label: string;
|
||||||
|
|
||||||
|
}
|
@@ -1,6 +1,8 @@
|
|||||||
import { autoserialize } from 'cerialize';
|
import { autoserialize, autoserializeAs } from 'cerialize';
|
||||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||||
|
import { AppliedFilter } from './applied-filter.model';
|
||||||
|
import { SearchResultSorting } from './search-result-sorting.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing the response returned by the server when performing a search request
|
* Class representing the response returned by the server when performing a search request
|
||||||
@@ -21,14 +23,14 @@ export abstract class SearchQueryResponse<T> extends PaginatedList<T> {
|
|||||||
/**
|
/**
|
||||||
* The currently active filters used in the search request
|
* The currently active filters used in the search request
|
||||||
*/
|
*/
|
||||||
@autoserialize
|
@autoserializeAs(AppliedFilter)
|
||||||
appliedFilters: any[]; // TODO
|
appliedFilters: AppliedFilter[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sort parameters used in the search request
|
* The sort parameters used in the search request
|
||||||
*/
|
*/
|
||||||
@autoserialize
|
@autoserializeAs(SearchResultSorting)
|
||||||
sort: any; // TODO
|
sort: SearchResultSorting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sort parameters used in the search request
|
* The sort parameters used in the search request
|
||||||
|
11
src/app/shared/search/models/search-result-sorting.model.ts
Normal file
11
src/app/shared/search/models/search-result-sorting.model.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { autoserialize } from 'cerialize';
|
||||||
|
|
||||||
|
export class SearchResultSorting {
|
||||||
|
|
||||||
|
@autoserialize
|
||||||
|
by: string;
|
||||||
|
|
||||||
|
@autoserialize
|
||||||
|
order: string;
|
||||||
|
|
||||||
|
}
|
@@ -2,14 +2,7 @@ import { animate, state, style, transition, trigger } from '@angular/animations'
|
|||||||
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
|
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import {
|
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, of as observableOf, Subject, Subscription } from 'rxjs';
|
||||||
BehaviorSubject,
|
|
||||||
combineLatest as observableCombineLatest,
|
|
||||||
Observable,
|
|
||||||
of as observableOf,
|
|
||||||
Subject,
|
|
||||||
Subscription
|
|
||||||
} from 'rxjs';
|
|
||||||
import { debounceTime, distinctUntilChanged, filter, map, mergeMap, switchMap, take, tap } from 'rxjs/operators';
|
import { debounceTime, distinctUntilChanged, filter, map, mergeMap, switchMap, take, tap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remote-data-build.service';
|
||||||
@@ -20,12 +13,7 @@ import { EmphasizePipe } from '../../../../utils/emphasize.pipe';
|
|||||||
import { FacetValue } from '../../../models/facet-value.model';
|
import { FacetValue } from '../../../models/facet-value.model';
|
||||||
import { SearchFilterConfig } from '../../../models/search-filter-config.model';
|
import { SearchFilterConfig } from '../../../models/search-filter-config.model';
|
||||||
import { SearchService } from '../../../../../core/shared/search/search.service';
|
import { SearchService } from '../../../../../core/shared/search/search.service';
|
||||||
import {
|
import { FILTER_CONFIG, IN_PLACE_SEARCH, REFRESH_FILTER, SearchFilterService } from '../../../../../core/shared/search/search-filter.service';
|
||||||
FILTER_CONFIG,
|
|
||||||
IN_PLACE_SEARCH,
|
|
||||||
REFRESH_FILTER,
|
|
||||||
SearchFilterService
|
|
||||||
} from '../../../../../core/shared/search/search-filter.service';
|
|
||||||
import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service';
|
import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service';
|
||||||
import { getFirstSucceededRemoteData } from '../../../../../core/shared/operators';
|
import { getFirstSucceededRemoteData } from '../../../../../core/shared/operators';
|
||||||
import { InputSuggestion } from '../../../../input-suggestions/input-suggestions.model';
|
import { InputSuggestion } from '../../../../input-suggestions/input-suggestions.model';
|
||||||
@@ -35,6 +23,7 @@ import { currentPath } from '../../../../utils/route.utils';
|
|||||||
import { getFacetValueForType, stripOperatorFromFilterValue } from '../../../search.utils';
|
import { getFacetValueForType, stripOperatorFromFilterValue } from '../../../search.utils';
|
||||||
import { createPendingRemoteDataObject } from '../../../../remote-data.utils';
|
import { createPendingRemoteDataObject } from '../../../../remote-data.utils';
|
||||||
import { FacetValues } from '../../../models/facet-values.model';
|
import { FacetValues } from '../../../models/facet-values.model';
|
||||||
|
import { AppliedFilter } from '../../../models/applied-filter.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-search-facet-filter',
|
selector: 'ds-search-facet-filter',
|
||||||
@@ -48,7 +37,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* Emits an array of pages with values found for this facet
|
* Emits an array of pages with values found for this facet
|
||||||
*/
|
*/
|
||||||
filterValues$: Subject<RemoteData<PaginatedList<FacetValue>[]>>;
|
filterValues$: Subject<RemoteData<FacetValues[]>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emits the current last shown page of this facet's values
|
* Emits the current last shown page of this facet's values
|
||||||
@@ -78,7 +67,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* Emits the active values for this filter
|
* Emits the active values for this filter
|
||||||
*/
|
*/
|
||||||
selectedValues$: Observable<FacetValue[]>;
|
selectedValues$: Observable<AppliedFilter[]>;
|
||||||
|
|
||||||
protected collapseNextUpdate = true;
|
protected collapseNextUpdate = true;
|
||||||
|
|
||||||
@@ -260,7 +249,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
|
|||||||
queryParams:
|
queryParams:
|
||||||
{
|
{
|
||||||
[this.filterConfig.paramName]: [
|
[this.filterConfig.paramName]: [
|
||||||
...selectedValues.map((facet) => this.getFacetValue(facet)),
|
...selectedValues.map((appliedFilter: AppliedFilter) => appliedFilter.value),
|
||||||
data
|
data
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -280,12 +269,9 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
|
|||||||
return getFacetValueForType(facet, this.filterConfig);
|
return getFacetValueForType(facet, this.filterConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected retrieveFilterValues(useCachedVersionIfAvailable = true): Observable<RemoteData<PaginatedList<FacetValue>[]>> {
|
protected retrieveFilterValues(useCachedVersionIfAvailable = true): Observable<RemoteData<FacetValues[]>> {
|
||||||
const facetValues$ = observableCombineLatest([this.searchOptions$, this.currentPage]).pipe(
|
const facetValues$: Observable<{ values: Observable<RemoteData<FacetValues>>, page: number}> = observableCombineLatest([this.searchOptions$, this.currentPage]).pipe(
|
||||||
map(([options, page]) => {
|
switchMap(([options, page]: [SearchOptions, number]) => {
|
||||||
return { options, page };
|
|
||||||
}),
|
|
||||||
switchMap(({ options, page }) => {
|
|
||||||
return this.searchService.getFacetValuesFor(this.filterConfig, page, options, null, useCachedVersionIfAvailable)
|
return this.searchService.getFacetValuesFor(this.filterConfig, page, options, null, useCachedVersionIfAvailable)
|
||||||
.pipe(
|
.pipe(
|
||||||
getFirstSucceededRemoteData(),
|
getFirstSucceededRemoteData(),
|
||||||
@@ -301,9 +287,9 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
let filterValues = [];
|
let filterValues: Observable<RemoteData<FacetValues>>[] = [];
|
||||||
return facetValues$.pipe(
|
return facetValues$.pipe(
|
||||||
mergeMap((facetOutcome) => {
|
mergeMap((facetOutcome: { values: Observable<RemoteData<FacetValues>>, page: number}) => {
|
||||||
const newValues$ = facetOutcome.values;
|
const newValues$ = facetOutcome.values;
|
||||||
|
|
||||||
if (this.collapseNextUpdate) {
|
if (this.collapseNextUpdate) {
|
||||||
@@ -319,22 +305,16 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
return this.rdbs.aggregate(filterValues);
|
return this.rdbs.aggregate(filterValues);
|
||||||
}),
|
}),
|
||||||
tap((rd: RemoteData<PaginatedList<FacetValue>[]>) => {
|
tap((rd: RemoteData<FacetValues[]>) => {
|
||||||
|
const appliedFilters: AppliedFilter[] = [].concat(...rd.payload.map((facetValues: FacetValues) => facetValues.appliedFilters))
|
||||||
|
.filter((appliedFilter: AppliedFilter) => hasValue(appliedFilter));
|
||||||
this.selectedValues$ = this.filterService.getSelectedValuesForFilter(this.filterConfig).pipe(
|
this.selectedValues$ = this.filterService.getSelectedValuesForFilter(this.filterConfig).pipe(
|
||||||
map((selectedValues) => {
|
map((selectedValues: string[]) => {
|
||||||
return selectedValues.map((value: string) => {
|
return selectedValues.map((value: string) => {
|
||||||
const fValue = [].concat(...rd.payload.map((page) => page.page))
|
return appliedFilters.find((appliedFilter: AppliedFilter) => appliedFilter.value === stripOperatorFromFilterValue(value));
|
||||||
.find((facetValue: FacetValue) => this.getFacetValue(facetValue) === value);
|
}).filter((appliedFilter: AppliedFilter) => hasValue(appliedFilter));
|
||||||
if (hasValue(fValue)) {
|
}),
|
||||||
return fValue;
|
|
||||||
}
|
|
||||||
const filterValue = stripOperatorFromFilterValue(value);
|
|
||||||
return Object.assign(new FacetValue(), { label: filterValue, value: filterValue });
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}),
|
|
||||||
tap((rd: RemoteData<PaginatedList<FacetValue>[]>) => {
|
|
||||||
this.animationState = 'ready';
|
this.animationState = 'ready';
|
||||||
this.filterValues$.next(rd);
|
this.filterValues$.next(rd);
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user