11import { Component , OnInit , OnChanges , OnDestroy , Input } from '@angular/core' ;
22import { VocabularyOptions } from '../../core/submission/vocabularies/models/vocabulary-options.model' ;
33import { VocabularyEntryDetail } from '../../core/submission/vocabularies/models/vocabulary-entry-detail.model' ;
4- import { ActivatedRoute } from '@angular/router' ;
4+ import { ActivatedRoute , Params } from '@angular/router' ;
55import { BehaviorSubject , Observable , Subscription } from 'rxjs' ;
66import { BrowseDefinition } from '../../core/shared/browse-definition.model' ;
77import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator' ;
88import { map } from 'rxjs/operators' ;
99import { HierarchicalBrowseDefinition } from '../../core/shared/hierarchical-browse-definition.model' ;
1010import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type' ;
1111import { Context } from '../../core/shared/context.model' ;
12+ import { hasValue } from '../../shared/empty.util' ;
1213
1314@Component ( {
1415 selector : 'ds-browse-by-taxonomy' ,
@@ -71,7 +72,7 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
7172 /**
7273 * The parameters used in the URL
7374 */
74- queryParams : any ;
75+ queryParams : Params ;
7576
7677 /**
7778 * Resolved browse-by definition
@@ -99,6 +100,9 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
99100 this . vocabularyName = browseDefinition . vocabulary ;
100101 this . vocabularyOptions = { name : this . vocabularyName , closed : true } ;
101102 } ) ) ;
103+ this . subs . push ( this . scope$ . subscribe ( ( ) => {
104+ this . updateQueryParams ( ) ;
105+ } ) ) ;
102106 }
103107
104108 ngOnChanges ( ) : void {
@@ -112,9 +116,9 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
112116 * @param detail VocabularyEntryDetail to be added
113117 */
114118 onSelect ( detail : VocabularyEntryDetail ) : void {
115- this . selectedItems . push ( detail ) ;
116- this . filterValues = this . selectedItems
117- . map ( ( item : VocabularyEntryDetail ) => `${ item . value } ,equals` ) ;
119+ this . selectedItems . push ( detail ) ;
120+ this . filterValues = this . selectedItems
121+ . map ( ( item : VocabularyEntryDetail ) => `${ item . value } ,equals` ) ;
118122 this . updateQueryParams ( ) ;
119123 }
120124
@@ -124,18 +128,25 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
124128 * @param detail VocabularyEntryDetail to be removed
125129 */
126130 onDeselect ( detail : VocabularyEntryDetail ) : void {
127- this . selectedItems = this . selectedItems . filter ( ( entry : VocabularyEntryDetail ) => { return entry . id !== detail . id ; } ) ;
128- this . filterValues = this . filterValues . filter ( ( value : string ) => { return value !== `${ detail . value } ,equals` ; } ) ;
131+ this . selectedItems = this . selectedItems . filter ( ( entry : VocabularyEntryDetail ) => {
132+ return entry . id !== detail . id ;
133+ } ) ;
134+ this . filterValues = this . filterValues . filter ( ( value : string ) => {
135+ return value !== `${ detail . value } ,equals` ;
136+ } ) ;
129137 this . updateQueryParams ( ) ;
130138 }
131139
132140 /**
133141 * Updates queryParams based on the current facetType and filterValues.
134142 */
135- private updateQueryParams ( ) : void {
143+ updateQueryParams ( ) : void {
136144 this . queryParams = {
137145 [ 'f.' + this . facetType ] : this . filterValues
138146 } ;
147+ if ( hasValue ( this . scope ) ) {
148+ this . queryParams . scope = this . scope ;
149+ }
139150 }
140151
141152 ngOnDestroy ( ) : void {
0 commit comments