mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-16 06:23:03 +00:00
[DURACOM-304] Refactored relationship-type-data.service.ts by removing page size of 9999
This commit is contained in:

committed by
FrancescoMolinaro

parent
c3b265d213
commit
3922130434
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
||||
import { combineLatest as observableCombineLatest, EMPTY, expand, from, Observable, reduce } from 'rxjs';
|
||||
import { map, mergeMap, switchMap, toArray } from 'rxjs/operators';
|
||||
import { hasValue } from '../../shared/empty.util';
|
||||
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||
@@ -62,11 +62,26 @@ export class RelationshipTypeDataService extends BaseDataService<RelationshipTyp
|
||||
*/
|
||||
getRelationshipTypeByLabelAndTypes(relationshipTypeLabel: string, firstItemType: string, secondItemType: string): Observable<RelationshipType> {
|
||||
// Retrieve all relationship types from the server in a single page
|
||||
return this.findAllData.findAll({ currentPage: 1, elementsPerPage: 9999 }, true, true, followLink('leftType'), followLink('rightType'))
|
||||
const initialPageInfo = { currentPage: 1, elementsPerPage: 20 };
|
||||
return this.findAllData.findAll(initialPageInfo, true, true, followLink('leftType'), followLink('rightType'))
|
||||
.pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
// Emit each type in the page array separately
|
||||
switchMap((typeListRD: RemoteData<PaginatedList<RelationshipType>>) => typeListRD.payload.page),
|
||||
expand((typeListRD: RemoteData<PaginatedList<RelationshipType>>) => {
|
||||
const currentPage = typeListRD.payload.pageInfo.currentPage;
|
||||
const totalPages = typeListRD.payload.pageInfo.totalPages;
|
||||
if (currentPage < totalPages) {
|
||||
const nextPageInfo = { currentPage: currentPage + 1, elementsPerPage: 20 };
|
||||
return this.findAllData.findAll(nextPageInfo, true, true, followLink('leftType'), followLink('rightType')).pipe(
|
||||
getFirstSucceededRemoteData()
|
||||
);
|
||||
} else {
|
||||
return EMPTY;
|
||||
}
|
||||
}),
|
||||
// Collect all pages into a single array
|
||||
reduce((acc: RelationshipType[], typeListRD: RemoteData<PaginatedList<RelationshipType>>) => acc.concat(typeListRD.payload.page), []),
|
||||
mergeMap((relationshipTypes: RelationshipType[]) => from(relationshipTypes)),
|
||||
// Check each type individually, to see if it matches the provided types
|
||||
mergeMap((relationshipType: RelationshipType) => {
|
||||
if (relationshipType.leftwardType === relationshipTypeLabel) {
|
||||
|
Reference in New Issue
Block a user