mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 23:13:04 +00:00
[Task 72397] implemented the bitstream pagination on simple and full item pages
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user