From bcafe84bb6211754a65d661ec8e5903fdd0cf5fc Mon Sep 17 00:00:00 2001 From: scmmishra Date: Sat, 3 Nov 2018 14:48:42 +0530 Subject: [PATCH] Adding session management to client --- erpnext/public/js/education/web-academy.js | 47 ++++++++++++++++--- .../components/AcademyCourseCard.vue | 20 ++++---- .../components/AcademyTopSection.vue | 3 +- .../components/AcademyTopSectionButton.vue | 32 +++++++++++++ erpnext/www/academy.py | 16 ++++--- 5 files changed, 96 insertions(+), 22 deletions(-) create mode 100644 erpnext/public/js/education/web-academy/components/AcademyTopSectionButton.vue diff --git a/erpnext/public/js/education/web-academy.js b/erpnext/public/js/education/web-academy.js index 9b96e6a086..2d6a1b909d 100644 --- a/erpnext/public/js/education/web-academy.js +++ b/erpnext/public/js/education/web-academy.js @@ -19,30 +19,63 @@ var store = { debug: true, state: { completedCourses: new Set(), + enrolledPrograms: new Set(), currentEnrollment: '', - currentStudentID: '', + student: '', + isLogin: false }, - setCourseEnrollment (enrollment) { + + 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 + }, + addCompletedCourses (courseName){ if (this.debug) console.log('addCompletedCourses triggered with', courseName) this.state.completedCourses.add(courseName) }, + checkCourseCompletion (courseName){ return this.state.completedCourses.has(courseName) }, - updateState (){ + + checkProgramEnrollment (programName){ + return this.state.enrolledPrograms.has(programName) + }, + + updateCompletedCourses (){ if (this.debug) console.log('Updating States') - frappe.call("erpnext.www.academy.get_state").then( r => { + frappe.call("erpnext.www.academy.get_completed_courses").then( r => { this.state.completedCourses.clear() for(var ii=0; ii < r.message.length; ii++){ this.state.completedCourses.add(r.message[ii]) } }) if (this.debug) console.log('Updated State', this.state.completedCourses) - } + }, + + checkLogin (){ + if(frappe.session.user === "Guest"){ + if (this.debug) console.log('No Session') + this.isLogin = false + } + else { + if (this.debug) console.log('Current User: ', frappe.session.user) + this.isLogin = true + } + return this.isLogin + }, + + updateState (){ + this.updateCompletedCourses() + this.checkLogin() + + }, } const router = new VueRouter({ @@ -57,7 +90,9 @@ frappe.ready(() => { template: "", components: { AcademyRoot }, created: function() { - store.updateState() + if(store.checkLogin()){ + store.updateState() + } } }); }) \ No newline at end of file diff --git a/erpnext/public/js/education/web-academy/components/AcademyCourseCard.vue b/erpnext/public/js/education/web-academy/components/AcademyCourseCard.vue index 5fc44cc7fa..4110cd9d1c 100644 --- a/erpnext/public/js/education/web-academy/components/AcademyCourseCard.vue +++ b/erpnext/public/js/education/web-academy/components/AcademyCourseCard.vue @@ -32,15 +32,17 @@ export default { } }, mounted() { - frappe.call({ - method: "erpnext.www.academy.get_starting_content", - args: { - course_name: this.course.name - } - }).then(r => { - this.nextContent = r.message.content, - this.nextContentType = r.message.content_type - }); + if(this.$root.$data.checkLogin()){ + frappe.call({ + method: "erpnext.www.academy.get_starting_content", + args: { + course_name: this.course.name + } + }).then(r => { + this.nextContent = r.message.content, + this.nextContentType = r.message.content_type + }); + } }, components: { AcademyCourseCardButton diff --git a/erpnext/public/js/education/web-academy/components/AcademyTopSection.vue b/erpnext/public/js/education/web-academy/components/AcademyTopSection.vue index 93724c6d50..7bd1b35e41 100644 --- a/erpnext/public/js/education/web-academy/components/AcademyTopSection.vue +++ b/erpnext/public/js/education/web-academy/components/AcademyTopSection.vue @@ -16,8 +16,9 @@ \ No newline at end of file diff --git a/erpnext/public/js/education/web-academy/components/AcademyTopSectionButton.vue b/erpnext/public/js/education/web-academy/components/AcademyTopSectionButton.vue new file mode 100644 index 0000000000..2af1eaf117 --- /dev/null +++ b/erpnext/public/js/education/web-academy/components/AcademyTopSectionButton.vue @@ -0,0 +1,32 @@ + + \ No newline at end of file diff --git a/erpnext/www/academy.py b/erpnext/www/academy.py index 024afc2844..dd2a7d003d 100644 --- a/erpnext/www/academy.py +++ b/erpnext/www/academy.py @@ -3,16 +3,16 @@ import frappe import erpnext.education.utils as utils # Functions to get homepage details -@frappe.whitelist() +@frappe.whitelist(allow_guest=True) def get_portal_details(): settings = frappe.get_doc("Education Settings") title = settings.portal_title description = settings.description return dict(title=title, description=description) -@frappe.whitelist() +@frappe.whitelist(allow_guest=True) def get_featured_programs(): - featured_program_names = frappe.get_list("Program", filters={"is_published": True, "is_featured": True}) + featured_program_names = frappe.get_all("Program", filters={"is_published": True, "is_featured": True}) featured_list = [program["name"] for program in featured_program_names] if featured_list: return featured_list @@ -20,7 +20,7 @@ def get_featured_programs(): return None # Functions to get program & course details -@frappe.whitelist() +@frappe.whitelist(allow_guest=True) def get_program_details(program_name): try: program = frappe.get_doc('Program', program_name) @@ -28,7 +28,7 @@ def get_program_details(program_name): except: return None -@frappe.whitelist() +@frappe.whitelist(allow_guest=True) def get_courses(program_name): program = frappe.get_doc('Program', program_name) courses = program.get_course_list() @@ -103,4 +103,8 @@ def evaluate_quiz(quiz_response, quiz_name): # return score # except frappe.DoesNotExistError: # frappe.throw("Quiz {0} does not exist".format(quiz_name)) - # return None \ No newline at end of file + # return None + +@frappe.whitelist() +def get_completed_courses(): + return ['ECP-001', 'ECP-002'] \ No newline at end of file