Skip to content
Draft
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
14 changes: 13 additions & 1 deletion frontend/components/quizzes/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export enum QuizQuestionTypes {
essay_question="essay_question",
file_upload_question="file_upload_question",

numerical_question="numerical_question"
numerical_question="numerical_question",
likert_question="likert_question"
}

export const clearValue = (question: Question) => {
Expand All @@ -29,6 +30,7 @@ export const clearValue = (question: Question) => {
return question.student.map((v: any) => v(undefined));
case QuizQuestionTypes.multiple_dropdowns_question:
case QuizQuestionTypes.fill_in_multiple_blanks_question:
case QuizQuestionTypes.likert_question:
for (const key in question.student) {
question.student[key]('');
}
Expand Down Expand Up @@ -59,6 +61,13 @@ export const getDefaultValue = (question: Question, answer: any): any => {
.extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 400 } });
});
return fimbResult;
case QuizQuestionTypes.likert_question:
let likertResult: {[key: string]: ko.Observable} = {};
(question.statements || []).forEach((_: any, i: number) => {
const key = String(i);
likertResult[key] = ko.observable(answer ? answer[key] || '' : '');
});
return likertResult;
case QuizQuestionTypes.numerical_question:
case QuizQuestionTypes.essay_question:
case QuizQuestionTypes.short_answer_question:
Expand All @@ -83,6 +92,7 @@ export const subscribeToStudent = (question: Question): ko.Observable[] => {
return question.student;
case QuizQuestionTypes.multiple_dropdowns_question:
case QuizQuestionTypes.fill_in_multiple_blanks_question:
case QuizQuestionTypes.likert_question:
return Object.values(question.student);
case QuizQuestionTypes.multiple_answers_question:
default:
Expand All @@ -96,6 +106,7 @@ export const getValue = (question: Question): any => {
return question.student.map((value: ko.Observable) => value());
case QuizQuestionTypes.multiple_dropdowns_question:
case QuizQuestionTypes.fill_in_multiple_blanks_question:
case QuizQuestionTypes.likert_question:
let result: {[key: string]: string} = {};
Object.entries(question.student).forEach(([key, value]: [string, ko.Observable])=> {
result[key] = value();
Expand Down Expand Up @@ -123,6 +134,7 @@ export interface Question {
student: any
answers?: string[] | {[key: string]: string[]}
statements?: string[]
options?: string[]
retainOrder?: boolean

feedback: ko.Observable<Feedback>
Expand Down
33 changes: 32 additions & 1 deletion frontend/components/quizzes/questions_ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h6 class="card-subtitle mb-2 text-muted">
<div class="col" data-bind="markdowned: {value: $data}"></div>
<div class="col">
<select class="custom-select"
data-bind="options: $parent.retainOrder ? $parent.answers : $parent.answers.sort(() => Math.random() - 0.5),
data-bind="options: $parent.retainOrder ? $parent.answers : [...$parent.answers].sort(() => Math.random() - 0.5),
disable: $component.isReadOnly(),
optionsCaption: '',
value: $parent.student[$index()],
Expand Down Expand Up @@ -137,6 +137,37 @@ <h6 class="card-subtitle mb-2 text-muted">
<!-- Multiple Fill in the Blank Question -->
<div data-bind="case: 'fill_in_multiple_blanks_question'">
</div>
<!-- Likert Question -->
<div data-bind="case: 'likert_question'">
<div class="table-responsive">
<table class="table table-bordered table-sm text-center">
<thead>
<tr>
<th class="text-left" style="min-width:200px"></th>
<!-- ko foreach: options -->
<th data-bind="text: $data"></th>
<!-- /ko -->
</tr>
</thead>
<tbody>
<!-- ko foreach: statements -->
<tr>
<td class="text-left" data-bind="markdowned: {value: $data}"></td>
<!-- ko foreach: $parent.options -->
<td>
<input type="radio"
data-bind="checked: $parents[1].student[String($parentContext.$index())],
value: $data,
disable: $component.isReadOnly(),
attr: {name: 'question-likert-'+$parentContext.$parentContext.$index()+'-'+$parentContext.$index()}">
</td>
<!-- /ko -->
</tr>
<!-- /ko -->
</tbody>
</table>
</div>
</div>
<!-- Else -->
<div data-bind="case: $default">
I have no idea what this is!
Expand Down
Loading