From 4fbf99a4513690df6a5789d94440d991f30a919f Mon Sep 17 00:00:00 2001 From: Michael Spalti Date: Fri, 17 Dec 2021 10:14:39 -0800 Subject: [PATCH] Added change detection to assure the form updates. --- .../edit-bitstream-page.component.ts | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts b/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts index bc724bc408..9aeadb6192 100644 --- a/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts +++ b/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts @@ -1,4 +1,10 @@ -import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; +import { + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + OnDestroy, + OnInit +} from '@angular/core'; import { Bitstream } from '../../core/shared/bitstream.model'; import { ActivatedRoute, Router } from '@angular/router'; import { filter, map, mergeMap, switchMap } from 'rxjs/operators'; @@ -355,8 +361,10 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { */ protected subs: Subscription[] = []; + constructor(private route: ActivatedRoute, private router: Router, + private changeDetectorRef: ChangeDetectorRef, private location: Location, private formService: DynamicFormService, private translate: TranslateService, @@ -397,9 +405,9 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { ).subscribe(([bitstream, allFormats]) => { this.bitstream = bitstream as Bitstream; this.formats = allFormats.page; + this.setIiifStatus(this.bitstream); // testing this.updateFormatModel(); this.updateForm(this.bitstream); - this.setIiifStatus(this.bitstream); }) ); @@ -601,13 +609,17 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { } /** - * Checks bitstream mimetype to be sure it's an image, excludes bitstreams in the OTHERCONTENT bundle - * since even if the bitstream is an image it will not be displayed within the viewer, - * and finally verifies that the parent item itself is iiif-enabled. + * Checks bitstream mimetype to be sure it's an image, excludes any bitstream in the + * THUMBNAIL bundle or in the OTHERCONTENT bundle since in that case the image bitstream + * it will never be displayed in the viewer, and last verifies that the parent item + * is iiif-enabled. * @param bitstream */ setIiifStatus(bitstream: Bitstream) { + const regexExcludeBundles = /OTHERCONTENT|THUMBNAIL/; + const regexIIIFItem = /(true|yes)/i; + const iiifCheck$ = this.bitstream.format.pipe( getFirstSucceededRemoteData(), filter((format: RemoteData) => format.payload.mimetype.includes('image/')), @@ -615,14 +627,13 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { this.bitstream.bundle.pipe( getFirstSucceededRemoteData(), filter((bundle: RemoteData) => - this.dsoNameService.getName(bundle.payload) !== 'OTHERCONTENT'), + this.dsoNameService.getName(bundle.payload).match(regexExcludeBundles) == null), mergeMap((bundle: RemoteData) => bundle.payload.item.pipe( getFirstSucceededRemoteData(), - map((remoteData: RemoteData) => { - const regex = /(true|yes)/i; - return (remoteData.payload.firstMetadataValue('dspace.iiif.enabled') && - remoteData.payload.firstMetadataValue('dspace.iiif.enabled').match(regex) !== null); - }) + map((remoteData: RemoteData) => + (remoteData.payload.firstMetadataValue('dspace.iiif.enabled') && + remoteData.payload.firstMetadataValue('dspace.iiif.enabled').match(regexIIIFItem) !== null) + ) )) ) ) @@ -650,6 +661,8 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { iiifHeight: bitstream.firstMetadataValue('iiif.image.height') } }); + // Assure that the form always detects the iiif addition. + this.changeDetectorRef.detectChanges(); } });