Skip to content

Commit 9aac463

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-8.x
Conflicts: src/app/shared/access-control-form-container/item-access-control-select-bitstreams-modal/item-access-control-select-bitstreams-modal.component.ts
2 parents 60f1007 + c03bbb0 commit 9aac463

3 files changed

Lines changed: 33 additions & 31 deletions

File tree

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

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
@@ -5,14 +5,16 @@ import {
55
import {
66
Component,
77
Input,
8+
OnDestroy,
89
OnInit,
910
} from '@angular/core';
1011
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
1112
import {
1213
TranslateModule,
1314
TranslateService,
1415
} from '@ngx-translate/core';
15-
import { BehaviorSubject } from 'rxjs';
16+
import { Observable } from 'rxjs';
17+
import { switchMap } from 'rxjs/operators';
1618
import { PaginatedList } from 'src/app/core/data/paginated-list.model';
1719
import { RemoteData } from 'src/app/core/data/remote-data';
1820
import { Bitstream } from 'src/app/core/shared/bitstream.model';
@@ -21,8 +23,6 @@ import { Context } from 'src/app/core/shared/context.model';
2123
import { BitstreamDataService } from '../../../core/data/bitstream-data.service';
2224
import { PaginationService } from '../../../core/pagination/pagination.service';
2325
import { Item } from '../../../core/shared/item.model';
24-
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
25-
import { hasValue } from '../../empty.util';
2626
import { ObjectCollectionComponent } from '../../object-collection/object-collection.component';
2727
import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';
2828

@@ -35,43 +35,43 @@ export const ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID = 'item-access-contro
3535
standalone: true,
3636
imports: [NgIf, ObjectCollectionComponent, AsyncPipe, TranslateModule],
3737
})
38-
export class ItemAccessControlSelectBitstreamsModalComponent implements OnInit {
38+
export class ItemAccessControlSelectBitstreamsModalComponent implements OnInit, OnDestroy {
3939

4040
LIST_ID = ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID;
4141

4242
@Input() item!: Item;
4343
@Input() selectedBitstreams: string[] = [];
4444

45-
data$ = new BehaviorSubject<RemoteData<PaginatedList<Bitstream>> | null>(null);
46-
paginationConfig: PaginationComponentOptions;
47-
pageSize = 5;
48-
45+
bitstreams$: Observable<RemoteData<PaginatedList<Bitstream>>>;
4946
context: Context = Context.Bitstream;
5047

48+
paginationConfig = Object.assign(new PaginationComponentOptions(), {
49+
id: 'iacsbm',
50+
currentPage: 1,
51+
pageSize: 5,
52+
});
53+
5154
constructor(
5255
private bitstreamService: BitstreamDataService,
5356
protected paginationService: PaginationService,
5457
protected translateService: TranslateService,
5558
public activeModal: NgbActiveModal,
5659
) { }
5760

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

69-
loadForPage(page: number) {
70-
this.bitstreamService.findAllByItemAndBundleName(this.item, 'ORIGINAL', { currentPage: page }, false)
71-
.pipe(
72-
getFirstCompletedRemoteData(),
73-
)
74-
.subscribe(this.data$);
73+
ngOnDestroy(): void {
74+
this.paginationService.clearPagination(this.paginationConfig.id);
7575
}
7676

7777
}

0 commit comments

Comments
 (0)