@@ -3,7 +3,7 @@ import { Component, Inject, ViewChild } from '@angular/core';
33import { UntypedFormControl } from '@angular/forms' ;
44
55import { filter , map , mergeMap , take } from 'rxjs/operators' ;
6- import { combineLatest , Observable , of , Subscription } from 'rxjs' ;
6+ import { BehaviorSubject , combineLatest , Observable , Subscription } from 'rxjs' ;
77import { TranslateService } from '@ngx-translate/core' ;
88
99import { renderSectionFor } from '../sections-decorator' ;
@@ -42,7 +42,7 @@ import {
4242 FORM_ACCESS_CONDITION_TYPE_CONFIG ,
4343 FORM_ACCESS_CONDITION_TYPE_LAYOUT
4444} from './section-accesses.model' ;
45- import { hasValue , isNotEmpty , isNotNull } from '../../../shared/empty.util' ;
45+ import { hasValue , isNotEmpty , isNotNull , isObjectEmpty } from '../../../shared/empty.util' ;
4646import {
4747 WorkspaceitemSectionAccessesObject
4848} from '../../../core/submission/models/workspaceitem-section-accesses.model' ;
@@ -124,6 +124,11 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
124124 */
125125 public canChangeDiscoverable : boolean ;
126126
127+ /**
128+ * Whether the section is required
129+ */
130+ public required$ : BehaviorSubject < boolean > = new BehaviorSubject ( false ) ;
131+
127132 /**
128133 * Initialize instance variables
129134 *
@@ -161,7 +166,7 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
161166 * The form model
162167 */
163168 public initModelData ( formModel : DynamicFormControlModel [ ] ) {
164- this . accessesData . accessConditions . forEach ( ( accessCondition , index ) => {
169+ this . accessesData . accessConditions ? .forEach ( ( accessCondition , index ) => {
165170 Array . of ( 'name' , 'startDate' , 'endDate' )
166171 . filter ( ( key ) => accessCondition . hasOwnProperty ( key ) && isNotEmpty ( accessCondition [ key ] ) )
167172 . forEach ( ( key ) => {
@@ -298,9 +303,8 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
298303 this . canChangeDiscoverable = ! ! config . canChangeDiscoverable ;
299304 this . accessesData = accessData ;
300305 this . formModel = this . buildFileEditForm ( ) ;
306+ this . required$ . next ( config . required ) ;
301307 } ) ;
302-
303-
304308 }
305309
306310 /**
@@ -310,7 +314,12 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
310314 * the section status
311315 */
312316 protected getSectionStatus ( ) : Observable < boolean > {
313- return of ( true ) ;
317+ return combineLatest ( [
318+ this . required$ ,
319+ this . sectionService . getSectionErrors ( this . submissionId , this . sectionData . id )
320+ ] ) . pipe (
321+ map ( ( [ required , errors ] ) => ( ! required || ( required && isObjectEmpty ( errors ) && ! isObjectEmpty ( this . accessesData ) ) ) )
322+ ) ;
314323 }
315324
316325 /**
0 commit comments