UI Fixes
diff --git a/erpnext/public/js/education/lms/components/CourseCard.vue b/erpnext/public/js/education/lms/components/CourseCard.vue
index 8aa553c..ee4ad95 100644
--- a/erpnext/public/js/education/lms/components/CourseCard.vue
+++ b/erpnext/public/js/education/lms/components/CourseCard.vue
@@ -17,12 +17,12 @@
</span>
</div>
<div class='course-buttons text-center col-xs-4 col-sm-3 col-md-2'>
- <a-button
+ <a-button v-if="isLogin"
:type="buttonType"
size="sm btn-block"
:route="firstContentRoute"
>
- {{ courseMeta.flag }}
+ {{ buttonName }}
</a-button>
</div>
</div>
@@ -49,24 +49,39 @@
},
computed: {
firstContentRoute() {
- return `${this.program_name}/${this.course.name}/${this.courseMeta.content_type}/${this.courseMeta.content}`
+ if(lms.store.checkLogin()){
+ return `${this.program_name}/${this.course.name}/${this.courseMeta.content_type}/${this.courseMeta.content}`
+ }
+ else {
+ return {}
+ }
},
buttonType() {
- if (this.courseMeta.flag == "Start Course" ){
+ if(lms.store.checkProgramEnrollment(this.program_name)){
+ if (this.courseMeta.flag == "Start Course" ){
return "primary"
- }
- else if (this.courseMeta.flag == "Completed" ) {
- return "success"
- }
- else if (this.courseMeta.flag == "Continue" ) {
- return "info"
+ }
+ else if (this.courseMeta.flag == "Completed" ) {
+ return "success"
+ }
+ else if (this.courseMeta.flag == "Continue" ) {
+ return "info"
+ }
}
else {
return " hidden"
}
},
isLogin() {
- return lms.store.checkLogin()
+ return lms.store.checkProgramEnrollment(this.program_name)
+ },
+ buttonName() {
+ if(lms.store.checkLogin()){
+ return this.courseMeta.flag
+ }
+ else {
+ return "Enroll"
+ }
}
},
methods: {
diff --git a/erpnext/public/js/education/lms/lms.js b/erpnext/public/js/education/lms/lms.js
index a98b862..9e902a8 100644
--- a/erpnext/public/js/education/lms/lms.js
+++ b/erpnext/public/js/education/lms/lms.js
@@ -31,7 +31,6 @@
if (lms.debug) console.log('Updated Enrolled Programs', this.enrolledPrograms)
}
},
-
updateEnrolledCourses() {
if(this.isLogin) {
lms.call("get_all_course_enrollments").then(data => {
@@ -40,7 +39,6 @@
if (lms.debug) console.log('Updated Enrolled Courses', this.enrolledCourses)
}
},
-
checkLogin() {
if(frappe.session.user === "Guest"){
if (lms.debug) console.log('No Session')
@@ -52,15 +50,31 @@
}
return this.isLogin
},
-
updateState() {
this.checkLogin()
this.updateEnrolledPrograms()
this.updateEnrolledCourses()
},
+ checkProgramEnrollment(programName) {
+ if(this.checkLogin()){
+ if(this.enrolledPrograms) {
+ if(this.enrolledPrograms.includes(programName)) {
+ return true
+ }
+ else {
+ return false
+ }
+ }
+ else {
+ return false
+ }
+ }
+ else {
+ return false
+ }
+ }
}
});
-
lms.view = new Vue({
el: "#lms-app",
router: new VueRouter({ routes }),
@@ -70,5 +84,8 @@
if(lms.store.isLogin) lms.store.updateState()
}
});
+ lms.view.$router.afterEach((to, from) => {
+ window.scrollTo(0,0)
+ })
lms.debug = true
})
\ No newline at end of file
diff --git a/erpnext/public/js/education/lms/pages/ListPage.vue b/erpnext/public/js/education/lms/pages/ListPage.vue
index c807f69..0768191 100644
--- a/erpnext/public/js/education/lms/pages/ListPage.vue
+++ b/erpnext/public/js/education/lms/pages/ListPage.vue
@@ -1,6 +1,6 @@
<template>
<div>
- <TopSection :title="portal.title" :description="portal.description">
+ <TopSection :title="'Programs at ' + portal.title" :description="portal.description">
<AButton v-if="isLogin" :type="'primary'" :size="'lg'" :route="{ name: 'signup'}">Sign Up</AButton>
</TopSection>
<CardList :title="'All Programs'" :description="''" :sectionType="'section-padding section-bg'">
diff --git a/erpnext/public/js/education/lms/routes.js b/erpnext/public/js/education/lms/routes.js
index 020c597..65c7dba 100644
--- a/erpnext/public/js/education/lms/routes.js
+++ b/erpnext/public/js/education/lms/routes.js
@@ -4,20 +4,32 @@
import ListPage from "./pages/ListPage.vue";
import ProfilePage from "./pages/ProfilePage.vue";
-const routes = [
- {name: 'home', path: '', component: Home},
- {name: 'program', path: '/Program/:program_name', component: ProgramPage, props: true},
+const routes = [{
+ name: 'home',
+ path: '',
+ component: Home
+ },
+ {
+ name: 'program',
+ path: '/Program/:program_name',
+ component: ProgramPage,
+ props: true
+ },
{
name: 'content',
path: '/Program/:program_name/:course/:type/:content',
component: ContentPage,
props: true,
beforeEnter: (to, from, next) => {
- if(!lms.store.checkLogin()){
- next({name: 'home'})
- }
- else {
+ if (lms.store.checkProgramEnrollment(this.program_name)) {
next()
+ } else {
+ next({
+ name: 'program',
+ params: {
+ program_name: to.params.program_name
+ }
+ })
}
}
},
@@ -31,9 +43,9 @@
name: 'signup',
path: '/Signup',
beforeEnter(to, from, next) {
- window.location = window.location.origin.toString() +'/login#signup'
- },
- component: ListPage,
+ window.location = window.location.origin.toString() + '/login#signup'
+ },
+ component: Home,
props: true
},
{
@@ -42,10 +54,11 @@
component: ProfilePage,
props: true,
beforeEnter: (to, from, next) => {
- if(!lms.store.checkLogin()){
- next({name: 'home'})
- }
- else {
+ if (!lms.store.checkLogin()) {
+ next({
+ name: 'home'
+ })
+ } else {
next()
}
}
diff --git a/erpnext/www/lms.py b/erpnext/www/lms.py
index c106a2a..261330b 100644
--- a/erpnext/www/lms.py
+++ b/erpnext/www/lms.py
@@ -5,8 +5,11 @@
# LMS Utils to Update State for Vue Store
@frappe.whitelist()
def get_program_enrollments():
+ student = utils.get_current_student()
+ if student == None:
+ return None
try:
- student = frappe.get_doc("Student", utils.get_current_student())
+ student = frappe.get_doc("Student", student)
return student.get_program_enrollments()
except:
return None
@@ -201,6 +204,9 @@
@frappe.whitelist()
def get_course_meta(course_name, program_name):
course_enrollment = utils.get_course_enrollment(course_name)
+ program_enrollment = utils.get_program_enrollment(program_name)
+ if not program_enrollment:
+ return None
if not course_enrollment:
utils.enroll_in_course(course_name, program_name)
progress = get_course_progress(course_enrollment)