Skip to content

Commit 5bd8690

Browse files
FrancescoMolinarodanieleninfo
authored andcommitted
[CST-16309] update status handling
1 parent 74c17e7 commit 5bd8690

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/app/core/config/models/config-submission-access.model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export class SubmissionAccessModel extends ConfigObject {
3737
@autoserialize
3838
singleAccessCondition: boolean;
3939

40+
/**
41+
* Whether the field is mandatory
42+
*/
43+
@autoserialize
44+
required: boolean;
45+
4046
/**
4147
* The links to all related resources returned by the rest api.
4248
*/

src/app/submission/sections/accesses/section-accesses.component.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component, Inject, ViewChild } from '@angular/core';
33
import { UntypedFormControl } from '@angular/forms';
44

55
import { filter, map, mergeMap, take } from 'rxjs/operators';
6-
import { combineLatest, Observable, of, Subscription } from 'rxjs';
6+
import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs';
77
import { TranslateService } from '@ngx-translate/core';
88

99
import { 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';
4646
import {
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

Comments
 (0)