diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py index f7bce3a5eb8..69959ea7847 100644 --- a/erpnext/education/doctype/student/student.py +++ b/erpnext/education/doctype/student/student.py @@ -46,11 +46,11 @@ class Student(Document): 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 282a5883d59..8608680648c 100644 --- a/erpnext/public/js/education/web-academy.js +++ b/erpnext/public/js/education/web-academy.js @@ -17,66 +17,55 @@ const routes = [ 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 87db2214523..a281f14fb93 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 @@ @@ -9,7 +9,20 @@ diff --git a/erpnext/www/academy.py b/erpnext/www/academy.py index 66874c62e5a..9162b711364 100644 --- a/erpnext/www/academy.py +++ b/erpnext/www/academy.py @@ -170,4 +170,16 @@ def get_course_enrollments(email=frappe.session.user): 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