diff --git a/modules/ui/src/app/model/profile.ts b/modules/ui/src/app/model/profile.ts index f9c0912a9..fcf2f8207 100644 --- a/modules/ui/src/app/model/profile.ts +++ b/modules/ui/src/app/model/profile.ts @@ -29,6 +29,7 @@ export type ProfileFormat = QuestionFormat; export interface Question { question?: string; answer?: string | number[]; + default?: string | number[]; } export enum ProfileRisk { diff --git a/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.ts b/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.ts index 2666e7853..a9bd50886 100644 --- a/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.ts +++ b/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.ts @@ -172,7 +172,7 @@ export class ProfileFormComponent implements OnInit, AfterViewInit { if (profile.questions) { for (const question of profile.questions) { - if (question.answer && question.answer !== '') { + if (this.isAnswerFilled(question)) { return false; } } @@ -182,6 +182,34 @@ export class ProfileFormComponent implements OnInit, AfterViewInit { return true; } + private isAnswerFilled(question: Question): boolean { + if ( + !question.answer || + (Array.isArray(question.answer) && question.answer.length === 0) + ) { + return false; + } + + if (typeof question.answer === 'string') { + return ( + question.answer.trim() !== '' && question.answer !== question.default + ); + } + + if (Array.isArray(question.answer)) { + if (!Array.isArray(question.default) && question.answer.length === 0) { + return true; + } + + return ( + question.answer.length > 0 && + JSON.stringify(question.answer) !== JSON.stringify(question.default) + ); + } + + return true; + } + private compareProfiles(profile1: Profile, profile2: Profile) { if (profile1.name !== profile2.name) { return false; @@ -311,7 +339,7 @@ export class ProfileFormComponent implements OnInit, AfterViewInit { } close(): Observable { - if (this.profileHasNoChanges()) { + if (this.profileHasNoChanges() || this.profileForm.pristine) { return of(true); } return this.openCloseDialog().pipe(map(res => !!res)); @@ -362,7 +390,9 @@ export class ProfileFormComponent implements OnInit, AfterViewInit { this.profileFormat?.forEach((initialQuestion, index) => { const question: Question = {}; question.question = initialQuestion.question; - + if (initialQuestion.default) { + question.default = initialQuestion.default; + } if (initialQuestion.type === FormControlType.SELECT_MULTIPLE) { const answer: number[] = []; initialQuestion.options?.forEach((_, idx) => {