import { Component, Input, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { BitstreamDataService } from '../../../../core/data/bitstream-data.service'; import { Bitstream } from '../../../../core/shared/bitstream.model'; import { Item } from '../../../../core/shared/item.model'; import { followLink } from '../../../../shared/utils/follow-link-config.model'; import { FileSectionComponent } from '../../../simple/field-components/file-section/file-section.component'; import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model'; import { PaginatedList } from '../../../../core/data/paginated-list.model'; import { RemoteData } from '../../../../core/data/remote-data'; import { switchMap, tap } from 'rxjs/operators'; import { NotificationsService } from '../../../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; import { hasValue, isEmpty } from '../../../../shared/empty.util'; import { PaginationService } from '../../../../core/pagination/pagination.service'; /** * This component renders the file section of the item * inside a 'ds-metadata-field-wrapper' component. */ @Component({ selector: 'ds-item-page-full-file-section', styleUrls: ['./full-file-section.component.scss'], templateUrl: './full-file-section.component.html' }) export class FullFileSectionComponent extends FileSectionComponent implements OnInit { @Input() item: Item; label: string; originals$: Observable>>; licenses$: Observable>>; pageSize = 5; originalOptions = Object.assign(new PaginationComponentOptions(), { id: 'obo', currentPage: 1, pageSize: this.pageSize }); licenseOptions = Object.assign(new PaginationComponentOptions(), { id: 'lbo', currentPage: 1, pageSize: this.pageSize }); constructor( bitstreamDataService: BitstreamDataService, protected notificationsService: NotificationsService, protected translateService: TranslateService, protected paginationService: PaginationService ) { super(bitstreamDataService, notificationsService, translateService); } ngOnInit(): void { this.initialize(); } initialize(): void { this.originals$ = this.paginationService.getCurrentPagination(this.originalOptions.id, this.originalOptions).pipe( switchMap((options: PaginationComponentOptions) => this.bitstreamDataService.findAllByItemAndBundleName( this.item, 'ORIGINAL', {elementsPerPage: options.pageSize, currentPage: options.currentPage}, true, true, followLink('format'), followLink('thumbnail'), )), tap((rd: RemoteData>) => { if (hasValue(rd.errorMessage)) { this.notificationsService.error(this.translateService.get('file-section.error.header'), `${rd.statusCode} ${rd.errorMessage}`); } } ) ); this.licenses$ = this.paginationService.getCurrentPagination(this.licenseOptions.id, this.licenseOptions).pipe( switchMap((options: PaginationComponentOptions) => this.bitstreamDataService.findAllByItemAndBundleName( this.item, 'LICENSE', {elementsPerPage: options.pageSize, currentPage: options.currentPage}, true, true, followLink('format'), followLink('thumbnail'), )), tap((rd: RemoteData>) => { if (hasValue(rd.errorMessage)) { this.notificationsService.error(this.translateService.get('file-section.error.header'), `${rd.statusCode} ${rd.errorMessage}`); } } ) ); } hasValuesInBundle(bundle: PaginatedList) { return hasValue(bundle) && !isEmpty(bundle.page); } ngOnDestroy(): void { this.paginationService.clearPagination(this.originalOptions.id); this.paginationService.clearPagination(this.licenseOptions.id); } }