Skip to content

Commit ac716c4

Browse files
committed
Single form initialization.
1 parent 94b2f53 commit ac716c4

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h3>{{bitstreamRD?.payload?.name}} <span class="text-muted">({{bitstreamRD?.payl
1212
</div>
1313
</div>
1414
</div>
15-
<ds-form [formId]="'edit-bitstream-form-id'"
15+
<ds-form *ngIf="formGroup" [formId]="'edit-bitstream-form-id'"
1616
[formGroup]="formGroup"
1717
[formModel]="formModel"
1818
[formLayout]="formLayout"

src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ import {
77
} from '@angular/core';
88
import { Bitstream } from '../../core/shared/bitstream.model';
99
import { 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';
1218
import {
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 = /OTHERCONTENT|THUMBNAIL/;
685+
const regexExcludeBundles = /OTHERCONTENT|THUMBNAIL|LICENSE/;
681686
const regexIIIFItem = /true|yes/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

Comments
 (0)