Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ <h4 class="modal-title">
</button>
</div>
<div class="modal-body">
@if (data$ | async; as data) {
@if (data.payload.page.length > 0) {
@if (bitstreams$ | async; as bitstreams) {
@if (bitstreams.payload.page.length > 0) {
<ds-viewable-collection
[config]="paginationConfig"
[context]="context"
[objects]="data"
[objects]="bitstreams"
[selectable]="true"
[selectionConfig]="{ repeatable: true, listId: LIST_ID }"
[showPaginator]="true"
(pageChange)="loadForPage($event)">
[showPaginator]="true">
</ds-viewable-collection>
}
@if (data && data.payload.page.length === 0) {
@if (bitstreams && bitstreams.payload.page.length === 0) {
<div
class="alert alert-info w-100" role="alert">
{{'access-control-select-bitstreams-modal.no-items' | translate}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Bitstream } from '../../../core/shared/bitstream.model';
import { Item } from '../../../core/shared/item.model';
import { ObjectCollectionComponent } from '../../object-collection/object-collection.component';
import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils';
import { PaginationServiceStub } from '../../testing/pagination-service.stub';
import { createPaginatedList } from '../../testing/utils.test';
import { FollowLinkConfig } from '../../utils/follow-link-config.model';
import { ItemAccessControlSelectBitstreamsModalComponent } from './item-access-control-select-bitstreams-modal.component';
Expand All @@ -37,6 +38,8 @@ describe('ItemAccessControlSelectBitstreamsModalComponent', () => {
},
};

const mockPaginationService = new PaginationServiceStub();

const translateServiceStub = {
get: () => observableOf('test-message'),
onLangChange: new EventEmitter(),
Expand All @@ -50,7 +53,7 @@ describe('ItemAccessControlSelectBitstreamsModalComponent', () => {
providers: [
NgbActiveModal,
{ provide: BitstreamDataService, useValue: mockBitstreamDataService },
{ provide: PaginationService, useValue: {} },
{ provide: PaginationService, useValue: mockPaginationService },
{ provide: TranslateService, useValue: translateServiceStub },
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { AsyncPipe } from '@angular/common';
import {
Component,
Input,
OnDestroy,
OnInit,
} from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import { BehaviorSubject } from 'rxjs';
import { Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { PaginatedList } from 'src/app/core/data/paginated-list.model';
import { RemoteData } from 'src/app/core/data/remote-data';
import { Bitstream } from 'src/app/core/shared/bitstream.model';
Expand All @@ -18,8 +20,6 @@ import { Context } from 'src/app/core/shared/context.model';
import { BitstreamDataService } from '../../../core/data/bitstream-data.service';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { Item } from '../../../core/shared/item.model';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { hasValue } from '../../empty.util';
import { ObjectCollectionComponent } from '../../object-collection/object-collection.component';
import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';

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

LIST_ID = ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID;

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

data$ = new BehaviorSubject<RemoteData<PaginatedList<Bitstream>> | null>(null);
paginationConfig: PaginationComponentOptions;
pageSize = 5;

bitstreams$: Observable<RemoteData<PaginatedList<Bitstream>>>;
context: Context = Context.Bitstream;

paginationConfig = Object.assign(new PaginationComponentOptions(), {
id: 'iacsbm',
currentPage: 1,
pageSize: 5,
});

constructor(
private bitstreamService: BitstreamDataService,
protected paginationService: PaginationService,
protected translateService: TranslateService,
public activeModal: NgbActiveModal,
) { }

ngOnInit() {
this.loadForPage(1);

this.paginationConfig = new PaginationComponentOptions();
this.paginationConfig.id = 'iacsbm';
this.paginationConfig.currentPage = 1;
if (hasValue(this.pageSize)) {
this.paginationConfig.pageSize = this.pageSize;
}
ngOnInit(): void {
this.bitstreams$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig).pipe(
switchMap((options: PaginationComponentOptions) => this.bitstreamService.findAllByItemAndBundleName(
this.item,
'ORIGINAL',
{ elementsPerPage: options.pageSize, currentPage: options.currentPage },
true,
true,
)),
);
}

loadForPage(page: number) {
this.bitstreamService.findAllByItemAndBundleName(this.item, 'ORIGINAL', { currentPage: page }, false)
.pipe(
getFirstCompletedRemoteData(),
)
.subscribe(this.data$);
ngOnDestroy(): void {
this.paginationService.clearPagination(this.paginationConfig.id);
}

}
Loading