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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ COPY . .

EXPOSE 4200

CMD ["npm", "run", "v3"]
CMD ["npm", "run", "v3:local"]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ng": "ng",
"start": "npm run v3",
"v3": "ng serve --project=v3 -c development --host 0.0.0.0 --port 4200 --disable-host-check --ssl true",
"v3:local": "ng serve --project=v3 -c development --host 0.0.0.0 --port 4200 --disable-host-check",
"proxy": "ng serve --project=v3 -c development --proxy-config proxy.conf.json",
"prestart": "npm run prebuildv3",
"prev3": "npm run prebuildv3",
Expand Down
67 changes: 43 additions & 24 deletions projects/v3/src/app/components/assessment/assessment.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,18 @@ Best regards`;
answer?: string;
file?: FileInput;
}): Observable<any> {
const answer = (!this.utils.isEmpty(questionInput.answer)) ? questionInput.answer : '';
const answer = this._getAnswerValueForQuestion(questionInput.questionId, questionInput.answer);

this.filledAnswers().forEach(answerObj => {
if (answerObj.questionId === questionInput.questionId) {
// if the answer is empty, we need to set it to null
if (this.utils.isEmpty(answer)) {
answerObj.answer = null;
} else {
answerObj.answer = answer;
}
}
});

return this.assessmentService.saveQuestionAnswer(
questionInput.submissionId,
Expand Down Expand Up @@ -315,7 +326,7 @@ Best regards`;
comment: string;
file?: FileInput;
}): Observable<any> {
const answer = (!this.utils.isEmpty(questionInput.answer)) ? questionInput.answer : '';
const answer = this._getAnswerValueForQuestion(questionInput.questionId, questionInput.answer);
const comment = (!this.utils.isEmpty(questionInput.comment)) ? questionInput.comment : '';

const savedValues = this.saved();
Expand Down Expand Up @@ -541,31 +552,14 @@ Best regards`;
}
this.utils.each(this.questionsForm.value, (value, key) => {
questionId = +key.replace('q-', '');
let answer;
if (value) {
answer = value;
} else {
this.assessment.groups.forEach(group => {
const currentQuestion = group.questions.find(question => {
return question.id === questionId;
});
if (currentQuestion && currentQuestion.type === 'multiple') {
answer = [];
} else {
answer = null;
}
});
}
answers.push({
questionId: questionId,
answer: answer
answer: this._getAnswerValueForQuestion(questionId, value)
});
});
}

// In review we also have comments for a question. and questionsForm value have both
// answer and comment. need to add them as separately
if (this.isPendingReview) {
} else if (this.isPendingReview) {
// In review we also have comments for a question. and questionsForm value have both
// answer and comment. need to add them as separately
assessment = Object.assign(assessment, {
reviewId: this.review.id
});
Expand All @@ -581,7 +575,7 @@ Best regards`;
questionId = +key.replace('q-', '');
const save: { questionId: number; answer: any; comment: any; file?: any } = {
questionId,
answer: answer?.answer,
answer: this._getAnswerValueForQuestion(questionId, answer.answer),
comment: answer?.comment,
};
if (answer.file) {
Expand All @@ -595,6 +589,31 @@ Best regards`;
return answers;
}

private _getAnswerValueForQuestion(questionId: number, value: any): any {
if (value || (Array.isArray(value) && value.length === 0)) {
return value;
}

let answer = null; // null for one off / default value
this.assessment.groups.forEach(group => {
const currentQuestion = group.questions.find(question => question.id === questionId);
if (currentQuestion) {
switch (currentQuestion.type) {
case 'multiple':
answer = [];
break;
case 'text':
case 'file':
case 'team-member-selector':
case 'multi-team-member-selector':
answer = '';
break;
}
}
});
return answer;
}

async _submitAnswer({autoSave = false, goBack = false}) {
const answers = this.filledAnswers();
// check if all required questions have answer when assessment done
Expand Down
Loading