[Task 72397] implemented the bitstream pagination on simple and full item pages

This commit is contained in:
Raf Ponsaerts
2020-08-07 16:07:33 +02:00
parent 8b639bc7ba
commit f6f87a5738
7 changed files with 474 additions and 67 deletions

View File

@@ -1,10 +1,13 @@
import { Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
import { BitstreamDataService } from '../../../../core/data/bitstream-data.service';
import { Bitstream } from '../../../../core/shared/bitstream.model';
import { Item } from '../../../../core/shared/item.model';
import { getFirstSucceededRemoteListPayload } from '../../../../core/shared/operators';
import {filter, takeWhile} from 'rxjs/operators';
import {RemoteData} from '../../../../core/data/remote-data';
import {hasNoValue, hasValue} from '../../../../shared/empty.util';
import {PaginatedList} from '../../../../core/data/paginated-list';
/**
* This component renders the file section of the item
@@ -22,7 +25,13 @@ export class FileSectionComponent implements OnInit {
separator = '<br/>';
bitstreams$: Observable<Bitstream[]>;
bitstreams$: BehaviorSubject<Bitstream[]>;
currentPage: number;
isLoading: boolean;
isLastPage: boolean;
constructor(
protected bitstreamDataService: BitstreamDataService
@@ -30,13 +39,31 @@ export class FileSectionComponent implements OnInit {
}
ngOnInit(): void {
this.initialize();
this.getNextPage();
}
initialize(): void {
this.bitstreams$ = this.bitstreamDataService.findAllByItemAndBundleName(this.item, 'ORIGINAL').pipe(
getFirstSucceededRemoteListPayload()
);
/**
* This method will retrieve the next page of Bitstreams from the external BitstreamDataService call.
* It'll retrieve the currentPage from the class variables and it'll add the next page of bitstreams with the
* already existing one.
* If the currentPage variable is undefined, we'll set it to 1 and retrieve the first page of Bitstreams
*/
getNextPage(): void {
this.isLoading = true;
if (this.currentPage === undefined) {
this.currentPage = 1;
this.bitstreams$ = new BehaviorSubject([]);
} else {
this.currentPage++;
}
this.bitstreamDataService.findAllByItemAndBundleName(this.item, 'ORIGINAL', { currentPage: this.currentPage }).pipe(
filter((bitstreamsRD: RemoteData<PaginatedList<Bitstream>>) => hasValue(bitstreamsRD)),
takeWhile((bitstreamsRD: RemoteData<PaginatedList<Bitstream>>) => hasNoValue(bitstreamsRD.payload) && hasNoValue(bitstreamsRD.error), true)
).subscribe((bitstreamsRD: RemoteData<PaginatedList<Bitstream>>) => {
const current: Bitstream[] = this.bitstreams$.getValue();
this.bitstreams$.next([...current, ...bitstreamsRD.payload.page]);
this.isLoading = false;
this.isLastPage = hasNoValue(bitstreamsRD.payload.next);
});
}
}