Course completion logic complete
diff --git a/erpnext/public/js/education/web-academy/components/AcademyCourseCardButton.vue b/erpnext/public/js/education/web-academy/components/AcademyCourseCardButton.vue
index 10e52e4..7ff7a6e 100644
--- a/erpnext/public/js/education/web-academy/components/AcademyCourseCardButton.vue
+++ b/erpnext/public/js/education/web-academy/components/AcademyCourseCardButton.vue
@@ -1,5 +1,5 @@
<template>
- <button :class="className" class='btn btn-primary btn-sm btn-block' @click="$router.push($route.path + '/' + course + '/' + nextContentType + '/' + nextContent)">{{ buttonName }}</button>
+ <button :class="getClassName" class='btn btn-primary btn-sm btn-block' @click="$router.push($route.path + '/' + course + '/' + nextContentType + '/' + nextContent)">{{ getButtonName }}</button>
</template>
<script>
export default {
@@ -12,10 +12,22 @@
}
},
mounted() {
- if(this.$root.$data.checkCourseCompletion(this.course)){
- this.buttonName = 'Completed'
- this.className = 'btn-success'
- }
+ this.$root.$data.updateCompletedCourses()
+ }
+ computed: {
+ getButtonName: function() {
+ if(this.$root.$data.checkCourseCompletion(this.course)){
+ return 'Completed'
+ }
+ else{
+ return 'Start'
+ }
+ },
+ getClassName: function() {
+ if(this.$root.$data.checkCourseCompletion(this.course)){
+ return 'btn-success'
+ }
+ }
}
};
</script>
\ No newline at end of file
diff --git a/erpnext/public/js/education/web-academy/components/ContentNavigation.vue b/erpnext/public/js/education/web-academy/components/ContentNavigation.vue
index 738dcd9..1ea5fca 100644
--- a/erpnext/public/js/education/web-academy/components/ContentNavigation.vue
+++ b/erpnext/public/js/education/web-academy/components/ContentNavigation.vue
@@ -1,8 +1,8 @@
<template>
<div class="nav-buttons">
<button class='btn btn-outline-secondary' @click="$router.go(-1)">Back</button>
- <button v-show="nextContent" class='btn btn-primary' @click="goNext()">Next</button>
- <button v-show="!nextContent" class='btn btn-primary' @click="finish()">Finish Course</button>
+ <button v-if="nextContent" class='btn btn-primary' @click="goNext()">Next</button>
+ <button v-else class='btn btn-primary' @click="finish()">Finish Course</button>
</div>
</template>
@@ -12,14 +12,16 @@
name: 'ContentNavigation',
methods: {
goNext() {
- frappe.call({
- method: "erpnext.www.academy.add_activity",
- args: {
- enrollment: this.$root.$data.enrolledCourses[this.$route.params.course],
- content_type: this.$route.params.type,
- content: this.$route.params.content
- }
- })
+ if(this.$route.params.type != "Quiz"){
+ frappe.call({
+ method: "erpnext.www.academy.add_activity",
+ args: {
+ enrollment: this.$root.$data.enrolledCourses[this.$route.params.course],
+ content_type: this.$route.params.type,
+ content: this.$route.params.content
+ }
+ })
+ }
this.$router.push({ name: 'content', params: { course: this.$route.params.course, type:this.nextContentType, content:this.nextContent }})
},
finish() {
@@ -33,6 +35,12 @@
}
})
}
+ frappe.call({
+ method: "erpnext.www.academy.mark_course_complete",
+ args: {
+ enrollment: this.$root.$data.enrolledCourses[this.$route.params.course]
+ }
+ })
this.$router.push({ name: 'program', params: { code: this.$route.params.code}})
}
}
diff --git a/erpnext/public/js/education/web-academy/pages/AcademyCoursePage.vue b/erpnext/public/js/education/web-academy/pages/AcademyCoursePage.vue
index 4149f4d..ca5434b 100644
--- a/erpnext/public/js/education/web-academy/pages/AcademyCoursePage.vue
+++ b/erpnext/public/js/education/web-academy/pages/AcademyCoursePage.vue
@@ -16,7 +16,7 @@
name: "AcademyCoursePage",
data() {
return{
- nextContent: true,
+ nextContent: '',
nextContentType: '',
}
},
diff --git a/erpnext/www/academy.py b/erpnext/www/academy.py
index 69faeba..d68dee4 100644
--- a/erpnext/www/academy.py
+++ b/erpnext/www/academy.py
@@ -89,11 +89,8 @@
"""
import json
quiz_response = json.loads(quiz_response)
- print(quiz_response)
quiz = frappe.get_doc("Quiz", quiz_name)
answers, score, status = quiz.evaluate(quiz_response, quiz_name)
- print("-----------------")
- print(answers)
result = {k: ('Correct' if v else 'Wrong') for k,v in answers.items()}
result_data = []
@@ -113,7 +110,6 @@
@frappe.whitelist()
def get_completed_courses(email=frappe.session.user):
- print("Get completed course ", email)
try:
student = frappe.get_doc("Student", get_student_id(email))
return student.get_completed_courses()
@@ -208,5 +204,11 @@
"status": status
})
quiz_activity.save()
- print(quiz_activity)
- frappe.db.commit()
\ No newline at end of file
+ frappe.db.commit()
+
+@frappe.whitelist()
+def mark_course_complete(enrollment):
+ course_enrollment = frappe.get_doc("Course Enrollment", enrollment)
+ course_enrollment.completed = True
+ course_enrollment.save()
+ frappe.db.commit()