@@ -21,7 +21,6 @@ import {
2121 DynamicFormLayout ,
2222 DynamicFormService ,
2323 DynamicInputModel ,
24- DynamicSelectModel ,
2524} from '@ng-dynamic-forms/core' ;
2625import {
2726 TranslateModule ,
@@ -39,23 +38,24 @@ import {
3938 filter ,
4039 map ,
4140 switchMap ,
41+ take ,
4242 tap ,
4343} from 'rxjs/operators' ;
4444
4545import { DSONameService } from '../../core/breadcrumbs/dso-name.service' ;
46+ import { FindAllDataImpl } from '../../core/data/base/find-all-data' ;
4647import { BitstreamDataService } from '../../core/data/bitstream-data.service' ;
4748import { BitstreamFormatDataService } from '../../core/data/bitstream-format-data.service' ;
48- import { PaginatedList } from '../../core/data/paginated-list.model' ;
4949import { PrimaryBitstreamService } from '../../core/data/primary-bitstream.service' ;
5050import { RemoteData } from '../../core/data/remote-data' ;
5151import { Bitstream } from '../../core/shared/bitstream.model' ;
5252import { BitstreamFormat } from '../../core/shared/bitstream-format.model' ;
53+ import { BITSTREAM_FORMAT } from '../../core/shared/bitstream-format.resource-type' ;
5354import { BitstreamFormatSupportLevel } from '../../core/shared/bitstream-format-support-level' ;
5455import { Bundle } from '../../core/shared/bundle.model' ;
5556import { Item } from '../../core/shared/item.model' ;
5657import { Metadata } from '../../core/shared/metadata.utils' ;
5758import {
58- getAllSucceededRemoteDataPayload ,
5959 getFirstCompletedRemoteData ,
6060 getFirstSucceededRemoteData ,
6161 getFirstSucceededRemoteDataPayload ,
@@ -72,6 +72,7 @@ import { ErrorComponent } from '../../shared/error/error.component';
7272import { DynamicCustomSwitchModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/custom-switch/custom-switch.model' ;
7373import { DsDynamicInputModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model' ;
7474import { DsDynamicTextAreaModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-textarea.model' ;
75+ import { DynamicScrollableDropdownModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.model' ;
7576import { FormComponent } from '../../shared/form/form.component' ;
7677import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component' ;
7778import { NotificationsService } from '../../shared/notifications/notifications.service' ;
@@ -109,12 +110,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
109110 */
110111 bitstreamRD$ : Observable < RemoteData < Bitstream > > ;
111112
112- /**
113- * The formats their remote data observable
114- * Tracks changes and updates the view
115- */
116- bitstreamFormatsRD$ : Observable < RemoteData < PaginatedList < BitstreamFormat > > > ;
117-
118113 /**
119114 * The UUID of the primary bitstream for this bundle
120115 */
@@ -130,11 +125,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
130125 */
131126 originalFormat : BitstreamFormat ;
132127
133- /**
134- * A list of all available bitstream formats
135- */
136- formats : BitstreamFormat [ ] ;
137-
138128 /**
139129 * @type {string } Key prefix used to generate form messages
140130 */
@@ -178,7 +168,10 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
178168 /**
179169 * Options for fetching all bitstream formats
180170 */
181- findAllOptions = { elementsPerPage : 9999 } ;
171+ findAllOptions = {
172+ elementsPerPage : 20 ,
173+ currentPage : 1 ,
174+ } ;
182175
183176 /**
184177 * The Dynamic Input Model for the file's name
@@ -218,9 +211,22 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
218211 /**
219212 * The Dynamic Input Model for the selected format
220213 */
221- selectedFormatModel = new DynamicSelectModel ( {
214+ selectedFormatModel = new DynamicScrollableDropdownModel ( {
222215 id : 'selectedFormat' ,
223216 name : 'selectedFormat' ,
217+ displayKey : 'shortDescription' ,
218+ repeatable : false ,
219+ metadataFields : [ ] ,
220+ submissionId : '' ,
221+ hasSelectableMetadata : false ,
222+ resourceType : BITSTREAM_FORMAT ,
223+ formatFunction : ( format : BitstreamFormat | string ) => {
224+ if ( format instanceof BitstreamFormat ) {
225+ return hasValue ( format ) && format . supportLevel === BitstreamFormatSupportLevel . Unknown ? this . translate . instant ( this . KEY_PREFIX + 'selectedFormat.unknown' ) : format . shortDescription ;
226+ } else {
227+ return format ;
228+ }
229+ } ,
224230 } ) ;
225231
226232 /**
@@ -438,6 +444,11 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
438444 * @private
439445 */
440446 private bundle : Bundle ;
447+ /**
448+ * The currently selected format
449+ * @private
450+ */
451+ private selectedFormat : BitstreamFormat ;
441452
442453 constructor ( private route : ActivatedRoute ,
443454 private router : Router ,
@@ -463,18 +474,12 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
463474 this . itemId = this . route . snapshot . queryParams . itemId ;
464475 this . entityType = this . route . snapshot . queryParams . entityType ;
465476 this . bitstreamRD$ = this . route . data . pipe ( map ( ( data : any ) => data . bitstream ) ) ;
466- this . bitstreamFormatsRD$ = this . bitstreamFormatService . findAll ( this . findAllOptions ) ;
467477
468478 const bitstream$ = this . bitstreamRD$ . pipe (
469479 getFirstSucceededRemoteData ( ) ,
470480 getRemoteDataPayload ( ) ,
471481 ) ;
472482
473- const allFormats$ = this . bitstreamFormatsRD$ . pipe (
474- getFirstSucceededRemoteData ( ) ,
475- getRemoteDataPayload ( ) ,
476- ) ;
477-
478483 const bundle$ = bitstream$ . pipe (
479484 switchMap ( ( bitstream : Bitstream ) => bitstream . bundle ) ,
480485 getFirstSucceededRemoteDataPayload ( ) ,
@@ -490,24 +495,31 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
490495 switchMap ( ( bundle : Bundle ) => bundle . item ) ,
491496 getFirstSucceededRemoteDataPayload ( ) ,
492497 ) ;
498+ const format$ = bitstream$ . pipe (
499+ switchMap ( bitstream => bitstream . format ) ,
500+ getFirstSucceededRemoteDataPayload ( ) ,
501+ ) ;
502+
493503 this . subs . push (
494504 observableCombineLatest (
495505 bitstream$ ,
496- allFormats$ ,
497506 bundle$ ,
498507 primaryBitstream$ ,
499508 item$ ,
500- ) . pipe ( )
501- . subscribe ( ( [ bitstream , allFormats , bundle , primaryBitstream , item ] ) => {
502- this . bitstream = bitstream as Bitstream ;
503- this . formats = allFormats . page ;
504- this . bundle = bundle ;
505- // hasValue(primaryBitstream) because if there's no primaryBitstream on the bundle it will
506- // be a success response, but empty
507- this . primaryBitstreamUUID = hasValue ( primaryBitstream ) ? primaryBitstream . uuid : null ;
508- this . itemId = item . uuid ;
509- this . setIiifStatus ( this . bitstream ) ;
510- } ) ,
509+ format$ ,
510+ ) . subscribe ( ( [ bitstream , bundle , primaryBitstream , item , format ] ) => {
511+ this . bitstream = bitstream as Bitstream ;
512+ this . bundle = bundle ;
513+ this . selectedFormat = format ;
514+ // hasValue(primaryBitstream) because if there's no primaryBitstream on the bundle it will
515+ // be a success response, but empty
516+ this . primaryBitstreamUUID = hasValue ( primaryBitstream ) ? primaryBitstream . uuid : null ;
517+ this . itemId = item . uuid ;
518+ this . setIiifStatus ( this . bitstream ) ;
519+ } ) ,
520+ format$ . pipe ( take ( 1 ) ) . subscribe (
521+ ( format ) => this . originalFormat = format ,
522+ ) ,
511523 ) ;
512524
513525 this . subs . push (
@@ -523,7 +535,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
523535 */
524536 setForm ( ) {
525537 this . formGroup = this . formService . createFormGroup ( this . formModel ) ;
526- this . updateFormatModel ( ) ;
527538 this . updateForm ( this . bitstream ) ;
528539 this . updateFieldTranslations ( ) ;
529540 }
@@ -542,6 +553,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
542553 description : bitstream . firstMetadataValue ( 'dc.description' ) ,
543554 } ,
544555 formatContainer : {
556+ selectedFormat : this . selectedFormat . shortDescription ,
545557 newFormat : hasValue ( bitstream . firstMetadata ( 'dc.format' ) ) ? bitstream . firstMetadata ( 'dc.format' ) . value : undefined ,
546558 } ,
547559 } ) ;
@@ -561,36 +573,16 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
561573 } ,
562574 } ) ;
563575 }
564- this . bitstream . format . pipe (
565- getAllSucceededRemoteDataPayload ( ) ,
566- ) . subscribe ( ( format : BitstreamFormat ) => {
567- this . originalFormat = format ;
568- this . formGroup . patchValue ( {
569- formatContainer : {
570- selectedFormat : format . id ,
571- } ,
572- } ) ;
573- this . updateNewFormatLayout ( format . id ) ;
574- } ) ;
576+ this . updateNewFormatLayout ( ) ;
575577 }
576578
577- /**
578- * Create the list of unknown format IDs an add options to the selectedFormatModel
579- */
580- updateFormatModel ( ) {
581- this . selectedFormatModel . options = this . formats . map ( ( format : BitstreamFormat ) =>
582- Object . assign ( {
583- value : format . id ,
584- label : this . isUnknownFormat ( format . id ) ? this . translate . instant ( this . KEY_PREFIX + 'selectedFormat.unknown' ) : format . shortDescription ,
585- } ) ) ;
586- }
587579
588580 /**
589581 * Update the layout of the "Other Format" input depending on the selected format
590582 * @param selectedId
591583 */
592- updateNewFormatLayout ( selectedId : string ) {
593- if ( this . isUnknownFormat ( selectedId ) ) {
584+ updateNewFormatLayout ( ) {
585+ if ( this . isUnknownFormat ( ) ) {
594586 this . formLayout . newFormat . grid . host = this . newFormatBaseLayout ;
595587 } else {
596588 this . formLayout . newFormat . grid . host = this . newFormatBaseLayout + ' invisible' ;
@@ -601,9 +593,8 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
601593 * Is the provided format (id) part of the list of unknown formats?
602594 * @param id
603595 */
604- isUnknownFormat ( id : string ) : boolean {
605- const format = this . formats . find ( ( f : BitstreamFormat ) => f . id === id ) ;
606- return hasValue ( format ) && format . supportLevel === BitstreamFormatSupportLevel . Unknown ;
596+ isUnknownFormat ( ) : boolean {
597+ return hasValue ( this . selectedFormat ) && this . selectedFormat . supportLevel === BitstreamFormatSupportLevel . Unknown ;
607598 }
608599
609600 /**
@@ -635,7 +626,8 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
635626 onChange ( event ) {
636627 const model = event . model ;
637628 if ( model . id === this . selectedFormatModel . id ) {
638- this . updateNewFormatLayout ( model . value ) ;
629+ this . selectedFormat = model . value ;
630+ this . updateNewFormatLayout ( ) ;
639631 }
640632 }
641633
@@ -645,8 +637,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
645637 onSubmit ( ) {
646638 const updatedValues = this . formGroup . getRawValue ( ) ;
647639 const updatedBitstream = this . formToBitstream ( updatedValues ) ;
648- const selectedFormat = this . formats . find ( ( f : BitstreamFormat ) => f . id === updatedValues . formatContainer . selectedFormat ) ;
649- const isNewFormat = selectedFormat . id !== this . originalFormat . id ;
640+ const isNewFormat = this . selectedFormat . id !== this . originalFormat . id ;
650641 const isPrimary = updatedValues . fileNamePrimaryContainer . primaryBitstream ;
651642 const wasPrimary = this . primaryBitstreamUUID === this . bitstream . uuid ;
652643
@@ -698,7 +689,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
698689 bundle$ = observableOf ( this . bundle ) ;
699690 }
700691 if ( isNewFormat ) {
701- bitstream$ = this . bitstreamService . updateFormat ( this . bitstream , selectedFormat ) . pipe (
692+ bitstream$ = this . bitstreamService . updateFormat ( this . bitstream , this . selectedFormat ) . pipe (
702693 getFirstCompletedRemoteData ( ) ,
703694 map ( ( formatResponse : RemoteData < Bitstream > ) => {
704695 if ( hasValue ( formatResponse ) && formatResponse . hasFailed ) {
@@ -856,4 +847,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
856847 . forEach ( ( subscription ) => subscription . unsubscribe ( ) ) ;
857848 }
858849
850+ findAllFormatsServiceFactory ( ) {
851+ return ( ) => this . bitstreamFormatService as any as FindAllDataImpl < BitstreamFormat > ;
852+ }
859853}
0 commit comments