1- import { Component , Input , OnInit } from '@angular/core' ;
1+ import { Component , Input , OnChanges , OnInit , SimpleChanges } from '@angular/core' ;
22import { Observable } from 'rxjs' ;
33import { ScriptDataService } from '../../../core/data/processes/script-data.service' ;
44import { getFirstCompletedRemoteData } from '../../../core/shared/operators' ;
@@ -14,6 +14,8 @@ import { TranslateService } from '@ngx-translate/core';
1414import { Router } from '@angular/router' ;
1515import { PaginatedSearchOptions } from '../models/paginated-search-options.model' ;
1616import { SearchFilter } from '../models/search-filter.model' ;
17+ import { ConfigurationDataService } from '../../../core/data/configuration-data.service' ;
18+ import { ConfigurationProperty } from '../../../core/shared/configuration-property.model' ;
1719
1820@Component ( {
1921 selector : 'ds-search-export-csv' ,
@@ -23,13 +25,18 @@ import { SearchFilter } from '../models/search-filter.model';
2325/**
2426 * Display a button to export the current search results as csv
2527 */
26- export class SearchExportCsvComponent implements OnInit {
28+ export class SearchExportCsvComponent implements OnInit , OnChanges {
2729
2830 /**
2931 * The current configuration of the search
3032 */
3133 @Input ( ) searchConfig : PaginatedSearchOptions ;
3234
35+ /**
36+ * The total number of items in the search results which can be exported
37+ */
38+ @Input ( ) total : number ;
39+
3340 /**
3441 * Observable used to determine whether the button should be shown
3542 */
@@ -40,12 +47,18 @@ export class SearchExportCsvComponent implements OnInit {
4047 */
4148 tooltipMsg = 'metadata-export-search.tooltip' ;
4249
50+ exportLimitExceededKey = 'metadata-export-search.submit.error.limit-exceeded' ;
51+
52+ exportLimitExceededMsg = '' ;
53+
54+ shouldShowWarning$ : Observable < boolean > ;
55+
4356 constructor ( private scriptDataService : ScriptDataService ,
4457 private authorizationDataService : AuthorizationDataService ,
4558 private notificationsService : NotificationsService ,
4659 private translateService : TranslateService ,
47- private router : Router
48- ) {
60+ private router : Router ,
61+ private configurationService : ConfigurationDataService ) {
4962 }
5063
5164 ngOnInit ( ) : void {
@@ -55,6 +68,31 @@ export class SearchExportCsvComponent implements OnInit {
5568 map ( ( canExecute : boolean ) => canExecute ) ,
5669 startWith ( false ) ,
5770 ) ;
71+ this . shouldShowWarning$ = this . itemExceeds ( ) ;
72+ }
73+
74+ ngOnChanges ( changes : SimpleChanges ) : void {
75+ if ( changes . total ) {
76+ this . shouldShowWarning$ = this . itemExceeds ( ) ;
77+ }
78+ }
79+
80+ /**
81+ * Checks if the export limit has been exceeded and updates the tooltip accordingly
82+ */
83+ private itemExceeds ( ) : Observable < boolean > {
84+ return this . configurationService . findByPropertyName ( 'bulkedit.export.max.items' ) . pipe (
85+ getFirstCompletedRemoteData ( ) ,
86+ map ( ( response : RemoteData < ConfigurationProperty > ) => {
87+ const limit = Number ( response . payload ?. values ?. [ 0 ] ) || 500 ;
88+ if ( limit < this . total ) {
89+ this . exportLimitExceededMsg = this . translateService . instant ( this . exportLimitExceededKey , { limit : String ( limit ) } ) ;
90+ return true ;
91+ } else {
92+ return false ;
93+ }
94+ } ) ,
95+ ) ;
5896 }
5997
6098 /**
0 commit comments