120 lines
3.7 KiB
Vue
Raw Normal View History

2018-11-01 17:20:04 +05:30
<template>
2018-11-01 19:51:33 +05:30
<section class="quiz-section">
2019-02-19 17:01:31 +05:30
<div>
2018-11-01 19:51:33 +05:30
<div class="row">
<div class="col-md-8">
<h2>{{ content }}</h2>
</div>
</div>
<div class="content">
<hr>
2018-11-02 16:29:04 +05:30
<div id="quiz" :name="content">
2018-11-01 19:51:33 +05:30
<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 19:51:33 +05:30
</div>
<div class="mt-3">
2018-11-02 16:29:04 +05:30
<div>
<div v-if="isDisabled || submitted" id="post-quiz-actions" class="row">
2018-11-02 16:29:04 +05:30
<div class="col-md-8 text-left">
<span v-html="message"></span>
2018-11-02 16:29:04 +05:30
</div>
<div class="col-md-4 text-right">
<slot></slot>
2018-11-02 16:29:04 +05:30
</div>
2018-11-01 19:51:33 +05:30
</div>
2018-11-02 16:29:04 +05:30
<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 19:51:33 +05:30
</div>
</div>
</div>
2018-11-02 16:29:04 +05:30
</div>
2018-11-01 19:51:33 +05:30
</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 17:20:04 +05:30
</template>
<script>
2018-11-01 19:51:33 +05:30
import QuizSingleChoice from "./Quiz/QuizSingleChoice.vue"
import QuizMultipleChoice from "./Quiz/QuizMultipleChoice.vue"
2018-11-01 17:20:04 +05:30
export default {
2018-11-01 19:51:33 +05:30
props: ['content', 'type'],
2018-11-13 17:24:07 +05:30
name: 'Quiz',
2018-11-01 19:51:33 +05:30
data() {
return {
2018-11-02 12:51:51 +05:30
quizData: '',
2018-11-02 16:29:04 +05:30
quizResponse: {},
score: '',
submitted: false,
isDisabled: false,
quizStatus: {},
2018-11-01 19:51:33 +05:30
}
},
mounted() {
2018-11-19 15:12:39 +05:30
this.getQuizWithoutAnswers().then(data => {
this.quizData = data.quizData
this.quizStatus = data.status
this.isDisabled = data.status.is_complete
2018-11-01 19:51:33 +05:30
});
},
components: {
'SingleChoice': QuizSingleChoice,
'MultipleChoice': QuizMultipleChoice
2018-11-02 12:51:51 +05:30
},
methods: {
2018-11-19 15:12:39 +05:30
getQuizWithoutAnswers() {
2018-11-20 17:36:57 +05:30
return lms.call("get_quiz_without_answers",
{
2018-11-19 15:12:39 +05:30
quiz_name: this.content,
course_name: this.$route.params.course_name
2018-11-19 15:12:39 +05:30
}
2018-11-20 17:36:57 +05:30
)
2018-11-19 15:12:39 +05:30
},
2018-11-02 12:51:51 +05:30
updateResponse(res) {
this.quizResponse[res.question] = res.option
2018-11-02 13:15:49 +05:30
},
submitQuiz() {
2018-11-20 17:36:57 +05:30
lms.call("evaluate_quiz",
{
2018-11-02 16:29:04 +05:30
quiz_response: this.quizResponse,
2019-02-28 16:42:25 +05:30
quiz_name: this.content,
course: this.$route.params.course_name
2018-11-02 13:15:49 +05:30
}
2018-11-20 17:36:57 +05:30
).then(data => {
this.score = data
this.submitted = true
2018-11-02 16:29:04 +05:30
this.quizResponse = null
});
2018-11-02 12:51:51 +05:30
}
},
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 17:20:04 +05:30
};
</script>
<style lang="css" scoped>
</style>