@@ -3,9 +3,7 @@ import { FormControl } from '@angular/forms';
33
44import {
55 DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER ,
6- DynamicDateControlModel ,
76 DynamicDatePickerModel ,
8- DynamicFormArrayGroupModel ,
97 DynamicFormArrayModel ,
108 DynamicFormControlEvent ,
119 DynamicFormControlModel ,
@@ -57,6 +55,8 @@ import {
5755} from '../../../../../core/json-patch/builder/json-patch-operation-path-combiner' ;
5856import { SectionUploadService } from '../../section-upload.service' ;
5957import { Subscription } from 'rxjs' ;
58+ import { DynamicFormControlCondition } from '@ng-dynamic-forms/core/lib/model/misc/dynamic-form-control-relation.model' ;
59+ import { DynamicDateControlValue } from '@ng-dynamic-forms/core/lib/model/dynamic-date-control.model' ;
6060
6161/**
6262 * This component represents the edit form for bitstream
@@ -245,8 +245,6 @@ export class SubmissionSectionUploadFileEditComponent implements OnInit {
245245 this . availableAccessConditionOptions . filter ( ( element ) => element . name === control . value )
246246 . forEach ( ( element ) => accessCondition = element ) ;
247247 if ( isNotEmpty ( accessCondition ) ) {
248- const showGroups : boolean = accessCondition . hasStartDate === true || accessCondition . hasEndDate === true ;
249-
250248 const startDateControl : FormControl = control . parent . get ( 'startDate' ) as FormControl ;
251249 const endDateControl : FormControl = control . parent . get ( 'endDate' ) as FormControl ;
252250
@@ -257,34 +255,6 @@ export class SubmissionSectionUploadFileEditComponent implements OnInit {
257255 startDateControl ?. setValue ( null ) ;
258256 control . parent . markAsDirty ( ) ;
259257 endDateControl ?. setValue ( null ) ;
260-
261- if ( showGroups ) {
262- if ( accessCondition . hasStartDate && accessCondition . maxStartDate ) {
263- const startDateModel = this . formBuilderService . findById (
264- 'startDate' ,
265- ( model . parent as DynamicFormArrayGroupModel ) . group ) as DynamicDateControlModel ;
266-
267- const min = new Date ( accessCondition . maxStartDate ) ;
268- startDateModel . max = {
269- year : min . getUTCFullYear ( ) ,
270- month : min . getUTCMonth ( ) + 1 ,
271- day : min . getUTCDate ( )
272- } ;
273- }
274- if ( accessCondition . hasEndDate && accessCondition . maxEndDate ) {
275- const endDateModel = this . formBuilderService . findById (
276- 'endDate' ,
277- ( model . parent as DynamicFormArrayGroupModel ) . group ) as DynamicDateControlModel ;
278-
279- const max = new Date ( accessCondition . maxEndDate ) ;
280- endDateModel . max = {
281- year : max . getUTCFullYear ( ) ,
282- month : max . getUTCMonth ( ) + 1 ,
283- day : max . getUTCDate ( )
284- } ;
285-
286- }
287- }
288258 }
289259 }
290260
@@ -344,38 +314,63 @@ export class SubmissionSectionUploadFileEditComponent implements OnInit {
344314 }
345315 accessConditionTypeModelConfig . options = accessConditionTypeOptions ;
346316
347- // Dynamically assign of relation in config. For startdate, endDate, groups.
348- const hasStart = [ ] ;
349- const hasEnd = [ ] ;
350- const hasGroups = [ ] ;
317+ // Dynamically assign of relation in config. For startDate and endDate.
318+ const startDateCondition : DynamicFormControlCondition [ ] = [ ] ;
319+ const endDateCondition : DynamicFormControlCondition [ ] = [ ] ;
320+ let maxStartDate : DynamicDateControlValue ;
321+ let maxEndDate : DynamicDateControlValue ;
351322 this . availableAccessConditionOptions . forEach ( ( condition ) => {
352- const showStart : boolean = condition . hasStartDate === true ;
353- const showEnd : boolean = condition . hasEndDate === true ;
354- const showGroups : boolean = showStart || showEnd ;
355- if ( showStart ) {
356- hasStart . push ( { id : 'name' , value : condition . name } ) ;
357- }
358- if ( showEnd ) {
359- hasEnd . push ( { id : 'name' , value : condition . name } ) ;
323+
324+ if ( condition . hasStartDate ) {
325+ startDateCondition . push ( { id : 'name' , value : condition . name } ) ;
326+ if ( condition . maxStartDate ) {
327+ const min = new Date ( condition . maxStartDate ) ;
328+ maxStartDate = {
329+ year : min . getUTCFullYear ( ) ,
330+ month : min . getUTCMonth ( ) + 1 ,
331+ day : min . getUTCDate ( )
332+ } ;
333+ }
360334 }
361- if ( showGroups ) {
362- hasGroups . push ( { id : 'name' , value : condition . name } ) ;
335+ if ( condition . hasEndDate ) {
336+ endDateCondition . push ( { id : 'name' , value : condition . name } ) ;
337+ if ( condition . maxEndDate ) {
338+ const max = new Date ( condition . maxEndDate ) ;
339+ maxEndDate = {
340+ year : max . getUTCFullYear ( ) ,
341+ month : max . getUTCMonth ( ) + 1 ,
342+ day : max . getUTCDate ( )
343+ } ;
344+ }
363345 }
364346 } ) ;
365- const confStart = { relations : [ { match : MATCH_ENABLED , operator : OR_OPERATOR , when : hasStart } ] } ;
366- const confEnd = { relations : [ { match : MATCH_ENABLED , operator : OR_OPERATOR , when : hasEnd } ] } ;
347+ const confStart = { relations : [ { match : MATCH_ENABLED , operator : OR_OPERATOR , when : startDateCondition } ] } ;
348+ const confEnd = { relations : [ { match : MATCH_ENABLED , operator : OR_OPERATOR , when : endDateCondition } ] } ;
349+ const hasStartDate = startDateCondition . length > 0 ;
350+ const hasEndDate = endDateCondition . length > 0 ;
367351
368352 accessConditionsArrayConfig . groupFactory = ( ) => {
369353 const type = new DynamicSelectModel ( accessConditionTypeModelConfig , BITSTREAM_FORM_ACCESS_CONDITION_TYPE_LAYOUT ) ;
370354 const startDateConfig = Object . assign ( { } , BITSTREAM_FORM_ACCESS_CONDITION_START_DATE_CONFIG , confStart ) ;
355+ if ( maxStartDate ) {
356+ startDateConfig . max = maxStartDate ;
357+ }
358+
371359 const endDateConfig = Object . assign ( { } , BITSTREAM_FORM_ACCESS_CONDITION_END_DATE_CONFIG , confEnd ) ;
360+ if ( maxEndDate ) {
361+ endDateConfig . max = maxEndDate ;
362+ }
372363
373364 const startDate = new DynamicDatePickerModel ( startDateConfig , BITSTREAM_FORM_ACCESS_CONDITION_START_DATE_LAYOUT ) ;
374365 const endDate = new DynamicDatePickerModel ( endDateConfig , BITSTREAM_FORM_ACCESS_CONDITION_END_DATE_LAYOUT ) ;
375366 const accessConditionGroupConfig = Object . assign ( { } , BITSTREAM_ACCESS_CONDITION_GROUP_CONFIG ) ;
376367 accessConditionGroupConfig . group = [ type ] ;
377- if ( hasStart . length > 0 ) { accessConditionGroupConfig . group . push ( startDate ) ; }
378- if ( hasEnd . length > 0 ) { accessConditionGroupConfig . group . push ( endDate ) ; }
368+ if ( hasStartDate ) {
369+ accessConditionGroupConfig . group . push ( startDate ) ;
370+ }
371+ if ( hasEndDate ) {
372+ accessConditionGroupConfig . group . push ( endDate ) ;
373+ }
379374 return [ new DynamicFormGroupModel ( accessConditionGroupConfig , BITSTREAM_ACCESS_CONDITION_GROUP_LAYOUT ) ] ;
380375 } ;
381376
0 commit comments