Using lms.call across the Vue app
diff --git a/erpnext/public/js/education/lms/components/ContentNavigation.vue b/erpnext/public/js/education/lms/components/ContentNavigation.vue
index 7495717..40420be 100644
--- a/erpnext/public/js/education/lms/components/ContentNavigation.vue
+++ b/erpnext/public/js/education/lms/components/ContentNavigation.vue
@@ -11,10 +11,10 @@
props: ['nextContent', 'nextContentType'],
name: 'ContentNavigation',
methods: {
- goNext() {
+ addActivity() {
if(this.$route.params.type != "Quiz"){
- frappe.call({
- method: "erpnext.www.lms.add_activity",
+ lms.call({
+ method: "add_activity",
args: {
enrollment: lms.store.enrolledCourses[this.$route.params.course],
content_type: this.$route.params.type,
@@ -22,29 +22,14 @@
}
})
}
+ },
+ goNext() {
+ this.addActivity()
this.$router.push({ name: 'content', params: { course: this.$route.params.course, type:this.nextContentType, content:this.nextContent }})
},
finish() {
- if(this.$route.params.type != "Quiz"){
- frappe.call({
- method: "erpnext.www.lms.add_activity",
- args: {
- enrollment: lms.store.enrolledCourses[this.$route.params.course],
- content_type: this.$route.params.type,
- content: this.$route.params.content
- }
- })
- }
- frappe.call({
- method: "erpnext.www.lms.mark_course_complete",
- args: {
- enrollment: lms.store.enrolledCourses[this.$route.params.course]
- }
- })
- // lms.store.addCompletedCourses(this.$route.params.course)
- lms.store.updateCompletedCourses()
+ this.addActivity()
this.$router.push({ name: 'program', params: { program_name: this.$route.params.program_name}})
-
//
lms.trigger('course-completed', course_name);
}
diff --git a/erpnext/public/js/education/lms/components/Quiz.vue b/erpnext/public/js/education/lms/components/Quiz.vue
index d3dc1c7..92d6a94 100644
--- a/erpnext/public/js/education/lms/components/Quiz.vue
+++ b/erpnext/public/js/education/lms/components/Quiz.vue
@@ -52,32 +52,35 @@
}
},
mounted() {
- frappe.call({
- method: "erpnext.www.lms.get_quiz_without_answers",
- args: {
- quiz_name: this.content,
- }
- }).then(r => {
- this.quizData = r.message
+ this.getQuizWithoutAnswers().then(data => {
+ this.quizData = data
});
},
components: {
QuizSingleChoice,
},
methods: {
+ getQuizWithoutAnswers() {
+ return lms.call({
+ method: "get_quiz_without_answers",
+ args: {
+ quiz_name: this.content,
+ }
+ })
+ },
updateResponse(res) {
this.quizResponse[res.question] = (res.option)
},
submitQuiz() {
- frappe.call({
- method: "erpnext.www.lms.evaluate_quiz",
+ lms.call({
+ method: "evaluate_quiz",
args: {
enrollment: lms.store.enrolledCourses[this.$route.params.course],
quiz_response: this.quizResponse,
quiz_name: this.content
}
- }).then(r => {
- this.score = r.message,
+ }).then(data => {
+ this.score = data,
this.submitted = true,
this.quizResponse = null
});
diff --git a/erpnext/public/js/education/lms/components/TopSectionButton.vue b/erpnext/public/js/education/lms/components/TopSectionButton.vue
index 85897d8..895cae8 100644
--- a/erpnext/public/js/education/lms/components/TopSectionButton.vue
+++ b/erpnext/public/js/education/lms/components/TopSectionButton.vue
@@ -17,36 +17,41 @@
},
mounted() {
if(this.isLoggedIn && this.$route.name == 'program'){
- frappe.call({
- method: "erpnext.www.lms.get_continue_data",
+ this.getContinueData().then( data => {
+ this.nextContent = data.content,
+ this.nextContentType = data.content_type,
+ this.nextCourse = data.course
+ })
+ }
+ this.computeButtons()
+ },
+ methods: {
+ computeButtons(){
+ if(this.isLoggedIn){
+ if(lms.store.enrolledPrograms.has(this.$route.params.program_name)){
+ if(this.$route.name == 'home'){
+ this.buttonName = 'Explore Courses'
+ }
+ else if(this.$route.name == 'program'){
+ this.buttonName = 'Start Course'
+ }
+ }
+ else {
+ this.buttonName = 'Enroll Now'
+ }
+ }
+ else{
+ this.buttonName = 'Sign Up'
+ }
+ },
+ getContinueData() {
+ lms.call({
+ method: "get_continue_data",
args: {
program_name: this.$route.params.program_name
}
- }).then( r => {
- this.nextContent = r.message.content,
- this.nextContentType = r.message.content_type,
- this.nextCourse = r.message.course
})
- }
-
- if(this.isLoggedIn){
- if(lms.store.enrolledPrograms.has(this.$route.params.program_name)){
- if(this.$route.name == 'home'){
- this.buttonName = 'Explore Courses'
- }
- else if(this.$route.name == 'program'){
- this.buttonName = 'Start Course'
- }
- }
- else {
- this.buttonName = 'Enroll Now'
- }
- }
- else{
- this.buttonName = 'Sign Up'
- }
- },
- methods: {
+ },
primaryAction() {
if(this.$route.name == 'home'){
return
@@ -55,8 +60,8 @@
this.$router.push({ name: 'content', params: { program_name: this.$route.params.program_name, course: this.nextCourse, type: this.nextContentType, content: this.nextContent}})
}
else {
- frappe.call({
- method: "erpnext.www.lms.enroll_in_program",
+ lms.call({
+ method: "enroll_in_program",
args:{
program_name: this.$route.params.program_name,
student_email_id: frappe.session.user
diff --git a/erpnext/public/js/education/lms/lms.js b/erpnext/public/js/education/lms/lms.js
index a2a552e..47221bc 100644
--- a/erpnext/public/js/education/lms/lms.js
+++ b/erpnext/public/js/education/lms/lms.js
@@ -66,7 +66,7 @@
template: "<lms-root/>",
components: { lmsRoot },
mounted() {
- lms.store.updateState()
+ if(lms.store.isLogin) lms.store.updateState()
}
});
diff --git a/erpnext/public/js/education/lms/pages/CoursePage.vue b/erpnext/public/js/education/lms/pages/CoursePage.vue
index f838575..22d51cd 100644
--- a/erpnext/public/js/education/lms/pages/CoursePage.vue
+++ b/erpnext/public/js/education/lms/pages/CoursePage.vue
@@ -34,18 +34,23 @@
},
},
mounted() {
- frappe.call({
- method: "erpnext.www.lms.get_next_content",
- args:{
- content: this.content,
- content_type: this.type,
- course: this.course
- }
- }).then(r => {
+ this.getNextContent().then(data => {
this.nextContent = r.message.content,
this.nextContentType = r.message.content_type
});
},
+ methods: {
+ getNextContent(){
+ return lms.call({
+ method: "get_next_content",
+ args:{
+ content: this.content,
+ content_type: this.type,
+ course: this.course
+ }
+ });
+ }
+ },
components: {
Article,
Video,