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-10-30 12:55:49 +00:00
|
|
|
import AcademyRoot from "./web-academy/AcademyRoot.vue";
|
|
|
|
import AcademyHome from "./web-academy/pages/AcademyHome.vue";
|
|
|
|
import AcademyProgramPage from "./web-academy/pages/AcademyProgramPage.vue";
|
|
|
|
import AcademyCoursePage from "./web-academy/pages/AcademyCoursePage.vue";
|
|
|
|
|
|
|
|
Vue.use(VueRouter)
|
|
|
|
|
2018-11-02 15:20:55 +00:00
|
|
|
|
2018-10-30 12:55:49 +00:00
|
|
|
const routes = [
|
2018-11-01 11:47:30 +00:00
|
|
|
{name: 'home', path: '', component: AcademyHome},
|
|
|
|
{name: 'program', path: '/Program/:code', component: AcademyProgramPage, props: true},
|
|
|
|
{name: 'content', path: '/Program/:code/:course/:type/:content', component: AcademyCoursePage, props: true},
|
2018-10-30 12:55:49 +00:00
|
|
|
];
|
|
|
|
|
2018-11-02 15:20:55 +00:00
|
|
|
var store = {
|
2018-11-07 16:42:55 +00:00
|
|
|
debug: true,
|
2018-11-03 15:13:59 +00:00
|
|
|
isLogin: false,
|
|
|
|
completedCourses: new Set(),
|
|
|
|
enrolledPrograms: new Set(),
|
|
|
|
enrolledCourses: {},
|
2018-11-03 09:18:42 +00:00
|
|
|
|
2018-11-02 15:20:55 +00:00
|
|
|
addCompletedCourses (courseName){
|
|
|
|
if (this.debug) console.log('addCompletedCourses triggered with', courseName)
|
2018-11-03 15:13:59 +00:00
|
|
|
this.completedCourses.add(courseName)
|
2018-11-02 15:20:55 +00:00
|
|
|
},
|
2018-11-03 09:18:42 +00:00
|
|
|
|
2018-11-02 15:20:55 +00:00
|
|
|
checkCourseCompletion (courseName){
|
2018-11-03 15:13:59 +00:00
|
|
|
return this.completedCourses.has(courseName)
|
2018-11-02 15:20:55 +00:00
|
|
|
},
|
2018-11-03 09:18:42 +00:00
|
|
|
|
|
|
|
checkProgramEnrollment (programName){
|
2018-11-03 15:13:59 +00:00
|
|
|
return this.enrolledPrograms.has(programName)
|
|
|
|
},
|
|
|
|
|
|
|
|
checkCourseEnrollment (courseName){
|
|
|
|
course = new Set(Object.keys(enrolledCourses))
|
|
|
|
return course.has(courseName)
|
2018-11-03 09:18:42 +00:00
|
|
|
},
|
|
|
|
|
2018-11-03 14:03:04 +00:00
|
|
|
updateEnrolledPrograms (){
|
|
|
|
if (this.debug) console.log('Updating enrolledPrograms')
|
2018-11-05 05:31:54 +00:00
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.www.academy.get_program_enrollments",
|
|
|
|
args:{
|
|
|
|
email: frappe.session.user
|
|
|
|
}
|
|
|
|
}).then( r => {
|
2018-11-08 07:31:55 +00:00
|
|
|
if(r.message){
|
|
|
|
for(var ii=0; ii < r.message.length; ii++){
|
|
|
|
this.enrolledPrograms.add(r.message[ii])
|
|
|
|
}
|
2018-11-03 14:03:04 +00:00
|
|
|
}
|
|
|
|
})
|
2018-11-03 15:13:59 +00:00
|
|
|
if (this.debug) console.log('Updated State', this.enrolledPrograms)
|
2018-11-03 14:03:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateEnrolledCourses (){
|
|
|
|
if (this.debug) console.log('Updating enrolledCourses')
|
2018-11-05 05:31:54 +00:00
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.www.academy.get_course_enrollments",
|
|
|
|
args:{
|
|
|
|
email: frappe.session.user
|
|
|
|
}
|
|
|
|
}).then( r => {
|
2018-11-03 15:13:59 +00:00
|
|
|
this.enrolledCourses = r.message
|
2018-11-03 14:03:04 +00:00
|
|
|
})
|
2018-11-03 15:13:59 +00:00
|
|
|
if (this.debug) console.log('Updated State', this.enrolledCourses)
|
2018-11-03 14:03:04 +00:00
|
|
|
},
|
|
|
|
|
2018-11-03 09:18:42 +00:00
|
|
|
updateCompletedCourses (){
|
2018-11-02 15:20:55 +00:00
|
|
|
if (this.debug) console.log('Updating States')
|
2018-11-05 05:31:54 +00:00
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.www.academy.get_completed_courses",
|
|
|
|
args:{
|
|
|
|
email: frappe.session.user
|
|
|
|
}
|
|
|
|
}).then( r => {
|
2018-11-08 07:31:55 +00:00
|
|
|
if(r.message){
|
|
|
|
for(var ii=0; ii < r.message.length; ii++){
|
|
|
|
this.completedCourses.add(r.message[ii])
|
|
|
|
}
|
2018-11-02 15:20:55 +00:00
|
|
|
}
|
|
|
|
})
|
2018-11-03 15:13:59 +00:00
|
|
|
if (this.debug) console.log('Updated State', this.completedCourses)
|
2018-11-03 09:18:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
checkLogin (){
|
|
|
|
if(frappe.session.user === "Guest"){
|
|
|
|
if (this.debug) console.log('No Session')
|
|
|
|
this.isLogin = false
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (this.debug) console.log('Current User: ', frappe.session.user)
|
|
|
|
this.isLogin = true
|
|
|
|
}
|
|
|
|
return this.isLogin
|
|
|
|
},
|
|
|
|
|
|
|
|
updateState (){
|
|
|
|
this.updateCompletedCourses()
|
2018-11-03 14:03:04 +00:00
|
|
|
this.updateEnrolledPrograms()
|
|
|
|
this.updateEnrolledCourses()
|
2018-11-03 09:18:42 +00:00
|
|
|
this.checkLogin()
|
|
|
|
|
|
|
|
},
|
2018-11-02 15:20:55 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 12:55:49 +00:00
|
|
|
const router = new VueRouter({
|
|
|
|
routes: routes,
|
|
|
|
});
|
|
|
|
|
|
|
|
frappe.ready(() => {
|
2018-11-01 11:47:30 +00:00
|
|
|
window.v = new Vue({
|
2018-11-02 15:20:55 +00:00
|
|
|
el: "#academy",
|
2018-10-30 12:55:49 +00:00
|
|
|
router: router,
|
2018-11-02 15:20:55 +00:00
|
|
|
data: store,
|
2018-10-30 12:55:49 +00:00
|
|
|
template: "<academy-root/>",
|
2018-11-02 15:20:55 +00:00
|
|
|
components: { AcademyRoot },
|
|
|
|
created: function() {
|
2018-11-03 09:18:42 +00:00
|
|
|
if(store.checkLogin()){
|
|
|
|
store.updateState()
|
|
|
|
}
|
2018-11-02 15:20:55 +00:00
|
|
|
}
|
2018-10-30 12:55:49 +00:00
|
|
|
});
|
|
|
|
})
|