From 2b7e158e508e7fd7b217de173ef64fe4db9dd4f2 Mon Sep 17 00:00:00 2001 From: scmmishra Date: Fri, 29 Mar 2019 12:45:08 +0530 Subject: [PATCH] feat: Quiz attempt limits is configurable - Added a 'no limit' check to `check_quiz_completion` in utils.py - Added disabled flag for questions in quiz component - Refactored `get_quiz_without_answers` to send attempt limit data to client --- erpnext/education/utils.py | 2 +- .../js/education/lms/components/Quiz.vue | 35 +++++++++++++------ .../components/Quiz/QuizMultipleChoice.vue | 4 +-- .../lms/components/Quiz/QuizSingleChoice.vue | 4 +-- erpnext/www/lms.py | 13 ++++--- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py index a88f66b04c..641664c48e 100644 --- a/erpnext/education/utils.py +++ b/erpnext/education/utils.py @@ -135,7 +135,7 @@ def check_content_completion(content_name, content_type, enrollment_name): def check_quiz_completion(quiz, enrollment_name): attempts = frappe.get_all("Quiz Activity", filters={'enrollment': enrollment_name, 'quiz': quiz.name}, fields=["name", "activity_date", "score", "status"]) - status = bool(len(attempts) == quiz.max_attempts) + status = False if quiz.max_attempts == 0 else bool(len(attempts) == quiz.max_attempts) score = None result = None if attempts: diff --git a/erpnext/public/js/education/lms/components/Quiz.vue b/erpnext/public/js/education/lms/components/Quiz.vue index c0d6537a0d..0a6199a756 100644 --- a/erpnext/public/js/education/lms/components/Quiz.vue +++ b/erpnext/public/js/education/lms/components/Quiz.vue @@ -10,21 +10,21 @@
- +
-
+
-

Your Score: {{ score }}

+
- +
- - + +
@@ -50,12 +50,16 @@ export default { quizData: '', quizResponse: {}, score: '', - submitted: false + submitted: false, + isDisabled: false, + quizStatus: {}, } }, mounted() { this.getQuizWithoutAnswers().then(data => { - this.quizData = data + this.quizData = data.quizData + this.quizStatus = data.status + this.isDisabled = data.status.is_complete }); }, components: { @@ -67,6 +71,7 @@ export default { return lms.call("get_quiz_without_answers", { quiz_name: this.content, + course_name: this.$route.params.course_name } ) }, @@ -81,8 +86,8 @@ export default { course: this.$route.params.course_name } ).then(data => { - this.score = data, - this.submitted = true, + this.score = data + this.submitted = true this.quizResponse = null }); } @@ -96,6 +101,16 @@ export default { return 'QuizSingleChoice' } }, + message: function() { + if(this.submitted) { + return '

Your Score: '+ this.score +'

' + } + let message = '

You have exhausted all attempts for this quiz.

' + if(this.quizStatus.result == 'Pass') { + message = "

You have successfully completed this quiz.

Score: " + this.quizStatus.score + } + return message + } }, }; diff --git a/erpnext/public/js/education/lms/components/Quiz/QuizMultipleChoice.vue b/erpnext/public/js/education/lms/components/Quiz/QuizMultipleChoice.vue index 10c35f58c7..338b1ac0c5 100644 --- a/erpnext/public/js/education/lms/components/Quiz/QuizMultipleChoice.vue +++ b/erpnext/public/js/education/lms/components/Quiz/QuizMultipleChoice.vue @@ -3,7 +3,7 @@
{{ question.question }}
- + @@ -14,7 +14,7 @@