@@ -10,8 +10,9 @@ import { ActivatedRoute, Router } from '@angular/router';
1010import { filter , map , mergeMap , switchMap } from 'rxjs/operators' ;
1111import { combineLatest as observableCombineLatest , Observable , of as observableOf , Subscription } from 'rxjs' ;
1212import {
13+ DynamicFormControlLayout ,
1314 DynamicFormControlModel ,
14- DynamicFormGroupModel ,
15+ DynamicFormGroupModel , DynamicFormGroupModelConfig ,
1516 DynamicFormLayout ,
1617 DynamicFormService ,
1718 DynamicInputModel ,
@@ -42,8 +43,13 @@ import { getEntityEditRoute, getItemEditRoute } from '../../item-page/item-page-
4243import { Bundle } from '../../core/shared/bundle.model' ;
4344import { DSONameService } from '../../core/breadcrumbs/dso-name.service' ;
4445import { Item } from '../../core/shared/item.model' ;
45- import { DsDynamicInputModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model' ;
46+ import {
47+ DsDynamicInputModel ,
48+ DsDynamicInputModelConfig
49+ } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model' ;
4650import { DsDynamicTextAreaModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-textarea.model' ;
51+ import { Simulate } from 'react-dom/test-utils' ;
52+ import input = Simulate . input ;
4753
4854@Component ( {
4955 selector : 'ds-edit-bitstream-page' ,
@@ -148,9 +154,10 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
148154 * The Dynamic Switch Model for the file's name
149155 */
150156 primaryBitstreamModel = new DynamicCustomSwitchModel ( {
151- id : 'primaryBitstream' ,
152- name : 'primaryBitstream'
153- } ) ;
157+ id : 'primaryBitstream' ,
158+ name : 'primaryBitstream'
159+ }
160+ ) ;
154161
155162 /**
156163 * The Dynamic TextArea Model for the file's description
@@ -185,31 +192,80 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
185192 hasSelectableMetadata : false , metadataFields : [ ] , repeatable : false , submissionId : '' ,
186193 id : 'iiifLabel' ,
187194 name : 'iiifLabel'
195+ } ,
196+ {
197+ grid : {
198+ host : 'col col-lg-6 d-inline-block'
199+ }
200+ } ) ;
201+ iiifLabelContainer = new DynamicFormGroupModel ( {
202+ id : 'iiifLabelContainer' ,
203+ group : [ this . iiifLabelModel ]
204+ } , {
205+ grid : {
206+ host : 'form-row'
207+ }
188208 } ) ;
189209
190210 iiifTocModel = new DsDynamicInputModel ( {
191211 hasSelectableMetadata : false , metadataFields : [ ] , repeatable : false , submissionId : '' ,
192212 id : 'iiifToc' ,
193213 name : 'iiifToc' ,
214+ } , {
215+ grid : {
216+ host : 'col col-lg-6 d-inline-block'
217+ }
218+ } ) ;
219+ iiifTocContainer = new DynamicFormGroupModel ( {
220+ id : 'iiifTocContainer' ,
221+ group : [ this . iiifTocModel ]
222+ } , {
223+ grid : {
224+ host : 'form-row'
225+ }
194226 } ) ;
195227
196228 iiifWidthModel = new DsDynamicInputModel ( {
197229 hasSelectableMetadata : false , metadataFields : [ ] , repeatable : false , submissionId : '' ,
198230 id : 'iiifWidth' ,
199231 name : 'iiifWidth' ,
232+ } , {
233+ grid : {
234+ host : 'col col-lg-6 d-inline-block'
235+ }
236+ } ) ;
237+ iiifWidthContainer = new DynamicFormGroupModel ( {
238+ id : 'iiifWidthContainer' ,
239+ group : [ this . iiifWidthModel ]
240+ } , {
241+ grid : {
242+ host : 'form-row'
243+ }
200244 } ) ;
201245
202246 iiifHeightModel = new DsDynamicInputModel ( {
203247 hasSelectableMetadata : false , metadataFields : [ ] , repeatable : false , submissionId : '' ,
204248 id : 'iiifHeight' ,
205249 name : 'iiifHeight'
250+ } , {
251+ grid : {
252+ host : 'col col-lg-6 d-inline-block'
253+ }
254+ } ) ;
255+ iiifHeightContainer = new DynamicFormGroupModel ( {
256+ id : 'iiifHeightContainer' ,
257+ group : [ this . iiifHeightModel ]
258+ } , {
259+ grid : {
260+ host : 'form-row'
261+ }
206262 } ) ;
207263
208264 /**
209265 * All input models in a simple array for easier iterations
210266 */
211267 inputModels = [ this . fileNameModel , this . primaryBitstreamModel , this . descriptionModel , this . selectedFormatModel ,
212- this . newFormatModel , this . iiifLabelModel , this . iiifTocModel , this . iiifWidthModel , this . iiifHeightModel ] ;
268+ this . newFormatModel ] ;
213269
214270 /**
215271 * The dynamic form fields used for editing the information of a bitstream
@@ -222,7 +278,11 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
222278 this . fileNameModel ,
223279 this . primaryBitstreamModel
224280 ]
225- } ) ,
281+ } , {
282+ grid : {
283+ host : 'form-row'
284+ }
285+ } ) ,
226286 new DynamicFormGroupModel ( {
227287 id : 'descriptionContainer' ,
228288 group : [
@@ -235,30 +295,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
235295 this . selectedFormatModel ,
236296 this . newFormatModel
237297 ]
238- } ) ,
239- new DynamicFormGroupModel ( {
240- id : 'iiifLabelContainer' ,
241- group : [
242- this . iiifLabelModel
243- ]
244- } ) ,
245- new DynamicFormGroupModel ( {
246- id : 'iiifTocContainer' ,
247- group : [
248- this . iiifTocModel
249- ]
250- } ) ,
251- new DynamicFormGroupModel ( {
252- id : 'iiifWidthContainer' ,
253- group : [
254- this . iiifWidthModel
255- ]
256- } ) ,
257- new DynamicFormGroupModel ( {
258- id : 'iiifHeightContainer' ,
259- group : [
260- this . iiifHeightModel
261- ]
262298 } )
263299 ] ;
264300
@@ -267,11 +303,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
267303 */
268304 newFormatBaseLayout = 'col col-sm-6 d-inline-block' ;
269305
270- /**
271- * Base layout for iiif options
272- */
273- iiifOptionsBaseLayout = 'col col-sm-6' ;
274-
275306 /**
276307 * Layout used for structuring the form inputs
277308 */
@@ -306,26 +337,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
306337 host : this . newFormatBaseLayout + ' invisible'
307338 }
308339 } ,
309- iiifLabel : {
310- grid : {
311- host : 'd-none'
312- }
313- } ,
314- iiifToc : {
315- grid : {
316- host : 'd-none'
317- }
318- } ,
319- iiifWidth : {
320- grid : {
321- host : 'd-none'
322- }
323- } ,
324- iiifHeight : {
325- grid : {
326- host : 'd-none'
327- }
328- } ,
329340 fileNamePrimaryContainer : {
330341 grid : {
331342 host : 'row position-relative'
@@ -340,27 +351,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
340351 grid : {
341352 host : 'row'
342353 }
343- } ,
344- iiifLabelContainer : {
345- grid : {
346- host : 'row'
347- }
348- } ,
349- iiifTocContainer : {
350- grid : {
351- host : 'row'
352- }
353- } ,
354- iiifWidthContainer : {
355- grid : {
356- host : 'row'
357- }
358- } ,
359- iiifHeightContainer : {
360- grid : {
361- host : 'row'
362- }
363- } ,
354+ }
364355 } ;
365356
366357 /**
@@ -387,6 +378,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
387378 */
388379 isIIIF = false ;
389380
381+
390382 /**
391383 * Array to track all subscriptions and unsubscribe them onDestroy
392384 * @type {Array }
@@ -413,7 +405,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
413405 * - Translate the form labels and hints
414406 */
415407 ngOnInit ( ) : void {
416- this . formGroup = this . formService . createFormGroup ( this . formModel ) ;
417408
418409 this . itemId = this . route . snapshot . queryParams . itemId ;
419410 this . entityType = this . route . snapshot . queryParams . entityType ;
@@ -437,14 +428,11 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
437428 ) . subscribe ( ( [ bitstream , allFormats ] ) => {
438429 this . bitstream = bitstream as Bitstream ;
439430 this . formats = allFormats . page ;
431+ this . setForm ( ) ;
440432 this . setIiifStatus ( this . bitstream ) ;
441- this . updateFormatModel ( ) ;
442- this . updateForm ( this . bitstream ) ;
443433 } )
444434 ) ;
445435
446- this . updateFieldTranslations ( ) ;
447-
448436 this . subs . push (
449437 this . translate . onLangChange
450438 . subscribe ( ( ) => {
@@ -453,6 +441,16 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
453441 ) ;
454442 }
455443
444+ /**
445+ * Initializes the form.
446+ */
447+ setForm ( ) {
448+ this . formGroup = this . formService . createFormGroup ( this . formModel ) ;
449+ this . updateFormatModel ( ) ;
450+ this . updateForm ( this . bitstream ) ;
451+ this . updateFieldTranslations ( ) ;
452+ }
453+
456454 /**
457455 * Update the current form values with bitstream properties
458456 * @param bitstream
@@ -470,6 +468,22 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
470468 newFormat : hasValue ( bitstream . firstMetadata ( 'dc.format' ) ) ? bitstream . firstMetadata ( 'dc.format' ) . value : undefined
471469 }
472470 } ) ;
471+ if ( this . isIIIF ) {
472+ this . formGroup . patchValue ( {
473+ iiifLabelContainer : {
474+ iiifLabel : bitstream . firstMetadataValue ( this . IIIF_LABEL_METADATA )
475+ } ,
476+ iiifTocContainer : {
477+ iiifToc : bitstream . firstMetadataValue ( this . IIIF_TOC_METADATA )
478+ } ,
479+ iiifWidthContainer : {
480+ iiifWidth : bitstream . firstMetadataValue ( this . IMAGE_WIDTH_METADATA )
481+ } ,
482+ iiifHeightContainer : {
483+ iiifHeight : bitstream . firstMetadataValue ( this . IMAGE_HEIGHT_METADATA )
484+ }
485+ } ) ;
486+ }
473487 this . bitstream . format . pipe (
474488 getAllSucceededRemoteDataPayload ( )
475489 ) . subscribe ( ( format : BitstreamFormat ) => {
@@ -604,13 +618,17 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
604618 const primary = rawForm . fileNamePrimaryContainer . primaryBitstream ;
605619 Metadata . setFirstValue ( newMetadata , 'dc.title' , rawForm . fileNamePrimaryContainer . fileName ) ;
606620 Metadata . setFirstValue ( newMetadata , 'dc.description' , rawForm . descriptionContainer . description ) ;
621+ console . log ( this . isIIIF ) ;
607622 if ( this . isIIIF ) {
623+ console . log ( rawForm ) ;
608624 // It's helpful to remove these metadata elements entirely when the form value is empty.
609625 // This avoids potential issues on the REST side and makes it possible to do things like
610626 // remove an existing "table of contents" entry.
611627 if ( isEmpty ( rawForm . iiifLabelContainer . iiifLabel ) ) {
628+
612629 delete newMetadata [ this . IIIF_LABEL_METADATA ] ;
613630 } else {
631+ console . log ( rawForm . iiifLabelContainer . iiifLabel ) ;
614632 Metadata . setFirstValue ( newMetadata , this . IIIF_LABEL_METADATA , rawForm . iiifLabelContainer . iiifLabel ) ;
615633 }
616634 if ( isEmpty ( rawForm . iiifTocContainer . iiifToc ) ) {
@@ -690,30 +708,21 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
690708
691709 // If iiifCheck$ returns true, enable the IIIF form elements.
692710 const iiifSub = iiifCheck$ . subscribe ( ( iiif : boolean ) => {
693- if ( iiif ) {
694- this . isIIIF = true ;
695- this . formLayout . iiifLabel . grid . host = this . iiifOptionsBaseLayout ;
696- this . formLayout . iiifToc . grid . host = this . iiifOptionsBaseLayout ;
697- this . formLayout . iiifWidth . grid . host = this . iiifOptionsBaseLayout ;
698- this . formLayout . iiifHeight . grid . host = this . iiifOptionsBaseLayout ;
699- this . formGroup . patchValue ( {
700- iiifLabelContainer : {
701- iiifLabel : bitstream . firstMetadataValue ( this . IIIF_LABEL_METADATA )
702- } ,
703- iiifTocContainer : {
704- iiifToc : bitstream . firstMetadataValue ( this . IIIF_TOC_METADATA )
705- } ,
706- iiifWidthContainer : {
707- iiifWidth : bitstream . firstMetadataValue ( this . IMAGE_WIDTH_METADATA )
708- } ,
709- iiifHeightContainer : {
710- iiifHeight : bitstream . firstMetadataValue ( this . IMAGE_HEIGHT_METADATA )
711- }
712- } ) ;
713- // Assures that the form always includes the iiif additions.
714- this . changeDetectorRef . detectChanges ( ) ;
715- }
716- } ) ;
711+ if ( iiif ) {
712+ this . isIIIF = true ;
713+ this . inputModels . push ( this . iiifLabelModel ) ;
714+ this . formModel . push ( this . iiifLabelContainer ) ;
715+ this . inputModels . push ( this . iiifTocModel ) ;
716+ this . formModel . push ( this . iiifTocContainer ) ;
717+ this . inputModels . push ( this . iiifWidthModel ) ;
718+ this . formModel . push ( this . iiifWidthContainer ) ;
719+ this . inputModels . push ( this . iiifHeightModel ) ;
720+ this . formModel . push ( this . iiifHeightContainer ) ;
721+ }
722+ // re-initialize the form and detect the change.
723+ this . setForm ( ) ;
724+ this . changeDetectorRef . detectChanges ( ) ;
725+ } ) ;
717726
718727 this . subs . push ( iiifSub ) ;
719728
0 commit comments