@@ -7,8 +7,14 @@ import {
77} from '@angular/core' ;
88import { Bitstream } from '../../core/shared/bitstream.model' ;
99import { ActivatedRoute , Router } from '@angular/router' ;
10- import { filter , map , mergeMap , switchMap } from 'rxjs/operators' ;
11- import { combineLatest as observableCombineLatest , Observable , of as observableOf , Subscription } from 'rxjs' ;
10+ import { map , mergeMap , switchMap } from 'rxjs/operators' ;
11+ import {
12+ combineLatest ,
13+ combineLatest as observableCombineLatest ,
14+ Observable ,
15+ of as observableOf ,
16+ Subscription
17+ } from 'rxjs' ;
1218import {
1319 DynamicFormControlModel ,
1420 DynamicFormGroupModel ,
@@ -424,7 +430,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
424430 ) . subscribe ( ( [ bitstream , allFormats ] ) => {
425431 this . bitstream = bitstream as Bitstream ;
426432 this . formats = allFormats . page ;
427- this . setForm ( ) ;
428433 this . setIiifStatus ( this . bitstream ) ;
429434 } )
430435 ) ;
@@ -677,31 +682,33 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
677682 */
678683 setIiifStatus ( bitstream : Bitstream ) {
679684
680- const regexExcludeBundles = / O T H E R C O N T E N T | T H U M B N A I L / ;
685+ const regexExcludeBundles = / O T H E R C O N T E N T | T H U M B N A I L | L I C E N S E / ;
681686 const regexIIIFItem = / t r u e | y e s / i;
682687
683- const iiifCheck $ = this . bitstream . format . pipe (
688+ const isImage $ = this . bitstream . format . pipe (
684689 getFirstSucceededRemoteData ( ) ,
685- filter ( ( format : RemoteData < BitstreamFormat > ) => format . payload . mimetype . includes ( 'image/' ) ) ,
686- mergeMap ( ( ) =>
687- this . bitstream . bundle . pipe (
688- getFirstSucceededRemoteData ( ) ,
689- filter ( ( bundle : RemoteData < Bundle > ) =>
690- this . dsoNameService . getName ( bundle . payload ) . match ( regexExcludeBundles ) == null ) ,
691- mergeMap ( ( bundle : RemoteData < Bundle > ) => bundle . payload . item . pipe (
692- getFirstSucceededRemoteData ( ) ,
693- map ( ( remoteData : RemoteData < Item > ) =>
694- ( remoteData . payload . firstMetadataValue ( 'dspace.iiif.enabled' ) &&
695- remoteData . payload . firstMetadataValue ( 'dspace.iiif.enabled' ) . match ( regexIIIFItem ) !== null )
696- )
697- ) )
698- )
699- )
700- ) ;
690+ map ( ( format : RemoteData < BitstreamFormat > ) => format . payload . mimetype . includes ( 'image/' ) ) ) ;
701691
702- // If iiifCheck$ returns true, enable the IIIF form elements.
703- const iiifSub = iiifCheck$ . subscribe ( ( iiif : boolean ) => {
704- if ( iiif ) {
692+ const isIIIFBundle$ = this . bitstream . bundle . pipe (
693+ getFirstSucceededRemoteData ( ) ,
694+ map ( ( bundle : RemoteData < Bundle > ) =>
695+ this . dsoNameService . getName ( bundle . payload ) . match ( regexExcludeBundles ) == null ) ) ;
696+
697+ const isEnabled$ = this . bitstream . bundle . pipe (
698+ getFirstSucceededRemoteData ( ) ,
699+ map ( ( bundle : RemoteData < Bundle > ) => bundle . payload . item . pipe (
700+ getFirstSucceededRemoteData ( ) ,
701+ map ( ( item : RemoteData < Item > ) =>
702+ ( item . payload . firstMetadataValue ( 'dspace.iiif.enabled' ) &&
703+ item . payload . firstMetadataValue ( 'dspace.iiif.enabled' ) . match ( regexIIIFItem ) !== null )
704+ ) ) ) ) ;
705+
706+ const iiifSub = combineLatest (
707+ isImage$ ,
708+ isIIIFBundle$ ,
709+ isEnabled$
710+ ) . subscribe ( ( [ isImage , isIIIFBundle , isEnabled ] ) => {
711+ if ( isImage && isIIIFBundle && isEnabled ) {
705712 this . isIIIF = true ;
706713 this . inputModels . push ( this . iiifLabelModel ) ;
707714 this . formModel . push ( this . iiifLabelContainer ) ;
@@ -711,10 +718,9 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
711718 this . formModel . push ( this . iiifWidthContainer ) ;
712719 this . inputModels . push ( this . iiifHeightModel ) ;
713720 this . formModel . push ( this . iiifHeightContainer ) ;
714- // re-initialize the form and detect the change.
715- this . setForm ( ) ;
716- this . changeDetectorRef . detectChanges ( ) ;
717721 }
722+ this . setForm ( ) ;
723+ this . changeDetectorRef . detectChanges ( ) ;
718724 } ) ;
719725
720726 this . subs . push ( iiifSub ) ;
0 commit comments