Adding session management to client

This commit is contained in:
scmmishra 2018-11-03 14:48:42 +05:30 committed by Aditya Hase
parent 7a19b63837
commit bcafe84bb6
5 changed files with 96 additions and 22 deletions

View File

@ -19,30 +19,63 @@ var store = {
debug: true, debug: true,
state: { state: {
completedCourses: new Set(), completedCourses: new Set(),
enrolledPrograms: new Set(),
currentEnrollment: '', currentEnrollment: '',
currentStudentID: '', student: '',
isLogin: false
}, },
setCourseEnrollment (enrollment) {
setCurrentEnrollment (enrollment) {
if (this.debug) console.log('setCourseEnrollment triggered with', enrollment) if (this.debug) console.log('setCourseEnrollment triggered with', enrollment)
this.state.currentEnrollment = enrollment this.state.currentEnrollment = enrollment
}, },
getCurrentEnrollment () {
if (this.debug) console.log('getCourseEnrollment triggered')
return this.state.currentEnrollment
},
addCompletedCourses (courseName){ addCompletedCourses (courseName){
if (this.debug) console.log('addCompletedCourses triggered with', courseName) if (this.debug) console.log('addCompletedCourses triggered with', courseName)
this.state.completedCourses.add(courseName) this.state.completedCourses.add(courseName)
}, },
checkCourseCompletion (courseName){ checkCourseCompletion (courseName){
return this.state.completedCourses.has(courseName) return this.state.completedCourses.has(courseName)
}, },
updateState (){
checkProgramEnrollment (programName){
return this.state.enrolledPrograms.has(programName)
},
updateCompletedCourses (){
if (this.debug) console.log('Updating States') 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() this.state.completedCourses.clear()
for(var ii=0; ii < r.message.length; ii++){ for(var ii=0; ii < r.message.length; ii++){
this.state.completedCourses.add(r.message[ii]) this.state.completedCourses.add(r.message[ii])
} }
}) })
if (this.debug) console.log('Updated State', this.state.completedCourses) 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({ const router = new VueRouter({
@ -57,7 +90,9 @@ frappe.ready(() => {
template: "<academy-root/>", template: "<academy-root/>",
components: { AcademyRoot }, components: { AcademyRoot },
created: function() { created: function() {
store.updateState() if(store.checkLogin()){
store.updateState()
}
} }
}); });
}) })

View File

@ -32,15 +32,17 @@ export default {
} }
}, },
mounted() { mounted() {
frappe.call({ if(this.$root.$data.checkLogin()){
method: "erpnext.www.academy.get_starting_content", frappe.call({
args: { method: "erpnext.www.academy.get_starting_content",
course_name: this.course.name args: {
} course_name: this.course.name
}).then(r => { }
this.nextContent = r.message.content, }).then(r => {
this.nextContentType = r.message.content_type this.nextContent = r.message.content,
}); this.nextContentType = r.message.content_type
});
}
}, },
components: { components: {
AcademyCourseCardButton AcademyCourseCardButton

View File

@ -16,8 +16,9 @@
</section> </section>
</template> </template>
<script> <script>
import AcademyTopSectionButton from "./AcademyTopSectionButton.vue"
export default { export default {
props: ['title', 'description'], props: ['title', 'description', 'buttonName'],
name: "AcademyTopSection", name: "AcademyTopSection",
}; };
</script> </script>

View File

@ -0,0 +1,32 @@
<template>
<button class='btn btn-primary btn-lg' @click="$router.push()">{{ buttonName }}</button>
</template>
<script>
export default {
name: "AcademyTopSectionButton",
data() {
return {
buttonName: '',
url: {}
}
},
mounted() {
if(this.$route.name == 'home'){
this.buttonName = 'Explore Courses'
this.url = {}
}
else if(this.$route.name == 'program'){
this.buttonName = 'Start Course'
this.url = {
name: 'content',
params: {
code: this.$route.params.code,
course: this.$route.params.course,
type: this.nextContentType,
}
}
}
}
};
</script>

View File

@ -3,16 +3,16 @@ import frappe
import erpnext.education.utils as utils import erpnext.education.utils as utils
# Functions to get homepage details # Functions to get homepage details
@frappe.whitelist() @frappe.whitelist(allow_guest=True)
def get_portal_details(): def get_portal_details():
settings = frappe.get_doc("Education Settings") settings = frappe.get_doc("Education Settings")
title = settings.portal_title title = settings.portal_title
description = settings.description description = settings.description
return dict(title=title, description=description) return dict(title=title, description=description)
@frappe.whitelist() @frappe.whitelist(allow_guest=True)
def get_featured_programs(): 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] featured_list = [program["name"] for program in featured_program_names]
if featured_list: if featured_list:
return featured_list return featured_list
@ -20,7 +20,7 @@ def get_featured_programs():
return None return None
# Functions to get program & course details # Functions to get program & course details
@frappe.whitelist() @frappe.whitelist(allow_guest=True)
def get_program_details(program_name): def get_program_details(program_name):
try: try:
program = frappe.get_doc('Program', program_name) program = frappe.get_doc('Program', program_name)
@ -28,7 +28,7 @@ def get_program_details(program_name):
except: except:
return None return None
@frappe.whitelist() @frappe.whitelist(allow_guest=True)
def get_courses(program_name): def get_courses(program_name):
program = frappe.get_doc('Program', program_name) program = frappe.get_doc('Program', program_name)
courses = program.get_course_list() courses = program.get_course_list()
@ -103,4 +103,8 @@ def evaluate_quiz(quiz_response, quiz_name):
# return score # return score
# except frappe.DoesNotExistError: # except frappe.DoesNotExistError:
# frappe.throw("Quiz {0} does not exist".format(quiz_name)) # frappe.throw("Quiz {0} does not exist".format(quiz_name))
# return None # return None
@frappe.whitelist()
def get_completed_courses():
return ['ECP-001', 'ECP-002']