brotherton-erpnext/erpnext/public/js/education/lms/components/Quiz.vue

116 lines
3.5 KiB
Vue
Raw Normal View History

2018-11-01 11:50:04 +00:00
<template>
2018-11-01 14:21:33 +00:00
<section class="quiz-section">
2019-02-19 11:31:31 +00:00
<div>
2018-11-01 14:21:33 +00:00
<div class="row">
<div class="col-md-8">
<h2>{{ content }}</h2>
</div>
</div>
<div class="content">
<hr>
2018-11-02 10:59:04 +00:00
<div id="quiz" :name="content">
2018-11-01 14:21:33 +00:00
<div id="quiz-body">
<component v-for="question in quizData" :key="question.name" v-bind:is="question.type" :question="question" @updateResponse="updateResponse"></component>
2018-11-01 14:21:33 +00:00
</div>
<div class="mt-3">
2018-11-02 10:59:04 +00:00
<div>
<div v-if="submitted" id="post-quiz-actions" class="row">
<div class="col-md-8 text-left">
<h3>Your Score: <span id="result">{{ score }}</span></h3>
</div>
<div class="col-md-4 text-right">
<slot></slot>
</div>
2018-11-01 14:21:33 +00:00
</div>
2018-11-02 10:59:04 +00:00
<div v-else id="quiz-actions" class="text-right">
<button class='btn btn-outline-secondary' type="reset">Reset</button>
<button class='btn btn-primary' @click="submitQuiz" type="button">Submit</button>
2018-11-01 14:21:33 +00:00
</div>
</div>
</div>
2018-11-02 10:59:04 +00:00
</div>
2018-11-01 14:21:33 +00:00
</div>
<div class="mt-3 text-right">
<a class="text-muted" href="/report"><i class="octicon octicon-issue-opened" title="Report"></i> Report a
Mistake</a>
</div>
</div>
</section>
2018-11-01 11:50:04 +00:00
</template>
<script>
2018-11-01 14:21:33 +00:00
import QuizSingleChoice from "./Quiz/QuizSingleChoice.vue"
import QuizMultipleChoice from "./Quiz/QuizMultipleChoice.vue"
2018-11-01 11:50:04 +00:00
export default {
2018-11-01 14:21:33 +00:00
props: ['content', 'type'],
2018-11-13 11:54:07 +00:00
name: 'Quiz',
2018-11-01 14:21:33 +00:00
data() {
return {
2018-11-02 07:21:51 +00:00
quizData: '',
2018-11-02 10:59:04 +00:00
quizResponse: {},
score: '',
submitted: false
2018-11-01 14:21:33 +00:00
}
},
mounted() {
2018-11-19 09:42:39 +00:00
this.getQuizWithoutAnswers().then(data => {
this.quizData = data
2018-11-01 14:21:33 +00:00
});
},
components: {
'SingleChoice': QuizSingleChoice,
'MultipleChoice': QuizMultipleChoice
2018-11-02 07:21:51 +00:00
},
methods: {
2018-11-19 09:42:39 +00:00
getQuizWithoutAnswers() {
2018-11-20 12:06:57 +00:00
return lms.call("get_quiz_without_answers",
{
2018-11-19 09:42:39 +00:00
quiz_name: this.content,
}
2018-11-20 12:06:57 +00:00
)
2018-11-19 09:42:39 +00:00
},
2018-11-02 07:21:51 +00:00
updateResponse(res) {
if (res.type == 'SingleChoice') {
this.quizResponse[res.question] = (res.option)
}
if (res.type == 'MultipleChoice') {
if (!this.quizResponse[res.question]) {
this.quizResponse[res.question] = [res.option]
}
else {
this.quizResponse[res.question].push(res.option)
}
}
console.log(this.quizResponse)
2018-11-02 07:45:49 +00:00
},
submitQuiz() {
2018-11-20 12:06:57 +00:00
lms.call("evaluate_quiz",
{
2018-11-02 10:59:04 +00:00
quiz_response: this.quizResponse,
2019-02-28 11:12:25 +00:00
quiz_name: this.content,
course: this.$route.params.course_name
2018-11-02 07:45:49 +00:00
}
2018-11-20 12:06:57 +00:00
).then(data => {
2018-11-19 09:42:39 +00:00
this.score = data,
2018-11-02 10:59:04 +00:00
this.submitted = true,
this.quizResponse = null
});
2018-11-02 07:21:51 +00:00
}
},
computed: {
currentComponent: function() {
if(this.quizData.type === "MultipleChoice") {
return 'QuizMultipleChoice'
}
else {
return 'QuizSingleChoice'
}
},
},
2018-11-01 11:50:04 +00:00
};
</script>
<style lang="css" scoped>
</style>