-
Notifications
You must be signed in to change notification settings - Fork 634
/
index.vue
213 lines (197 loc) · 5.25 KB
/
index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<template>
<MultiPaneLayout ref="multiPaneLayout">
<PageStatus
slot="header"
:contentName="exam.title"
:userName="userName"
:questions="examAttempts"
:completionTimestamp="completionTimestamp"
:completed="closed"
/>
<AttemptLogList
slot="aside"
:attemptLogs="attemptLogs"
:selectedQuestionNumber="questionNumber"
@select="handleNavigateToQuestion"
/>
<div
v-if="exercise"
slot="main"
class="exercise-container"
:style="{ backgroundColor: $coreBgLight }"
>
<h3>{{ $tr('question', {questionNumber: questionNumber + 1}) }}</h3>
<KCheckbox
:label="$tr('showCorrectAnswerLabel')"
:checked="showCorrectAnswer"
@change="toggleShowCorrectAnswer"
/>
<InteractionList
v-if="!showCorrectAnswer"
:interactions="currentInteractionHistory"
:selectedInteractionIndex="selectedInteractionIndex"
@select="navigateToQuestionAttempt"
/>
<ContentRenderer
v-if="exercise"
:itemId="itemId"
:allowHints="false"
:kind="exercise.kind"
:files="exercise.files"
:available="exercise.available"
:extraFields="exercise.extra_fields"
:interactive="false"
:assessment="true"
:answerState="answerState"
:showCorrectAnswer="showCorrectAnswer"
/>
</div>
<p v-else slot="main">
{{ $tr('noItemId') }}
</p>
</MultiPaneLayout>
</template>
<script>
import themeMixin from 'kolibri.coreVue.mixins.themeMixin';
import ContentRenderer from 'kolibri.coreVue.components.ContentRenderer';
import AttemptLogList from 'kolibri.coreVue.components.AttemptLogList';
import InteractionList from 'kolibri.coreVue.components.InteractionList';
import KCheckbox from 'kolibri.coreVue.components.KCheckbox';
import find from 'lodash/find';
import MultiPaneLayout from 'kolibri.coreVue.components.MultiPaneLayout';
import PageStatus from './PageStatus';
export default {
name: 'ExamReport',
$trs: {
backTo: 'Back to quiz report for { title }',
correctAnswer: 'Correct answer',
yourAnswer: 'Your answer',
correctAnswerCannotBeDisplayed: 'Correct answer cannot be displayed',
question: 'Question { questionNumber, number }',
showCorrectAnswerLabel: 'Show correct answer',
noItemId: 'This question has an error, please move on to the next question',
},
components: {
ContentRenderer,
PageStatus,
AttemptLogList,
InteractionList,
KCheckbox,
MultiPaneLayout,
},
mixins: [themeMixin],
props: {
examAttempts: {
type: Array,
required: true,
},
exam: {
type: Object,
required: true,
},
userName: {
type: String,
required: true,
},
currentInteractionHistory: {
type: Array,
required: true,
},
currentInteraction: {
type: Object,
required: false,
default: null,
},
selectedInteractionIndex: {
type: Number,
required: true,
},
questionNumber: {
type: Number,
required: true,
},
exercise: {
type: Object,
required: true,
},
itemId: {
type: String,
required: true,
},
completionTimestamp: {
type: Date,
required: false,
default: null,
},
closed: {
type: Boolean,
required: true,
},
navigateToQuestion: {
type: Function,
required: true,
},
navigateToQuestionAttempt: {
type: Function,
required: true,
},
questions: {
type: Array,
required: true,
},
exerciseContentNodes: {
type: Array,
required: true,
},
},
data() {
return {
showCorrectAnswer: false,
};
},
computed: {
attemptLogs() {
return this.examAttempts.map(attempt => {
let num_coach_contents = 0;
const exerciseId = this.questions[attempt.questionNumber - 1].exercise_id;
const exerciseMatch = find(this.exerciseContentNodes, { id: exerciseId });
if (exerciseMatch) {
num_coach_contents = exerciseMatch.num_coach_contents;
}
return { ...attempt, num_coach_contents };
});
},
answerState() {
// Do not pass in answerState if showCorrectAnswer is set to true
// answerState has a precedence over showCorrectAnswer
if (
!this.showCorrectAnswer &&
this.currentInteraction &&
this.currentInteraction.type === 'answer'
) {
return this.currentInteraction.answer;
}
return null;
},
},
methods: {
handleNavigateToQuestion(questionNumber) {
this.navigateToQuestion(questionNumber);
this.$refs.multiPaneLayout.scrollMainToTop();
this.showCorrectAnswer = false;
},
toggleShowCorrectAnswer() {
this.showCorrectAnswer = !this.showCorrectAnswer;
this.$forceUpdate();
},
},
};
</script>
<style lang="scss" scoped>
.exercise-container {
padding: 8px;
}
h3 {
margin-top: 0;
}
</style>