@@ -25,6 +25,7 @@ import {
2525 reduce ,
2626 startWith ,
2727 switchMap ,
28+ take ,
2829 tap ,
2930} from 'rxjs/operators' ;
3031import { SortPipe } from 'src/app/shared/utils/sort.pipe' ;
@@ -36,12 +37,14 @@ import {
3637 PaginatedList ,
3738} from '../../core/data/paginated-list.model' ;
3839import { RemoteData } from '../../core/data/remote-data' ;
39- import { ItemExportFormatService } from '../../core/itemexportformat/item-export-format.service' ;
40+ import {
41+ ItemExportFormatMolteplicity ,
42+ ItemExportFormatService ,
43+ } from '../../core/itemexportformat/item-export-format.service' ;
4044import { ItemType } from '../../core/shared/item-relationships/item-type.model' ;
4145import { getFirstSucceededRemoteWithNotEmptyData } from '../../core/shared/operators' ;
4246import {
4347 hasValue ,
44- isEmpty ,
4548 isNotNull ,
4649} from '../empty.util' ;
4750import { ThemedLoadingComponent } from '../loading/themed-loading.component' ;
@@ -84,11 +87,16 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
8487 public searchListEntity : ItemType [ ] = [ ] ;
8588
8689 /**
87- * TRUE if the parent operation is a 'new submission' operation, FALSE otherwise (eg.: is an 'Import metadata from an external source'
88- * operation).
90+ * TRUE if the parent operation is a 'new submission' operation, FALSE otherwise (eg.: is an 'Import metadata from an external source' operation).
8991 */
9092 @Input ( ) isSubmission : boolean ;
9193
94+ /**
95+ * TRUE if the main operation is "Import metadata from an external source", FALSE otherwise.
96+ * Used to determine which list type to populate.
97+ */
98+ @Input ( ) isImportFromExternalSource : boolean ;
99+
92100 /**
93101 * The entity to output to the parent component
94102 */
@@ -127,6 +135,8 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
127135 constructor (
128136 private changeDetectorRef : ChangeDetectorRef ,
129137 private entityTypeService : EntityTypeDataService ,
138+ private itemExportFormatService : ItemExportFormatService ,
139+ private el : ElementRef ,
130140 private translate : TranslateService ,
131141 ) { }
132142
@@ -190,23 +200,44 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
190200 public populateEntityList ( page : number ) {
191201 this . isLoadingList . next ( true ) ;
192202 let searchListEntity$ : Observable < RemoteData < PaginatedList < ItemType > > > ;
193- // Set the pagination info
194- const findOptions : FindListOptions = {
195- elementsPerPage : 10 ,
196- currentPage : page ,
197- } ;
198- if ( this . isSubmission ) {
199- searchListEntity$ =
200- this . entityTypeService . getAllAuthorizedRelationshipType ( findOptions ) ;
203+ if ( this . isSubmission || this . isImportFromExternalSource ) {
204+ // Set the pagination info
205+ const findOptions : FindListOptions = {
206+ elementsPerPage : 10 ,
207+ currentPage : page ,
208+ } ;
209+
210+ searchListEntity$ = this . isSubmission ?
211+ this . entityTypeService . getAllAuthorizedRelationshipType ( findOptions ) :
212+ this . entityTypeService . getAllAuthorizedRelationshipTypeImport ( findOptions ) ;
213+
214+ searchListEntity$ = searchListEntity$ . pipe (
215+ getFirstSucceededRemoteWithNotEmptyData ( ) ,
216+ tap ( entityType => {
217+ if ( ( this . searchListEntity . length + findOptions . elementsPerPage ) >= entityType . payload . totalElements ) {
218+ this . hasNextPage = false ;
219+ }
220+ } ) ,
221+ ) ;
201222 } else {
202223 searchListEntity$ =
203- this . entityTypeService . getAllAuthorizedRelationshipTypeImport ( findOptions ) ;
224+ this . itemExportFormatService . byEntityTypeAndMolteplicity ( null , ItemExportFormatMolteplicity . MULTIPLE )
225+ . pipe (
226+ take ( 1 ) ,
227+ map ( ( formatTypes : any ) => {
228+ const entityList : ItemType [ ] = Object . keys ( formatTypes )
229+ . filter ( ( entityType : string ) => isNotNull ( entityType ) && entityType !== 'null' )
230+ . map ( ( entityType : string ) => ( {
231+ id : entityType ,
232+ label : entityType ,
233+ } as any ) ) ;
234+ return createSuccessfulRemoteDataObject ( buildPaginatedList ( null , entityList ) ) ;
235+ } ) ,
236+ tap ( ( ) => this . hasNextPage = false ) ,
237+ ) ;
204238 }
205239
206240 this . searchListEntity$ = searchListEntity$ . pipe (
207- getFirstSucceededRemoteWithNotEmptyData ( ) ,
208- map ( ( formatTypes : RemoteData < PaginatedList < ItemType > > ) => this . parseItemTypesResponse ( formatTypes ) ) ,
209- tap ( ( entityTypes ) => this . hasNextPages ( findOptions , entityTypes ) ) ,
210241 switchMap ( ( entityType : RemoteData < PaginatedList < ItemType > > ) => entityType . payload . page ) ,
211242 map ( ( item : ItemType ) => {
212243 return {
@@ -229,26 +260,6 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
229260 ) ;
230261 }
231262
232- private parseItemTypesResponse ( formatTypes : RemoteData < PaginatedList < ItemType > > ) {
233- if ( formatTypes . statusCode !== 200 ) {
234- return createSuccessfulRemoteDataObject ( buildPaginatedList ( null , [ ] ) ) ;
235- }
236- const entityList : ItemType [ ] = ( formatTypes ?. payload ?. page || [ ] )
237- . filter ( itemType => isNotNull ( itemType ?. id ) ) ;
238- return createSuccessfulRemoteDataObject ( buildPaginatedList ( null , entityList ) ) ;
239- }
240-
241- private hasNextPages < A > ( findOptions : FindListOptions , entityType : RemoteData < PaginatedList < A > > ) {
242- if (
243- findOptions . elementsPerPage > 0 &&
244- ( isEmpty ( entityType ?. payload ?. totalElements ) || entityType . payload . totalElements < findOptions . elementsPerPage )
245- ) {
246- this . hasNextPage = false ;
247- } else {
248- this . hasNextPage = true ;
249- }
250- }
251-
252263 /**
253264 * Reset pagination values
254265 */
0 commit comments