72 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-10-30 18:25:49 +05:30
import Vue from 'vue/dist/vue.js';
import VueRouter from 'vue-router/dist/vue-router.js'
2018-11-13 17:03:18 +05:30
import lmsRoot from "./lmsRoot.vue";
2018-11-09 11:47:09 +05:30
import routes from './routes';
import './call';
2018-10-30 18:25:49 +05:30
Vue.use(VueRouter)
2018-11-09 18:25:19 +05:30
var store = {
2018-11-03 20:43:59 +05:30
isLogin: false,
2018-11-19 17:08:40 +05:30
enrolledPrograms: [],
2018-11-09 18:25:19 +05:30
enrolledCourses: {}
}
2018-10-30 18:25:49 +05:30
frappe.ready(() => {
2018-11-13 16:47:46 +05:30
frappe.provide('lms')
// frappe.utils.make_event_emitter(lms);
2018-11-09 18:25:19 +05:30
2018-11-13 16:47:46 +05:30
lms.store = new Vue({
2018-11-09 11:47:09 +05:30
data: store,
methods: {
2018-11-15 11:13:56 +05:30
updateEnrolledPrograms() {
if(this.isLogin) {
lms.call("get_program_enrollments").then(data => {
2018-11-23 17:16:33 +05:30
this.enrolledPrograms = data
2018-11-15 11:13:56 +05:30
});
if (lms.debug) console.log('Updated Enrolled Programs', this.enrolledPrograms)
}
2018-11-09 18:25:19 +05:30
},
2018-11-15 11:13:56 +05:30
updateEnrolledCourses() {
2018-11-23 17:16:33 +05:30
if(this.isLogin) {
lms.call("get_all_course_enrollments").then(data => {
this.enrolledCourses = data
})
if (lms.debug) console.log('Updated Enrolled Courses', this.enrolledCourses)
}
2018-11-09 18:25:19 +05:30
},
2018-11-15 11:13:56 +05:30
checkLogin() {
2018-11-09 11:47:09 +05:30
if(frappe.session.user === "Guest"){
2018-11-13 16:47:46 +05:30
if (lms.debug) console.log('No Session')
2018-11-09 11:47:09 +05:30
this.isLogin = false
}
else {
2018-11-13 16:47:46 +05:30
if (lms.debug) console.log('Current User: ', frappe.session.user)
2018-11-09 11:47:09 +05:30
this.isLogin = true
}
return this.isLogin
2018-11-09 18:25:19 +05:30
},
2018-11-15 11:13:56 +05:30
updateState() {
this.checkLogin()
2018-11-09 18:25:19 +05:30
this.updateEnrolledPrograms()
this.updateEnrolledCourses()
},
}
});
2018-11-13 16:47:46 +05:30
lms.view = new Vue({
el: "#lms-app",
2018-11-09 18:25:19 +05:30
router: new VueRouter({ routes }),
2018-11-13 17:03:18 +05:30
template: "<lms-root/>",
components: { lmsRoot },
2018-11-15 11:13:56 +05:30
mounted() {
2018-11-19 15:12:39 +05:30
if(lms.store.isLogin) lms.store.updateState()
2018-11-09 11:47:09 +05:30
}
});
2018-11-09 18:25:19 +05:30
2018-11-13 16:47:46 +05:30
lms.debug = true
2018-10-30 18:25:49 +05:30
})