diff --git a/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts b/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts index 36b0816ade1..3e022e8c377 100644 --- a/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts +++ b/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts @@ -31,13 +31,16 @@ import cloneDeep from 'lodash/cloneDeep'; import { combineLatest, combineLatest as observableCombineLatest, + EMPTY, Observable, of as observableOf, Subscription, } from 'rxjs'; import { + expand, filter, map, + reduce, switchMap, tap, } from 'rxjs/operators'; @@ -178,7 +181,10 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { /** * Options for fetching all bitstream formats */ - findAllOptions = { elementsPerPage: 9999 }; + findAllOptions = { + elementsPerPage: 20, + currentPage: 1, + }; /** * The Dynamic Input Model for the file's name @@ -463,14 +469,27 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { this.itemId = this.route.snapshot.queryParams.itemId; this.entityType = this.route.snapshot.queryParams.entityType; this.bitstreamRD$ = this.route.data.pipe(map((data: any) => data.bitstream)); - this.bitstreamFormatsRD$ = this.bitstreamFormatService.findAll(this.findAllOptions); - const bitstream$ = this.bitstreamRD$.pipe( + this.bitstreamFormatsRD$ = this.bitstreamFormatService.findAll(this.findAllOptions).pipe( getFirstSucceededRemoteData(), - getRemoteDataPayload(), + expand((response: RemoteData>) => { + const pageInfo = response.payload.pageInfo; + if (pageInfo.currentPage < pageInfo.totalPages) { + const nextPageOptions = { ...this.findAllOptions, currentPage: pageInfo.currentPage + 1 }; + return this.bitstreamFormatService.findAll(nextPageOptions).pipe(getFirstSucceededRemoteData()); + } else { + return EMPTY; + } + }), ); - const allFormats$ = this.bitstreamFormatsRD$.pipe( + const bitstreamFormats$ = this.bitstreamFormatsRD$.pipe( + reduce((acc: BitstreamFormat[], response: RemoteData>) => { + return acc.concat(response.payload.page); + }, []), + ); + + const bitstream$ = this.bitstreamRD$.pipe( getFirstSucceededRemoteData(), getRemoteDataPayload(), ); @@ -493,14 +512,14 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { this.subs.push( observableCombineLatest( bitstream$, - allFormats$, + bitstreamFormats$, bundle$, primaryBitstream$, item$, ).pipe() .subscribe(([bitstream, allFormats, bundle, primaryBitstream, item]) => { this.bitstream = bitstream as Bitstream; - this.formats = allFormats.page; + this.formats = allFormats; this.bundle = bundle; // hasValue(primaryBitstream) because if there's no primaryBitstream on the bundle it will // be a success response, but empty diff --git a/src/app/core/data/bitstream-data.service.ts b/src/app/core/data/bitstream-data.service.ts index b8776d25309..9455a456fa7 100644 --- a/src/app/core/data/bitstream-data.service.ts +++ b/src/app/core/data/bitstream-data.service.ts @@ -241,11 +241,12 @@ export class BitstreamDataService extends IdentifiableDataService imp * no valid cached version. Defaults to true * @param reRequestOnStale Whether or not the request should automatically be re- * requested after the response becomes stale + * @param options the {@link FindListOptions} for the request * @return {Observable} * Return an observable that contains primary bitstream information or null */ - public findPrimaryBitstreamByItemAndName(item: Item, bundleName: string, useCachedVersionIfAvailable = true, reRequestOnStale = true): Observable { - return this.bundleService.findByItemAndName(item, bundleName, useCachedVersionIfAvailable, reRequestOnStale, followLink('primaryBitstream')).pipe( + public findPrimaryBitstreamByItemAndName(item: Item, bundleName: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, options?: FindListOptions): Observable { + return this.bundleService.findByItemAndName(item, bundleName, useCachedVersionIfAvailable, reRequestOnStale, options, followLink('primaryBitstream')).pipe( getFirstCompletedRemoteData(), switchMap((rd: RemoteData) => { if (!rd.hasSucceeded) { diff --git a/src/app/core/data/bundle-data.service.ts b/src/app/core/data/bundle-data.service.ts index 5d552c9bf0f..027ec4e68a7 100644 --- a/src/app/core/data/bundle-data.service.ts +++ b/src/app/core/data/bundle-data.service.ts @@ -78,10 +78,11 @@ export class BundleDataService extends IdentifiableDataService implement * requested after the response becomes stale * @param linksToFollow List of {@link FollowLinkConfig} that indicate which * {@link HALLink}s should be automatically resolved + * @param options the {@link FindListOptions} for the request */ // TODO should be implemented rest side - findByItemAndName(item: Item, bundleName: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable> { - return this.findAllByItem(item, { elementsPerPage: 9999 }, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow).pipe( + findByItemAndName(item: Item, bundleName: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, options?: FindListOptions, ...linksToFollow: FollowLinkConfig[]): Observable> { + return this.findAllByItem(item, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow).pipe( map((rd: RemoteData>) => { if (hasValue(rd.payload) && hasValue(rd.payload.page)) { const matchingBundle = rd.payload.page.find((bundle: Bundle) => @@ -114,6 +115,47 @@ export class BundleDataService extends IdentifiableDataService implement ); } + // findByItemAndName(item: Item, bundleName: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable> { + // return this.findAllByItem(item, { elementsPerPage: 1, currentPage: 1 }, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow).pipe( + // expand((rd: RemoteData>) => { + // if (rd.hasSucceeded && hasValue(rd.payload) && hasValue(rd.payload.page) && rd.payload.currentPage < rd.payload.totalPages) { + // const nextPageOptions = { elementsPerPage: 1, currentPage: rd.payload.currentPage + 1 }; + // return this.findAllByItem(item, nextPageOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); + // } else { + // return EMPTY; + // } + // }), + // map((rd: RemoteData>) => { + // if (hasValue(rd.payload) && hasValue(rd.payload.page)) { + // const matchingBundle = rd.payload.page.find((bundle: Bundle) => bundle.name === bundleName); + // if (hasValue(matchingBundle)) { + // return new RemoteData( + // rd.timeCompleted, + // rd.msToLive, + // rd.lastUpdated, + // RequestEntryState.Success, + // null, + // matchingBundle, + // 200 + // ); + // } else { + // return new RemoteData( + // rd.timeCompleted, + // rd.msToLive, + // rd.lastUpdated, + // RequestEntryState.Error, + // `The bundle with name ${bundleName} was not found.`, + // null, + // 404 + // ); + // } + // } else { + // return rd as any; + // } + // }) + // ); + // } + /** * Get the bitstreams endpoint for a bundle * @param bundleId diff --git a/src/app/core/data/relationship-type-data.service.ts b/src/app/core/data/relationship-type-data.service.ts index 43c018bbce2..dc553973ee5 100644 --- a/src/app/core/data/relationship-type-data.service.ts +++ b/src/app/core/data/relationship-type-data.service.ts @@ -1,12 +1,15 @@ import { Injectable } from '@angular/core'; import { combineLatest as observableCombineLatest, + EMPTY, + from, Observable, } from 'rxjs'; import { + expand, map, mergeMap, - switchMap, + reduce, toArray, } from 'rxjs/operators'; @@ -75,11 +78,26 @@ export class RelationshipTypeDataService extends BaseDataService { // 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>) => typeListRD.payload.page), + expand((typeListRD: RemoteData>) => { + 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>) => 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) { diff --git a/src/app/core/metadata/head-tag.service.ts b/src/app/core/metadata/head-tag.service.ts index 270e5fde723..8041bb3a4ac 100644 --- a/src/app/core/metadata/head-tag.service.ts +++ b/src/app/core/metadata/head-tag.service.ts @@ -50,6 +50,7 @@ import { coreSelector } from '../core.selectors'; import { CoreState } from '../core-state.model'; import { BundleDataService } from '../data/bundle-data.service'; import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service'; +import { FindListOptions } from '../data/find-list-options.model'; import { PaginatedList } from '../data/paginated-list.model'; import { RemoteData } from '../data/remote-data'; import { RootDataService } from '../data/root-data.service'; @@ -331,6 +332,7 @@ export class HeadTagService { 'ORIGINAL', true, true, + new FindListOptions(), followLink('primaryBitstream'), followLink('bitstreams', { findListOptions: { diff --git a/src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.html b/src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.html index 9d8f384e166..1564d3abc79 100644 --- a/src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.html +++ b/src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.html @@ -39,6 +39,9 @@ [isFirstTable]="isFirst" aria-describedby="reorder-description"> +
+ +