Adding session management to client
diff --git a/erpnext/public/js/education/web-academy.js b/erpnext/public/js/education/web-academy.js
index 9b96e6a..2d6a1b9 100644
--- a/erpnext/public/js/education/web-academy.js
+++ b/erpnext/public/js/education/web-academy.js
@@ -19,30 +19,63 @@
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 @@
template: "<academy-root/>",
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 5fc44cc..4110cd9 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 @@
}
},
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 93724c6..7bd1b35 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 @@
</section>
</template>
<script>
+import AcademyTopSectionButton from "./AcademyTopSectionButton.vue"
export default {
- props: ['title', 'description'],
+ props: ['title', 'description', 'buttonName'],
name: "AcademyTopSection",
};
</script>
\ 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 0000000..2af1eaf
--- /dev/null
+++ b/erpnext/public/js/education/web-academy/components/AcademyTopSectionButton.vue
@@ -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>
\ No newline at end of file
diff --git a/erpnext/www/academy.py b/erpnext/www/academy.py
index 024afc2..dd2a7d0 100644
--- a/erpnext/www/academy.py
+++ b/erpnext/www/academy.py
@@ -3,16 +3,16 @@
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 @@
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 @@
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 @@
# 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