@@ -2,7 +2,9 @@ import { AsyncPipe } from '@angular/common';
22import {
33 Component ,
44 Input ,
5+ OnChanges ,
56 OnInit ,
7+ SimpleChanges ,
68} from '@angular/core' ;
79import { Router } from '@angular/router' ;
810import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap' ;
@@ -18,10 +20,12 @@ import {
1820 switchMap ,
1921} from 'rxjs/operators' ;
2022
23+ import { ConfigurationDataService } from '../../../core/data/configuration-data.service' ;
2124import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service' ;
2225import { FeatureID } from '../../../core/data/feature-authorization/feature-id' ;
2326import { ScriptDataService } from '../../../core/data/processes/script-data.service' ;
2427import { RemoteData } from '../../../core/data/remote-data' ;
28+ import { ConfigurationProperty } from '../../../core/shared/configuration-property.model' ;
2529import { getFirstCompletedRemoteData } from '../../../core/shared/operators' ;
2630import { getProcessDetailRoute } from '../../../process-page/process-page-routing.paths' ;
2731import { Process } from '../../../process-page/processes/process.model' ;
@@ -43,13 +47,18 @@ import { SearchFilter } from '../models/search-filter.model';
4347/**
4448 * Display a button to export the current search results as csv
4549 */
46- export class SearchExportCsvComponent implements OnInit {
50+ export class SearchExportCsvComponent implements OnInit , OnChanges {
4751
4852 /**
4953 * The current configuration of the search
5054 */
5155 @Input ( ) searchConfig : PaginatedSearchOptions ;
5256
57+ /**
58+ * The total number of items in the search results which can be exported
59+ */
60+ @Input ( ) total : number ;
61+
5362 /**
5463 * Observable used to determine whether the button should be shown
5564 */
@@ -60,12 +69,18 @@ export class SearchExportCsvComponent implements OnInit {
6069 */
6170 tooltipMsg = 'metadata-export-search.tooltip' ;
6271
72+ exportLimitExceededKey = 'metadata-export-search.submit.error.limit-exceeded' ;
73+
74+ exportLimitExceededMsg = '' ;
75+
76+ shouldShowWarning$ : Observable < boolean > ;
77+
6378 constructor ( private scriptDataService : ScriptDataService ,
6479 private authorizationDataService : AuthorizationDataService ,
6580 private notificationsService : NotificationsService ,
6681 private translateService : TranslateService ,
6782 private router : Router ,
68- ) {
83+ private configurationService : ConfigurationDataService ) {
6984 }
7085
7186 ngOnInit ( ) : void {
@@ -75,6 +90,31 @@ export class SearchExportCsvComponent implements OnInit {
7590 map ( ( canExecute : boolean ) => canExecute ) ,
7691 startWith ( false ) ,
7792 ) ;
93+ this . shouldShowWarning$ = this . itemExceeds ( ) ;
94+ }
95+
96+ ngOnChanges ( changes : SimpleChanges ) : void {
97+ if ( changes . total ) {
98+ this . shouldShowWarning$ = this . itemExceeds ( ) ;
99+ }
100+ }
101+
102+ /**
103+ * Checks if the export limit has been exceeded and updates the tooltip accordingly
104+ */
105+ private itemExceeds ( ) : Observable < boolean > {
106+ return this . configurationService . findByPropertyName ( 'bulkedit.export.max.items' ) . pipe (
107+ getFirstCompletedRemoteData ( ) ,
108+ map ( ( response : RemoteData < ConfigurationProperty > ) => {
109+ const limit = Number ( response . payload ?. values ?. [ 0 ] ) || 500 ;
110+ if ( limit < this . total ) {
111+ this . exportLimitExceededMsg = this . translateService . instant ( this . exportLimitExceededKey , { limit : String ( limit ) } ) ;
112+ return true ;
113+ } else {
114+ return false ;
115+ }
116+ } ) ,
117+ ) ;
78118 }
79119
80120 /**
0 commit comments