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

120 lines
3.7 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" :isDisabled="isDisabled"></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="isDisabled || submitted" id="post-quiz-actions" class="row">
2018-11-02 10:59:04 +00:00
<div class="col-md-8 text-left">
<span v-html="message"></span>
2018-11-02 10:59:04 +00:00
</div>
<div class="col-md-4 text-right">
<slot></slot>
2018-11-02 10:59:04 +00:00
</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" :disabled="isDisabled">Reset</button>
<button class='btn btn-primary' @click="submitQuiz" type="button" :disabled="isDisabled">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,
isDisabled: false,
quizStatus: {},
2018-11-01 14:21:33 +00:00
}
},
mounted() {
2018-11-19 09:42:39 +00:00
this.getQuizWithoutAnswers().then(data => {
this.quizData = data.quizData
this.quizStatus = data.status
this.isDisabled = data.status.is_complete
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,
course_name: this.$route.params.course_name
2018-11-19 09:42:39 +00:00
}
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) {
this.quizResponse[res.question] = res.option
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 => {
this.score = data
this.submitted = true
2018-11-02 10:59:04 +00:00
this.quizResponse = null
});
2018-11-02 07:21:51 +00:00
}
},
computed: {
currentComponent: function() {
if(this.quizData.type === "MultipleChoice") {
return 'QuizMultipleChoice'
}
else {
return 'QuizSingleChoice'
}
},
message: function() {
if(this.submitted) {
return '<h3>Your Score: <span id="result">'+ this.score +'</span></h3>'
}
let message = '<h4>You have exhausted all attempts for this quiz.</h4>'
if(this.quizStatus.result == 'Pass') {
message = "<h4>You have successfully completed this quiz.</h4>Score: " + this.quizStatus.score
}
return message
}
},
2018-11-01 11:50:04 +00:00
};
</script>
<style lang="css" scoped>
</style>