11import { animate , state , style , transition , trigger } from '@angular/animations' ;
2- import { Component , Inject , OnDestroy , OnInit } from '@angular/core' ;
2+ import { Component , Inject , OnDestroy , OnInit , EventEmitter } from '@angular/core' ;
33import { Router } from '@angular/router' ;
44
55import { BehaviorSubject , combineLatest as observableCombineLatest , Observable , of as observableOf , Subject , Subscription } from 'rxjs' ;
@@ -13,14 +13,14 @@ import { EmphasizePipe } from '../../../../utils/emphasize.pipe';
1313import { FacetValue } from '../../../models/facet-value.model' ;
1414import { SearchFilterConfig } from '../../../models/search-filter-config.model' ;
1515import { SearchService } from '../../../../../core/shared/search/search.service' ;
16- import { FILTER_CONFIG , IN_PLACE_SEARCH , REFRESH_FILTER , SearchFilterService } from '../../../../../core/shared/search/search-filter.service' ;
16+ import { FILTER_CONFIG , IN_PLACE_SEARCH , REFRESH_FILTER , SearchFilterService , CHANGE_APPLIED_FILTERS } from '../../../../../core/shared/search/search-filter.service' ;
1717import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service' ;
1818import { getFirstSucceededRemoteData } from '../../../../../core/shared/operators' ;
1919import { InputSuggestion } from '../../../../input-suggestions/input-suggestions.model' ;
2020import { SearchOptions } from '../../../models/search-options.model' ;
2121import { SEARCH_CONFIG_SERVICE } from '../../../../../my-dspace-page/my-dspace-page.component' ;
2222import { currentPath } from '../../../../utils/route.utils' ;
23- import { getFacetValueForType , stripOperatorFromFilterValue } from '../../../search.utils' ;
23+ import { getFacetValueForType , stripOperatorFromFilterValue , addOperatorToFilterValue } from '../../../search.utils' ;
2424import { createPendingRemoteDataObject } from '../../../../remote-data.utils' ;
2525import { FacetValues } from '../../../models/facet-values.model' ;
2626import { AppliedFilter } from '../../../models/applied-filter.model' ;
@@ -93,7 +93,9 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
9393 @Inject ( SEARCH_CONFIG_SERVICE ) public searchConfigService : SearchConfigurationService ,
9494 @Inject ( IN_PLACE_SEARCH ) public inPlaceSearch : boolean ,
9595 @Inject ( FILTER_CONFIG ) public filterConfig : SearchFilterConfig ,
96- @Inject ( REFRESH_FILTER ) public refreshFilters : BehaviorSubject < boolean > ) {
96+ @Inject ( REFRESH_FILTER ) public refreshFilters : BehaviorSubject < boolean > ,
97+ @Inject ( CHANGE_APPLIED_FILTERS ) public changeAppliedFilters : EventEmitter < AppliedFilter [ ] > ,
98+ ) {
9799 }
98100
99101 /**
@@ -126,13 +128,6 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
126128 this . filter = '' ;
127129 }
128130
129- /**
130- * Checks if a value for this filter is currently active
131- */
132- isChecked ( value : FacetValue ) : Observable < boolean > {
133- return this . filterService . isFilterActiveWithValue ( this . filterConfig . paramName , value . value ) ;
134- }
135-
136131 /**
137132 * @returns {string } The base path to the search page, or the current page when inPlaceSearch is true
138133 */
@@ -243,13 +238,13 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
243238 */
244239 protected applyFilterValue ( data ) {
245240 if ( data . match ( new RegExp ( `^.+,(equals|query|authority)$` ) ) ) {
246- this . selectedValues$ . pipe ( take ( 1 ) ) . subscribe ( ( selectedValues ) => {
241+ this . selectedValues$ . pipe ( take ( 1 ) ) . subscribe ( ( selectedValues : AppliedFilter [ ] ) => {
247242 if ( isNotEmpty ( data ) ) {
248- this . router . navigate ( this . getSearchLinkParts ( ) , {
243+ void this . router . navigate ( this . getSearchLinkParts ( ) , {
249244 queryParams :
250245 {
251246 [ this . filterConfig . paramName ] : [
252- ...selectedValues . map ( ( appliedFilter : AppliedFilter ) => appliedFilter . value ) ,
247+ ...selectedValues . map ( ( appliedFilter : AppliedFilter ) => addOperatorToFilterValue ( appliedFilter . value , appliedFilter . operator ) ) ,
253248 data
254249 ]
255250 } ,
@@ -306,13 +301,15 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
306301 return this . rdbs . aggregate ( filterValues ) ;
307302 } ) ,
308303 tap ( ( rd : RemoteData < FacetValues [ ] > ) => {
309- const appliedFilters : AppliedFilter [ ] = [ ] . concat ( ...rd . payload . map ( ( facetValues : FacetValues ) => facetValues . appliedFilters ) )
304+ const allAppliedFilters : AppliedFilter [ ] = [ ] . concat ( ...rd . payload . map ( ( facetValues : FacetValues ) => facetValues . appliedFilters ) )
310305 . filter ( ( appliedFilter : AppliedFilter ) => hasValue ( appliedFilter ) ) ;
311306 this . selectedValues$ = this . filterService . getSelectedValuesForFilter ( this . filterConfig ) . pipe (
312307 map ( ( selectedValues : string [ ] ) => {
313- return selectedValues . map ( ( value : string ) => {
314- return appliedFilters . find ( ( appliedFilter : AppliedFilter ) => appliedFilter . value === stripOperatorFromFilterValue ( value ) ) ;
308+ const appliedFilters : AppliedFilter [ ] = selectedValues . map ( ( value : string ) => {
309+ return allAppliedFilters . find ( ( appliedFilter : AppliedFilter ) => appliedFilter . value === stripOperatorFromFilterValue ( value ) ) ;
315310 } ) . filter ( ( appliedFilter : AppliedFilter ) => hasValue ( appliedFilter ) ) ;
311+ this . changeAppliedFilters . emit ( appliedFilters ) ;
312+ return appliedFilters ;
316313 } ) ,
317314 ) ;
318315 this . animationState = 'ready' ;
0 commit comments