11import {
2- ChangeDetectorRef ,
3- Component ,
4- Input ,
5- OnChanges ,
6- OnDestroy ,
7- OnInit ,
8- SimpleChanges ,
9- ViewChild
2+ ChangeDetectorRef ,
3+ Component ,
4+ Input ,
5+ OnChanges ,
6+ OnDestroy ,
7+ OnInit ,
8+ SimpleChanges ,
9+ ViewChild
1010} from '@angular/core' ;
1111
12- import { BehaviorSubject , Subscription } from 'rxjs' ;
13- import { filter } from 'rxjs/operators' ;
12+ import { BehaviorSubject , Observable , of , Subscription } from 'rxjs' ;
13+ import { filter , map , take } from 'rxjs/operators' ;
1414import { DynamicFormControlModel , } from '@ng-dynamic-forms/core' ;
1515import { NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
1616
@@ -27,6 +27,12 @@ import { SubmissionJsonPatchOperationsService } from '../../../../core/submissio
2727import { SubmissionSectionUploadFileEditComponent } from './edit/section-upload-file-edit.component' ;
2828import { Bitstream } from '../../../../core/shared/bitstream.model' ;
2929import { NgbModalOptions } from '@ng-bootstrap/ng-bootstrap/modal/modal-config' ;
30+ import { VocabularyService } from '../../../../core/submission/vocabularies/vocabulary.service' ;
31+ import {
32+ getFirstCompletedRemoteData ,
33+ getPaginatedListPayload ,
34+ getRemoteDataPayload
35+ } from '../../../../core/shared/operators' ;
3036
3137/**
3238 * This component represents a single bitstream contained in the submission
@@ -137,6 +143,12 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit,
137143 */
138144 public formModel : DynamicFormControlModel [ ] ;
139145
146+
147+ /**
148+ * The translated dc.type of the file
149+ */
150+ public vocabularyFileType$ : Observable < string > ;
151+
140152 /**
141153 * A boolean representing if a submission delete operation is pending
142154 * @type {BehaviorSubject<boolean> }
@@ -172,6 +184,7 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit,
172184 * @param {SubmissionJsonPatchOperationsService } operationsService
173185 * @param {SubmissionService } submissionService
174186 * @param {SectionUploadService } uploadService
187+ * @param vocabularyService
175188 */
176189 constructor (
177190 private cdr : ChangeDetectorRef ,
@@ -182,6 +195,7 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit,
182195 private operationsService : SubmissionJsonPatchOperationsService ,
183196 private submissionService : SubmissionService ,
184197 private uploadService : SectionUploadService ,
198+ private vocabularyService : VocabularyService ,
185199 ) {
186200 this . readMode = true ;
187201 }
@@ -197,9 +211,17 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit,
197211 . getFileData ( this . submissionId , this . sectionId , this . fileId )
198212 . pipe ( filter ( ( bitstream ) => isNotUndefined ( bitstream ) ) )
199213 . subscribe ( ( bitstream ) => {
200- this . fileData = bitstream ;
201- }
202- )
214+ this . fileData = bitstream ;
215+ const fileType = this . fileData . metadata [ 'dc.type' ] ?. map ( data => data . value ) [ 0 ] ;
216+ this . vocabularyFileType$ = ! hasValue ( fileType ) ? of ( null ) : this . vocabularyService . getPublicVocabularyEntryByValue ( 'bitstream_types' , fileType ) . pipe (
217+ getFirstCompletedRemoteData ( ) ,
218+ getRemoteDataPayload ( ) ,
219+ getPaginatedListPayload ( ) ,
220+ map ( ( res ) => res ?. length > 0 ? res [ 0 ] : null ) ,
221+ map ( ( res ) => res ?. display ?? res ?. value ) ,
222+ take ( 1 )
223+ ) ;
224+ } )
203225 ) ;
204226 }
205227 }
@@ -272,12 +294,12 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit,
272294
273295 protected loadFormMetadata ( ) {
274296 this . configMetadataForm . rows . forEach ( ( row ) => {
275- row . fields . forEach ( ( field ) => {
276- field . selectableMetadata . forEach ( ( metadatum ) => {
277- this . formMetadata . push ( metadatum . metadata ) ;
297+ row . fields . forEach ( ( field ) => {
298+ field . selectableMetadata . forEach ( ( metadatum ) => {
299+ this . formMetadata . push ( metadatum . metadata ) ;
300+ } ) ;
278301 } ) ;
279- } ) ;
280- }
302+ }
281303 ) ;
282304 }
283305
0 commit comments