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