Skip to content

Commit 01a2e03

Browse files
fix UI bug
1 parent d76d9f9 commit 01a2e03

File tree

2 files changed

+66
-22
lines changed

2 files changed

+66
-22
lines changed

src/utils/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ export function snakeCaseToCamelCase (text: string): string {
2222
})
2323
return words.join('')
2424
}
25+
26+
export function toTitleCase (text: string, separator?: string): string {
27+
if (separator === undefined) separator = ' '
28+
let words = text.split(separator)
29+
words = words.map(word => {
30+
word = word.toLowerCase()
31+
return word.slice(0, 1).toUpperCase() + word.slice(1)
32+
})
33+
return words.join(' ')
34+
}

src/views/reading-exercise/ReadingExerciseEditAnswers.vue

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
</template>
5757
<v-select
5858
v-else
59-
v-model="question.question_type"
59+
:value="question.question_type"
60+
@change="onChangeQuestionType(question, $event)"
6061
:items="questionTypes"
6162
hide-details
6263
outlined
@@ -76,32 +77,39 @@
7677
hide-details
7778
outlined
7879
dense
79-
>
80-
<template #prepend-item>
81-
<v-list>
82-
<v-subheader>
83-
Common choices
84-
</v-subheader>
85-
<v-list-item
86-
v-for="(value, key) in commonChoices"
87-
:key="key"
88-
@click="question.choices = value"
89-
>
90-
<v-list-item-title>
91-
{{ key }}
92-
</v-list-item-title>
93-
</v-list-item>
94-
</v-list>
95-
</template>
96-
</v-select>
80+
></v-select>
9781
</template>
9882
</td>
9983
<td>
10084
<template v-if="!question.editing">
101-
{{ formatList(question.answers, ' / ') }}
85+
<span v-if="question.question_type === 'true_false' || question.question_type === 'yes_no'">
86+
{{ toTitleCase(question.answers[0], '_') }}
87+
</span>
88+
<span v-else>
89+
{{ formatList(question.answers, ' / ') }}
90+
</span>
10291
</template>
92+
<v-select
93+
v-else-if="question.question_type === 'multiple_choice'"
94+
v-model="question.answers"
95+
:items="getChoicesItems(question)"
96+
multiple
97+
hide-details
98+
outlined
99+
dense
100+
></v-select>
101+
<v-select
102+
v-else-if="question.question_type === 'true_false' || question.question_type === 'yes_no'"
103+
:value="question.answers[0]"
104+
@input="question.answers = [$event]"
105+
:items="getChoicesItems(question)"
106+
hide-details
107+
outlined
108+
dense
109+
></v-select>
103110
<v-text-field
104111
v-else
112+
v-model="question.answers"
105113
:value="formatList(question.answers, ' / ')"
106114
@input="question.answers = parseList($event, ' / ')"
107115
hide-details
@@ -188,7 +196,7 @@ import { Mixins, Component } from 'vue-property-decorator'
188196
import { ReadingExerciseMixin } from '@/mixins/reading-exercise-mixin'
189197
import { ReadingQuestion } from '@/interfaces/reading-question'
190198
import { ReadingQuestionCreateReq, ReadingQuestionUpdateReq } from '@/interfaces/api/reading-question'
191-
import { unexpectedExc } from '@/utils'
199+
import { toTitleCase, unexpectedExc } from '@/utils'
192200
193201
declare interface LocalQuestion extends ReadingQuestion {
194202
editing: boolean;
@@ -312,7 +320,7 @@ export default class ReadingExerciseEditAnswers extends Mixins(ReadingExerciseMi
312320
313321
allNextPassageIsEmpty (passage: LocalQuestion['passage']): boolean {
314322
if (passage === 3) return true
315-
for (let i = passage; i <= 3; i++) {
323+
for (let i = passage + 1; i <= 3; i++) {
316324
const questions = (this[`passage${i}Questions`] as LocalQuestion[])
317325
if (questions.length > 0) {
318326
return false
@@ -321,6 +329,32 @@ export default class ReadingExerciseEditAnswers extends Mixins(ReadingExerciseMi
321329
return true
322330
}
323331
332+
getChoicesItems (question: LocalQuestion): { text: string; value: string }[] | string[] {
333+
if (question.question_type === 'true_false') {
334+
return [
335+
{ text: 'True', value: 'TRUE' },
336+
{ text: 'False', value: 'FALSE' },
337+
{ text: 'Not Given', value: 'NOT_GIVEN' }
338+
]
339+
} else if (question.question_type === 'yes_no') {
340+
return [
341+
{ text: 'Yes', value: 'YES' },
342+
{ text: 'No', value: 'NO' },
343+
{ text: 'Not Given', value: 'NOT_GIVEN' }
344+
]
345+
} else {
346+
return question.choices
347+
}
348+
}
349+
350+
toTitleCase = toTitleCase
351+
352+
onChangeQuestionType (question: LocalQuestion, value: LocalQuestion['question_type']): void {
353+
question.question_type = value
354+
question.choices = []
355+
question.answers = []
356+
}
357+
324358
/**
325359
* Call API
326360
*/

0 commit comments

Comments
 (0)