|
| 1 | +import { AsyncPipe } from '@angular/common'; |
| 2 | +import { |
| 3 | + Component, |
| 4 | + Inject, |
| 5 | + Input, |
| 6 | + OnInit, |
| 7 | +} from '@angular/core'; |
| 8 | +import { |
| 9 | + APP_CONFIG, |
| 10 | + AppConfig, |
| 11 | +} from '@dspace/config/app-config.interface'; |
| 12 | +import { DSONameService } from '@dspace/core/breadcrumbs/dso-name.service'; |
| 13 | +import { BitstreamDataService } from '@dspace/core/data/bitstream-data.service'; |
| 14 | +import { BitstreamFormatDataService } from '@dspace/core/data/bitstream-format-data.service'; |
| 15 | +import { PaginatedList } from '@dspace/core/data/paginated-list.model'; |
| 16 | +import { RemoteData } from '@dspace/core/data/remote-data'; |
| 17 | +import { PaginationService } from '@dspace/core/pagination/pagination.service'; |
| 18 | +import { PaginationComponentOptions } from '@dspace/core/pagination/pagination-component-options.model'; |
| 19 | +import { Bitstream } from '@dspace/core/shared/bitstream.model'; |
| 20 | +import { followLink } from '@dspace/core/shared/follow-link-config.model'; |
| 21 | +import { Item } from '@dspace/core/shared/item.model'; |
| 22 | +import { TranslatePipe } from '@ngx-translate/core'; |
| 23 | +import { |
| 24 | + from, |
| 25 | + Observable, |
| 26 | +} from 'rxjs'; |
| 27 | +import { switchMap } from 'rxjs/operators'; |
| 28 | + |
| 29 | +import { ThemedFileDownloadLinkComponent } from '../../../../shared/file-download-link/themed-file-download-link.component'; |
| 30 | +import { PaginationComponent } from '../../../../shared/pagination/pagination.component'; |
| 31 | +import { FileSizePipe } from '../../../../shared/utils/file-size-pipe'; |
| 32 | +import { VarDirective } from '../../../../shared/utils/var.directive'; |
| 33 | + |
| 34 | +@Component({ |
| 35 | + selector: 'ds-extended-file-section', |
| 36 | + imports: [ |
| 37 | + AsyncPipe, |
| 38 | + FileSizePipe, |
| 39 | + PaginationComponent, |
| 40 | + ThemedFileDownloadLinkComponent, |
| 41 | + TranslatePipe, |
| 42 | + VarDirective, |
| 43 | + ], |
| 44 | + templateUrl: './extended-file-section.component.html', |
| 45 | + styleUrl: './extended-file-section.component.scss', |
| 46 | +}) |
| 47 | +export class ExtendedFileSectionComponent implements OnInit { |
| 48 | + |
| 49 | + @Input() item: Item; |
| 50 | + |
| 51 | + @Input() bundleName = 'ORIGINAL'; |
| 52 | + |
| 53 | + @Input() label = 'item.page.extended-file-section'; |
| 54 | + |
| 55 | + pageSize = 10; |
| 56 | + |
| 57 | + bitstreamsRD$: Observable<RemoteData<PaginatedList<Bitstream>>>; |
| 58 | + |
| 59 | + |
| 60 | + /** |
| 61 | + * The current pagination configuration for the page |
| 62 | + */ |
| 63 | + pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { |
| 64 | + id: 'afs', |
| 65 | + pageSize: this.pageSize, |
| 66 | + pageSizeOptions: [10, 20, 40, 60, 80, 100], |
| 67 | + }); |
| 68 | + |
| 69 | + |
| 70 | + constructor( |
| 71 | + protected bitstreamDataService: BitstreamDataService, |
| 72 | + protected bitstreamFormatDataService: BitstreamFormatDataService, |
| 73 | + public dsoNameService: DSONameService, |
| 74 | + @Inject(APP_CONFIG) protected appConfig: AppConfig, |
| 75 | + private paginationService: PaginationService, |
| 76 | + ) { |
| 77 | + this.pageSize = appConfig.item.bitstream.pageSize; |
| 78 | + this.bitstreamsRD$ = from([]); |
| 79 | + } |
| 80 | + |
| 81 | + ngOnInit(): void { |
| 82 | + this.bitstreamsRD$ = this.paginationService.getCurrentPagination(this.pageConfig.id, this.pageConfig).pipe( |
| 83 | + switchMap((options: PaginationComponentOptions) => { |
| 84 | + return this.bitstreamDataService.findAllByItemAndBundleName( |
| 85 | + this.item, |
| 86 | + this.bundleName, |
| 87 | + { elementsPerPage: options.pageSize, currentPage: options.currentPage }, |
| 88 | + true, |
| 89 | + true, |
| 90 | + followLink('format'), |
| 91 | + followLink('accessStatus'), |
| 92 | + ); |
| 93 | + }), |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | +} |
0 commit comments