This commit is contained in:
scmmishra 2018-12-06 20:13:20 +05:30 committed by Aditya Hase
parent 798f13be0d
commit b3154efa84
5 changed files with 82 additions and 31 deletions

View File

@ -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 @@ 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: {

View File

@ -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
})

View File

@ -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'">

View File

@ -4,20 +4,32 @@ import ContentPage from "./pages/ContentPage.vue";
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 @@ const routes = [
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 @@ const routes = [
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()
}
}

View File

@ -5,8 +5,11 @@ import frappe
# 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 @@ def check_quiz_completion(quiz, enrollment_name):
@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)