diff --git a/erpnext/public/js/education/lms/components/CourseCard.vue b/erpnext/public/js/education/lms/components/CourseCard.vue index 8aa553c823..ee4ad9571f 100644 --- a/erpnext/public/js/education/lms/components/CourseCard.vue +++ b/erpnext/public/js/education/lms/components/CourseCard.vue @@ -17,12 +17,12 @@
- - {{ courseMeta.flag }} + {{ buttonName }}
@@ -49,24 +49,39 @@ export default { }, 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 a98b86299f..9e902a8bd5 100644 --- a/erpnext/public/js/education/lms/lms.js +++ b/erpnext/public/js/education/lms/lms.js @@ -31,7 +31,6 @@ frappe.ready(() => { 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 @@ frappe.ready(() => { 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 @@ frappe.ready(() => { } 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 @@ frappe.ready(() => { 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 c807f690a0..07681910e0 100644 --- a/erpnext/public/js/education/lms/pages/ListPage.vue +++ b/erpnext/public/js/education/lms/pages/ListPage.vue @@ -1,6 +1,6 @@