1- import { Component , Input , OnInit } from '@angular/core' ;
1+ import { Component , Input , OnInit , OnDestroy } from '@angular/core' ;
22import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' ;
3- import { BehaviorSubject } from 'rxjs' ;
3+ import { Observable } from 'rxjs' ;
44import { PaginatedList } from 'src/app/core/data/paginated-list.model' ;
55import { RemoteData } from 'src/app/core/data/remote-data' ;
66import { Bitstream } from 'src/app/core/shared/bitstream.model' ;
@@ -10,8 +10,7 @@ import { Item } from '../../../core/shared/item.model';
1010import { BitstreamDataService } from '../../../core/data/bitstream-data.service' ;
1111import { PaginationService } from '../../../core/pagination/pagination.service' ;
1212import { TranslateService } from '@ngx-translate/core' ;
13- import { hasValue } from '../../empty.util' ;
14- import { getFirstCompletedRemoteData } from '../../../core/shared/operators' ;
13+ import { switchMap } from 'rxjs/operators' ;
1514
1615export const ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID = 'item-access-control-select-bitstreams' ;
1716
@@ -20,43 +19,43 @@ export const ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID = 'item-access-contro
2019 templateUrl : './item-access-control-select-bitstreams-modal.component.html' ,
2120 styleUrls : [ './item-access-control-select-bitstreams-modal.component.scss' ]
2221} )
23- export class ItemAccessControlSelectBitstreamsModalComponent implements OnInit {
22+ export class ItemAccessControlSelectBitstreamsModalComponent implements OnInit , OnDestroy {
2423
2524 LIST_ID = ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID ;
2625
2726 @Input ( ) item ! : Item ;
2827 @Input ( ) selectedBitstreams : string [ ] = [ ] ;
2928
30- data$ = new BehaviorSubject < RemoteData < PaginatedList < Bitstream > > | null > ( null ) ;
31- paginationConfig : PaginationComponentOptions ;
32- pageSize = 5 ;
33-
29+ bitstreams$ : Observable < RemoteData < PaginatedList < Bitstream > > > ;
3430 context : Context = Context . Bitstream ;
3531
32+ paginationConfig = Object . assign ( new PaginationComponentOptions ( ) , {
33+ id : 'iacsbm' ,
34+ currentPage : 1 ,
35+ pageSize : 5
36+ } ) ;
37+
3638 constructor (
3739 private bitstreamService : BitstreamDataService ,
3840 protected paginationService : PaginationService ,
3941 protected translateService : TranslateService ,
4042 public activeModal : NgbActiveModal
4143 ) { }
4244
43- ngOnInit ( ) {
44- this . loadForPage ( 1 ) ;
45-
46- this . paginationConfig = new PaginationComponentOptions ( ) ;
47- this . paginationConfig . id = 'iacsbm' ;
48- this . paginationConfig . currentPage = 1 ;
49- if ( hasValue ( this . pageSize ) ) {
50- this . paginationConfig . pageSize = this . pageSize ;
51- }
45+ ngOnInit ( ) : void {
46+ this . bitstreams$ = this . paginationService . getCurrentPagination ( this . paginationConfig . id , this . paginationConfig ) . pipe (
47+ switchMap ( ( options : PaginationComponentOptions ) => this . bitstreamService . findAllByItemAndBundleName (
48+ this . item ,
49+ 'ORIGINAL' ,
50+ { elementsPerPage : options . pageSize , currentPage : options . currentPage } ,
51+ true ,
52+ true ,
53+ ) )
54+ ) ;
5255 }
5356
54- loadForPage ( page : number ) {
55- this . bitstreamService . findAllByItemAndBundleName ( this . item , 'ORIGINAL' , { currentPage : page } , false )
56- . pipe (
57- getFirstCompletedRemoteData ( ) ,
58- )
59- . subscribe ( this . data$ ) ;
57+ ngOnDestroy ( ) : void {
58+ this . paginationService . clearPagination ( this . paginationConfig . id ) ;
6059 }
6160
6261}
0 commit comments