105 lines
3.0 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"></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="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 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">Reset</button>
<button class='btn btn-primary' @click="submitQuiz" type="button">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
2018-11-01 19:51:33 +05:30
}
},
mounted() {
2018-11-19 15:12:39 +05:30
this.getQuizWithoutAnswers().then(data => {
this.quizData = data
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,
}
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 => {
2018-11-19 15:12:39 +05:30
this.score = data,
2018-11-02 16:29:04 +05:30
this.submitted = true,
this.quizResponse = null
});
2018-11-02 12:51:51 +05:30
}
},
computed: {
currentComponent: function() {
if(this.quizData.type === "MultipleChoice") {
return 'QuizMultipleChoice'
}
else {
return 'QuizSingleChoice'
}
},
},
2018-11-01 17:20:04 +05:30
};
</script>
<style lang="css" scoped>
</style>