LMS: Saving Course Activity
diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py
index f7bce3a..69959ea 100644
--- a/erpnext/education/doctype/student/student.py
+++ b/erpnext/education/doctype/student/student.py
@@ -46,11 +46,11 @@
def get_course_enrollments(self):
"""Returns a list of course enrollments linked with the current student"""
- course_enrollments = frappe.get_list("Course Enrollment", filters={"student": self.name}, fields=['name'])
+ course_enrollments = frappe.get_list("Course Enrollment", filters={"student": self.name}, fields=['course', 'name'])
if not course_enrollments:
return None
else:
- enrollments = [item['name'] for item in course_enrollments]
+ enrollments = {item['course']:item['name'] for item in course_enrollments}
return enrollments
def get_program_enrollments(self):
diff --git a/erpnext/public/js/education/web-academy.js b/erpnext/public/js/education/web-academy.js
index 282a588..8608680 100644
--- a/erpnext/public/js/education/web-academy.js
+++ b/erpnext/public/js/education/web-academy.js
@@ -17,66 +17,55 @@
var store = {
debug: true,
- state: {
- completedCourses: new Set(),
- enrolledPrograms: new Set(),
- enrolledCourses: new Set(),
- currentEnrollment: '',
- student: '',
- isLogin: false
- },
-
- setCurrentEnrollment (enrollment) {
- if (this.debug) console.log('setCourseEnrollment triggered with', enrollment)
- this.state.currentEnrollment = enrollment
- },
-
- getCurrentEnrollment () {
- if (this.debug) console.log('getCourseEnrollment triggered')
- return this.state.currentEnrollment
- },
+ isLogin: false,
+ completedCourses: new Set(),
+ enrolledPrograms: new Set(),
+ enrolledCourses: {},
addCompletedCourses (courseName){
if (this.debug) console.log('addCompletedCourses triggered with', courseName)
- this.state.completedCourses.add(courseName)
+ this.completedCourses.add(courseName)
},
checkCourseCompletion (courseName){
- return this.state.completedCourses.has(courseName)
+ return this.completedCourses.has(courseName)
},
checkProgramEnrollment (programName){
- return this.state.enrolledPrograms.has(programName)
+ return this.enrolledPrograms.has(programName)
+ },
+
+ checkCourseEnrollment (courseName){
+ course = new Set(Object.keys(enrolledCourses))
+ return course.has(courseName)
},
updateEnrolledPrograms (){
if (this.debug) console.log('Updating enrolledPrograms')
frappe.call("erpnext.www.academy.get_program_enrollments").then( r => {
for(var ii=0; ii < r.message.length; ii++){
- this.state.enrolledPrograms.add(r.message[ii])
+ this.enrolledPrograms.add(r.message[ii])
}
})
- if (this.debug) console.log('Updated State', this.state.enrolledPrograms)
+ if (this.debug) console.log('Updated State', this.enrolledPrograms)
},
updateEnrolledCourses (){
if (this.debug) console.log('Updating enrolledCourses')
frappe.call("erpnext.www.academy.get_course_enrollments").then( r => {
- for(var ii=0; ii < r.message.length; ii++){
- this.state.enrolledCourses.add(r.message[ii])
- }
+ this.enrolledCourses = r.message
})
- if (this.debug) console.log('Updated State', this.state.enrolledCourses)
+ if (this.debug) console.log('Updated State', this.enrolledCourses)
},
updateCompletedCourses (){
if (this.debug) console.log('Updating States')
frappe.call("erpnext.www.academy.get_completed_courses").then( r => {
for(var ii=0; ii < r.message.length; ii++){
- this.state.completedCourses.add(r.message[ii])
+ this.completedCourses.add(r.message[ii])
}
})
- if (this.debug) console.log('Updated State', this.state.completedCourses)
+ if (this.debug) console.log('Updated State', this.completedCourses)
},
checkLogin (){
diff --git a/erpnext/public/js/education/web-academy/components/ContentNavigation.vue b/erpnext/public/js/education/web-academy/components/ContentNavigation.vue
index 87db221..a281f14 100644
--- a/erpnext/public/js/education/web-academy/components/ContentNavigation.vue
+++ b/erpnext/public/js/education/web-academy/components/ContentNavigation.vue
@@ -1,7 +1,7 @@
<template>
<div class="nav-buttons">
<button class='btn btn-outline-secondary' @click="$router.go(-1)">Back</button>
- <button v-if="nextContent" class='btn btn-primary' @click="$router.push({ name: 'content', params: { course: $route.params.course, type:nextContentType, content:nextContent }})">Next</button>
+ <button v-if="nextContent" class='btn btn-primary' @click="goNext()">Next</button>
<button v-else class='btn btn-primary' @click="$router.push({ name: 'program', params: { code: $route.params.code}})">Finish Course</button>
</div>
</template>
@@ -9,7 +9,20 @@
<script>
export default {
props: ['nextContent', 'nextContentType'],
- name: 'ContentNavigation'
+ 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
+ }
+ })
+ this.$router.push({ name: 'content', params: { course: this.$route.params.course, type:this.nextContentType, content:this.nextContent }})
+ }
+ }
};
</script>
diff --git a/erpnext/www/academy.py b/erpnext/www/academy.py
index 66874c6..9162b71 100644
--- a/erpnext/www/academy.py
+++ b/erpnext/www/academy.py
@@ -170,4 +170,16 @@
student = frappe.get_doc("Student", get_student_id(email))
return student.get_course_enrollments()
except:
- return None
\ No newline at end of file
+ return None
+
+@frappe.whitelist()
+def add_activity(enrollment, content_type, content):
+ activity = frappe.get_doc({
+ "doctype": "Course Activity",
+ "enrollment": enrollment,
+ "content_type": content_type,
+ "content": content,
+ "activity_date": frappe.utils.datetime.datetime.now()
+ })
+ activity.save()
+ frappe.db.commit()
\ No newline at end of file