Adding session management to client
This commit is contained in:
parent
7a19b63837
commit
bcafe84bb6
@ -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: "<academy-root/>",
|
||||
components: { AcademyRoot },
|
||||
created: function() {
|
||||
store.updateState()
|
||||
if(store.checkLogin()){
|
||||
store.updateState()
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
@ -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
|
||||
|
@ -16,8 +16,9 @@
|
||||
</section>
|
||||
</template>
|
||||
<script>
|
||||
import AcademyTopSectionButton from "./AcademyTopSectionButton.vue"
|
||||
export default {
|
||||
props: ['title', 'description'],
|
||||
props: ['title', 'description', 'buttonName'],
|
||||
name: "AcademyTopSection",
|
||||
};
|
||||
</script>
|
@ -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>
|
@ -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
|
||||
# return None
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_completed_courses():
|
||||
return ['ECP-001', 'ECP-002']
|
Loading…
x
Reference in New Issue
Block a user