Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/ui/src/app/model/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type ProfileFormat = QuestionFormat;
export interface Question {
question?: string;
answer?: string | number[];
default?: string | number[];
}

export enum ProfileRisk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -311,7 +339,7 @@ export class ProfileFormComponent implements OnInit, AfterViewInit {
}

close(): Observable<boolean> {
if (this.profileHasNoChanges()) {
if (this.profileHasNoChanges() || this.profileForm.pristine) {
return of(true);
}
return this.openCloseDialog().pipe(map(res => !!res));
Expand Down Expand Up @@ -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) => {
Expand Down
Loading