diff --git a/erpnext/public/js/education/web-academy.js b/erpnext/public/js/education/web-academy.js index f37b8f04c0..9b96e6a086 100644 --- a/erpnext/public/js/education/web-academy.js +++ b/erpnext/public/js/education/web-academy.js @@ -1,5 +1,6 @@ import Vue from 'vue/dist/vue.js'; import VueRouter from 'vue-router/dist/vue-router.js' + import AcademyRoot from "./web-academy/AcademyRoot.vue"; import AcademyHome from "./web-academy/pages/AcademyHome.vue"; import AcademyProgramPage from "./web-academy/pages/AcademyProgramPage.vue"; @@ -7,21 +8,56 @@ import AcademyCoursePage from "./web-academy/pages/AcademyCoursePage.vue"; Vue.use(VueRouter) + const routes = [ {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}, ]; +var store = { + debug: true, + state: { + completedCourses: new Set(), + currentEnrollment: '', + currentStudentID: '', + }, + setCourseEnrollment (enrollment) { + if (this.debug) console.log('setCourseEnrollment triggered with', enrollment) + this.state.currentEnrollment = enrollment + }, + addCompletedCourses (courseName){ + if (this.debug) console.log('addCompletedCourses triggered with', courseName) + this.state.completedCourses.add(courseName) + }, + checkCourseCompletion (courseName){ + return this.state.completedCourses.has(courseName) + }, + updateState (){ + if (this.debug) console.log('Updating States') + frappe.call("erpnext.www.academy.get_state").then( r => { + this.state.completedCourses.clear() + for(var ii=0; ii < r.message.length; ii++){ + this.state.completedCourses.add(r.message[ii]) + } + }) + if (this.debug) console.log('Updated State', this.state.completedCourses) + } +} + const router = new VueRouter({ routes: routes, }); frappe.ready(() => { window.v = new Vue({ - el: "#web-academy", + el: "#academy", router: router, + data: store, template: "", - components: { AcademyRoot } + components: { AcademyRoot }, + created: function() { + store.updateState() + } }); }) \ No newline at end of file