Skip to content

Commit c03bbb0

Browse files
committed
130081: Fix pagination on 'Select bistreams' modal on 'Access Control' tab
1 parent 404ccd9 commit c03bbb0

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

src/app/shared/access-control-form-container/item-access-control-select-bitstreams-modal/item-access-control-select-bitstreams-modal.component.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ <h4 class="modal-title">
88
</button>
99
</div>
1010
<div class="modal-body">
11-
<ng-container *ngIf="data$ | async as data">
11+
<ng-container *ngIf="bitstreams$ | async as bitstreams">
1212
<ds-viewable-collection
13-
*ngIf="data.payload.page.length > 0"
13+
*ngIf="bitstreams.payload?.page?.length > 0"
1414
[config]="paginationConfig"
1515
[context]="context"
16-
[objects]="data"
16+
[objects]="bitstreams"
1717
[selectable]="true"
1818
[selectionConfig]="{ repeatable: true, listId: LIST_ID }"
19-
[showPaginator]="true"
20-
(pageChange)="loadForPage($event)">
19+
[showPaginator]="true">
2120
</ds-viewable-collection>
2221

23-
<div *ngIf="data && data.payload.page.length === 0"
24-
class="alert alert-info w-100" role="alert">
22+
<div *ngIf="bitstreams && bitstreams.payload?.page?.length === 0"
23+
class="alert alert-info w-100" role="alert">
2524
{{'access-control-select-bitstreams-modal.no-items' | translate}}
2625
</div>
2726

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Component, Input, OnInit } from '@angular/core';
1+
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
22
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
3-
import { BehaviorSubject } from 'rxjs';
3+
import { Observable } from 'rxjs';
44
import { PaginatedList } from 'src/app/core/data/paginated-list.model';
55
import { RemoteData } from 'src/app/core/data/remote-data';
66
import { Bitstream } from 'src/app/core/shared/bitstream.model';
@@ -10,8 +10,7 @@ import { Item } from '../../../core/shared/item.model';
1010
import { BitstreamDataService } from '../../../core/data/bitstream-data.service';
1111
import { PaginationService } from '../../../core/pagination/pagination.service';
1212
import { 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

1615
export 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

Comments
 (0)