1- import { Component , Inject , Input , OnInit } from '@angular/core' ;
1+ import { Component , Input , OnInit } from '@angular/core' ;
22
3- import { Observable } from 'rxjs' ;
4- import { map , switchMap , tap } from 'rxjs/operators' ;
5-
6- import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component' ;
3+ import { BehaviorSubject , Observable } from 'rxjs' ;
4+ import { filter , take , tap } from 'rxjs/operators' ;
75import { RemoteData } from '../../../core/data/remote-data' ;
8- import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service' ;
9- import { SearchService } from '../../../core/shared/search/search.service' ;
106import { SearchFilterConfig } from '../models/search-filter-config.model' ;
11- import { getFirstCompletedRemoteData } from '../../../core/shared/operators' ;
127import { shrinkInOut } from '../../animations/shrink' ;
8+ import { isNotEmpty } from '../../empty.util' ;
139
1410@Component ( {
1511 selector : 'ds-search-charts' ,
@@ -22,6 +18,11 @@ import { shrinkInOut } from '../../animations/shrink';
2218 * This component represents the part of the search sidebar that contains filters.
2319 */
2420export class SearchChartsComponent implements OnInit {
21+ /**
22+ * An observable containing configuration about which filters are shown and how they are shown
23+ */
24+ @Input ( ) filters : Observable < RemoteData < SearchFilterConfig [ ] > > ;
25+
2526 /**
2627 * The currently applied configuration (determines title of search)
2728 */
@@ -38,56 +39,30 @@ export class SearchChartsComponent implements OnInit {
3839 @Input ( ) inPlaceSearch ;
3940
4041 /**
41- * Toggle button to Show/Hide chart
42- */
43- @Input ( ) showChartsToggle = false ;
44-
45- /**
46- * An observable containing configuration about which filters are shown and how they are shown
42+ * Emits when the search filters values may be stale, and so they must be refreshed.
4743 */
48- filters : Observable < RemoteData < SearchFilterConfig [ ] > > ;
49-
50- selectedTypeIndex = 0 ;
51-
52- selectedFilter : any ;
44+ @Input ( ) refreshFilters : BehaviorSubject < boolean > ;
5345
5446 /**
55- * For chart regular expression
47+ * Toggle button to Show/Hide chart
5648 */
57- chartReg = new RegExp ( / ^ c h a r t . / , 'i' ) ;
49+ @ Input ( ) showChartsToggle = false ;
5850
5951 /**
60- * Initialize instance variables
61- * @param {SearchService } searchService
62- * @param {SearchConfigurationService } searchConfigService
52+ * The selected chart to show
6353 */
64- constructor (
65- @Inject ( SEARCH_CONFIG_SERVICE ) private searchConfigService : SearchConfigurationService ,
66- private searchService : SearchService ,
67- ) {
68- }
54+ selectedFilter : SearchFilterConfig ;
6955
7056 ngOnInit ( ) : void {
71- this . filters = this . searchConfigService . searchOptions . pipe (
72- switchMap ( ( options ) => this . searchService . getConfig ( options ?. scope , options ?. configuration ) ) ,
73- getFirstCompletedRemoteData ( ) ,
74- map ( ( rd : RemoteData < SearchFilterConfig [ ] > ) => {
75- if ( rd . hasSucceeded ) {
76- return Object . assign ( rd , {
77- payload : rd . payload . filter ( ( filter : SearchFilterConfig ) =>
78- this . chartReg . test ( filter . filterType )
79- )
80- } ) ;
81- } else {
82- return rd ;
83- }
84- } ) ,
57+ this . filters . pipe (
58+ filter ( ( rd : RemoteData < SearchFilterConfig [ ] > ) => isNotEmpty ( rd ) ) ,
59+ take ( 1 ) ,
8560 tap ( ( rd : RemoteData < SearchFilterConfig [ ] > ) => {
8661 this . selectedFilter = this . selectedFilter
8762 ? this . selectedFilter
8863 : rd . hasSucceeded ? rd . payload [ 0 ] : null ;
8964 } )
90- ) ;
65+ ) . subscribe ( ) ;
9166 }
9267
9368 /**
@@ -100,10 +75,10 @@ export class SearchChartsComponent implements OnInit {
10075 /**
10176 * Change the current chart filter selected
10277 *
103- * @param filter
78+ * @param searchfilter
10479 */
105- changeChartType ( filter ) {
106- this . selectedFilter = filter ;
80+ changeChartType ( searchfilter : SearchFilterConfig ) {
81+ this . selectedFilter = searchfilter ;
10782 }
10883
10984 /**
0 commit comments