Skip to content

Commit 8f52250

Browse files
committed
Merge remote-tracking branch 'contributions/w2p-130081_access-control-bitstreams-pagination-fix-7.6' into w2p-130081_access-control-bitstreams-pagination-fix-main
Conflicts: src/app/shared/access-control-form-container/item-access-control-select-bitstreams-modal/item-access-control-select-bitstreams-modal.component.html src/app/shared/access-control-form-container/item-access-control-select-bitstreams-modal/item-access-control-select-bitstreams-modal.component.ts
2 parents bd4c6d6 + c03bbb0 commit 8f52250

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ <h4 class="modal-title">
77
</button>
88
</div>
99
<div class="modal-body">
10-
@if (data$ | async; as data) {
11-
@if (data.payload.page.length > 0) {
10+
@if (bitstreams$ | async; as bitstreams) {
11+
@if (bitstreams.payload.page.length > 0) {
1212
<ds-viewable-collection
1313
[config]="paginationConfig"
1414
[context]="context"
15-
[objects]="data"
15+
[objects]="bitstreams"
1616
[selectable]="true"
1717
[selectionConfig]="{ repeatable: true, listId: LIST_ID }"
18-
[showPaginator]="true"
19-
(pageChange)="loadForPage($event)">
18+
[showPaginator]="true">
2019
</ds-viewable-collection>
2120
}
22-
@if (data && data.payload.page.length === 0) {
21+
@if (bitstreams && bitstreams.payload.page.length === 0) {
2322
<div
2423
class="alert alert-info w-100" role="alert">
2524
{{'access-control-select-bitstreams-modal.no-items' | translate}}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Bitstream } from '../../../core/shared/bitstream.model';
2323
import { Item } from '../../../core/shared/item.model';
2424
import { ObjectCollectionComponent } from '../../object-collection/object-collection.component';
2525
import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils';
26+
import { PaginationServiceStub } from '../../testing/pagination-service.stub';
2627
import { createPaginatedList } from '../../testing/utils.test';
2728
import { FollowLinkConfig } from '../../utils/follow-link-config.model';
2829
import { ItemAccessControlSelectBitstreamsModalComponent } from './item-access-control-select-bitstreams-modal.component';
@@ -37,6 +38,8 @@ describe('ItemAccessControlSelectBitstreamsModalComponent', () => {
3738
},
3839
};
3940

41+
const mockPaginationService = new PaginationServiceStub();
42+
4043
const translateServiceStub = {
4144
get: () => observableOf('test-message'),
4245
onLangChange: new EventEmitter(),
@@ -50,7 +53,7 @@ describe('ItemAccessControlSelectBitstreamsModalComponent', () => {
5053
providers: [
5154
NgbActiveModal,
5255
{ provide: BitstreamDataService, useValue: mockBitstreamDataService },
53-
{ provide: PaginationService, useValue: {} },
56+
{ provide: PaginationService, useValue: mockPaginationService },
5457
{ provide: TranslateService, useValue: translateServiceStub },
5558
],
5659
})

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { AsyncPipe } from '@angular/common';
22
import {
33
Component,
44
Input,
5+
OnDestroy,
56
OnInit,
67
} from '@angular/core';
78
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
89
import {
910
TranslateModule,
1011
TranslateService,
1112
} from '@ngx-translate/core';
12-
import { BehaviorSubject } from 'rxjs';
13+
import { Observable } from 'rxjs';
14+
import { switchMap } from 'rxjs/operators';
1315
import { PaginatedList } from 'src/app/core/data/paginated-list.model';
1416
import { RemoteData } from 'src/app/core/data/remote-data';
1517
import { Bitstream } from 'src/app/core/shared/bitstream.model';
@@ -18,8 +20,6 @@ import { Context } from 'src/app/core/shared/context.model';
1820
import { BitstreamDataService } from '../../../core/data/bitstream-data.service';
1921
import { PaginationService } from '../../../core/pagination/pagination.service';
2022
import { Item } from '../../../core/shared/item.model';
21-
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
22-
import { hasValue } from '../../empty.util';
2323
import { ObjectCollectionComponent } from '../../object-collection/object-collection.component';
2424
import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';
2525

@@ -32,43 +32,43 @@ export const ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID = 'item-access-contro
3232
standalone: true,
3333
imports: [ObjectCollectionComponent, AsyncPipe, TranslateModule],
3434
})
35-
export class ItemAccessControlSelectBitstreamsModalComponent implements OnInit {
35+
export class ItemAccessControlSelectBitstreamsModalComponent implements OnInit, OnDestroy {
3636

3737
LIST_ID = ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID;
3838

3939
@Input() item!: Item;
4040
@Input() selectedBitstreams: string[] = [];
4141

42-
data$ = new BehaviorSubject<RemoteData<PaginatedList<Bitstream>> | null>(null);
43-
paginationConfig: PaginationComponentOptions;
44-
pageSize = 5;
45-
42+
bitstreams$: Observable<RemoteData<PaginatedList<Bitstream>>>;
4643
context: Context = Context.Bitstream;
4744

45+
paginationConfig = Object.assign(new PaginationComponentOptions(), {
46+
id: 'iacsbm',
47+
currentPage: 1,
48+
pageSize: 5,
49+
});
50+
4851
constructor(
4952
private bitstreamService: BitstreamDataService,
5053
protected paginationService: PaginationService,
5154
protected translateService: TranslateService,
5255
public activeModal: NgbActiveModal,
5356
) { }
5457

55-
ngOnInit() {
56-
this.loadForPage(1);
57-
58-
this.paginationConfig = new PaginationComponentOptions();
59-
this.paginationConfig.id = 'iacsbm';
60-
this.paginationConfig.currentPage = 1;
61-
if (hasValue(this.pageSize)) {
62-
this.paginationConfig.pageSize = this.pageSize;
63-
}
58+
ngOnInit(): void {
59+
this.bitstreams$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig).pipe(
60+
switchMap((options: PaginationComponentOptions) => this.bitstreamService.findAllByItemAndBundleName(
61+
this.item,
62+
'ORIGINAL',
63+
{ elementsPerPage: options.pageSize, currentPage: options.currentPage },
64+
true,
65+
true,
66+
)),
67+
);
6468
}
6569

66-
loadForPage(page: number) {
67-
this.bitstreamService.findAllByItemAndBundleName(this.item, 'ORIGINAL', { currentPage: page }, false)
68-
.pipe(
69-
getFirstCompletedRemoteData(),
70-
)
71-
.subscribe(this.data$);
70+
ngOnDestroy(): void {
71+
this.paginationService.clearPagination(this.paginationConfig.id);
7272
}
7373

7474
}

0 commit comments

Comments
 (0)