@@ -2,13 +2,16 @@ import { AfterViewInit, Component, Inject, Input, OnDestroy, OnInit, PLATFORM_ID
22import { ActivatedRoute , NavigationStart , Params , Router } from '@angular/router' ;
33import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap' ;
44import { BehaviorSubject , Observable , Subscription } from 'rxjs' ;
5+ import { Store , select } from '@ngrx/store' ;
56import { filter , map } from 'rxjs/operators' ;
67
78import { APP_CONFIG , AppConfig } from '../../app.config' ;
89import { Individual } from '../../core/model/discovery' ;
910import { SdrPage } from '../../core/model/sdr' ;
1011import { DisplayTabSectionView , Sort } from '../../core/model/view' ;
11- import { getResourcesPage , getSubsectionResources , loadBadges } from '../../shared/utilities/view.utility' ;
12+ import { AppState } from '../../core/store' ;
13+ import { selectRouterQueryParams } from '../../core/store/router' ;
14+ import { addExportToQueryParams , getResourcesPage , getSubsectionResources , hasExport , loadBadges } from '../../shared/utilities/view.utility' ;
1215
1316@Component ( {
1417 selector : 'scholars-section' ,
@@ -34,9 +37,12 @@ export class SectionComponent implements AfterViewInit, OnInit, OnDestroy {
3437
3538 private subscriptions : Subscription [ ] ;
3639
40+ public queryParams : Observable < Params > ;
41+
3742 constructor (
3843 @Inject ( APP_CONFIG ) private appConfig : AppConfig ,
3944 @Inject ( PLATFORM_ID ) private platformId : string ,
45+ private store : Store < AppState > ,
4046 private router : Router ,
4147 private route : ActivatedRoute
4248 ) {
@@ -51,11 +57,13 @@ export class SectionComponent implements AfterViewInit, OnInit, OnDestroy {
5157 }
5258
5359 ngOnInit ( ) {
60+ this . queryParams = this . store . pipe ( select ( selectRouterQueryParams ) ) ;
5461 if ( this . section . paginated ) {
5562 this . subscriptions . push (
5663 this . router . events . pipe ( filter ( ( event ) => event instanceof NavigationStart ) ) . subscribe ( ( ) => loadBadges ( this . platformId ) )
5764 ) ;
5865 const resources = getSubsectionResources ( this . individual [ this . section . field ] , this . section . filters ) ;
66+
5967 this . page = this . route . queryParams . pipe (
6068 map ( ( params : Params ) => {
6169 const pageSize = params [ `${ this . section . name } .size` ] ? Number ( params [ `${ this . section . name } .size` ] ) : this . section . pageSize ;
@@ -92,4 +100,22 @@ export class SectionComponent implements AfterViewInit, OnInit, OnDestroy {
92100 setTimeout ( ( ) => tooltip . close ( ) , 2000 ) ;
93101 }
94102
103+ public hasExport ( section : DisplayTabSectionView ) : boolean {
104+ return hasExport ( section ) ;
105+ }
106+
107+ public getSectionExportUrl ( params : Params , section : DisplayTabSectionView ) : string {
108+ const queryParams : Params = { ...params } ;
109+ queryParams . facets = null ;
110+ queryParams . collection = null ;
111+ addExportToQueryParams ( queryParams , section ) ;
112+ const tree = this . router . createUrlTree ( [ '' ] , { queryParams } ) ;
113+ const query = tree . toString ( ) . substring ( 1 ) ;
114+ if ( ! this . individual ?. id ) {
115+ return ;
116+ }
117+
118+ return `${ this . appConfig . serviceUrl } /individual/${ this . individual . id } /export${ query } &view=${ section . field } ` ;
119+ }
120+
95121}
0 commit comments