55import {
66 Component ,
77 Input ,
8+ OnChanges ,
89 OnInit ,
10+ SimpleChanges ,
911} from '@angular/core' ;
1012import { Router } from '@angular/router' ;
1113import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap' ;
@@ -21,10 +23,12 @@ import {
2123 switchMap ,
2224} from 'rxjs/operators' ;
2325
26+ import { ConfigurationDataService } from '../../../core/data/configuration-data.service' ;
2427import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service' ;
2528import { FeatureID } from '../../../core/data/feature-authorization/feature-id' ;
2629import { ScriptDataService } from '../../../core/data/processes/script-data.service' ;
2730import { RemoteData } from '../../../core/data/remote-data' ;
31+ import { ConfigurationProperty } from '../../../core/shared/configuration-property.model' ;
2832import { getFirstCompletedRemoteData } from '../../../core/shared/operators' ;
2933import { getProcessDetailRoute } from '../../../process-page/process-page-routing.paths' ;
3034import { Process } from '../../../process-page/processes/process.model' ;
@@ -46,13 +50,18 @@ import { SearchFilter } from '../models/search-filter.model';
4650/**
4751 * Display a button to export the current search results as csv
4852 */
49- export class SearchExportCsvComponent implements OnInit {
53+ export class SearchExportCsvComponent implements OnInit , OnChanges {
5054
5155 /**
5256 * The current configuration of the search
5357 */
5458 @Input ( ) searchConfig : PaginatedSearchOptions ;
5559
60+ /**
61+ * The total number of items in the search results which can be exported
62+ */
63+ @Input ( ) total : number ;
64+
5665 /**
5766 * Observable used to determine whether the button should be shown
5867 */
@@ -63,12 +72,18 @@ export class SearchExportCsvComponent implements OnInit {
6372 */
6473 tooltipMsg = 'metadata-export-search.tooltip' ;
6574
75+ exportLimitExceededKey = 'metadata-export-search.submit.error.limit-exceeded' ;
76+
77+ exportLimitExceededMsg = '' ;
78+
79+ shouldShowWarning$ : Observable < boolean > ;
80+
6681 constructor ( private scriptDataService : ScriptDataService ,
6782 private authorizationDataService : AuthorizationDataService ,
6883 private notificationsService : NotificationsService ,
6984 private translateService : TranslateService ,
7085 private router : Router ,
71- ) {
86+ private configurationService : ConfigurationDataService ) {
7287 }
7388
7489 ngOnInit ( ) : void {
@@ -78,6 +93,31 @@ export class SearchExportCsvComponent implements OnInit {
7893 map ( ( canExecute : boolean ) => canExecute ) ,
7994 startWith ( false ) ,
8095 ) ;
96+ this . shouldShowWarning$ = this . itemExceeds ( ) ;
97+ }
98+
99+ ngOnChanges ( changes : SimpleChanges ) : void {
100+ if ( changes . total ) {
101+ this . shouldShowWarning$ = this . itemExceeds ( ) ;
102+ }
103+ }
104+
105+ /**
106+ * Checks if the export limit has been exceeded and updates the tooltip accordingly
107+ */
108+ private itemExceeds ( ) : Observable < boolean > {
109+ return this . configurationService . findByPropertyName ( 'bulkedit.export.max.items' ) . pipe (
110+ getFirstCompletedRemoteData ( ) ,
111+ map ( ( response : RemoteData < ConfigurationProperty > ) => {
112+ const limit = Number ( response . payload ?. values ?. [ 0 ] ) || 500 ;
113+ if ( limit < this . total ) {
114+ this . exportLimitExceededMsg = this . translateService . instant ( this . exportLimitExceededKey , { limit : String ( limit ) } ) ;
115+ return true ;
116+ } else {
117+ return false ;
118+ }
119+ } ) ,
120+ ) ;
81121 }
82122
83123 /**
0 commit comments