Fixed course and content page

This commit is contained in:
scmmishra 2018-11-12 12:50:54 +05:30 committed by Aditya Hase
parent db9c8b795a
commit f9b2fb6717
10 changed files with 67 additions and 91 deletions

View File

@ -62,7 +62,7 @@
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"in_standard_filter": 1,
"label": "Student",
"length": 0,
"no_copy": 0,
@ -190,7 +190,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-11-07 21:16:34.764628",
"modified": "2018-11-09 19:23:07.967967",
"modified_by": "Administrator",
"module": "Education",
"name": "Course Enrollment",

View File

@ -11,29 +11,13 @@
</ul>
</span>
</div>
<div v-if="$root.$data.isLogin" class='course-buttons text-center col-xs-4 col-sm-3 col-md-2'>
<!-- <AcademyCourseCardButton
v-if="this.$root.$data.checkProgramEnrollment(this.$route.params.code)"
:course="course.name"
:nextContent="nextContent"
:nextContentType="nextContentType"
/> -->
<div class='course-buttons text-center col-xs-4 col-sm-3 col-md-2'>
<a-button
v-if="showCompleted"
type="success"
size="sm"
:type="buttonType"
size="sm btn-block"
:route="firstContentRoute"
>
Completed
</a-button>
<a-button
v-if="showStart"
type="primary"
size="sm"
:route="firstContentRoute"
>
Start
{{ courseMeta.flag }}
</a-button>
</div>
</div>
@ -42,44 +26,36 @@
</template>
<script>
import AButton from './Button';
import AButton from './Button.vue';
import AcademyCourseCardButton from './AcademyCourseCardButton.vue'
export default {
props: ['course'],
props: ['course', 'courseMeta', 'program_name'],
name: "AcademyCourseCard",
data() {
return {
nextContent: '',
nextContentType: ''
}
},
mounted() {
if(this.$root.$data.checkLogin()) {
frappe.call({
method: "erpnext.www.academy.get_starting_content",
args: {
course_name: this.course.name
}
}).then(r => {
this.nextContent = r.message.content,
this.nextContentType = r.message.content_type
});
}
},
components: {
AcademyCourseCardButton,
AButton
},
computed: {
showStart() {
return academy.loggedIn && !this.course.completed;
return academy.loggedIn && !this.courseMeta.flag == "Completed";
},
showCompleted() {
return academy.loggedIn && this.course.completed;
return academy.loggedIn && this.courseMeta.flag == "Completed";
},
firstContentRoute() {
return `${course.name}/${course.content_type}/${data.content}`
return `${this.program_name}/${this.course.name}/${this.courseMeta.content_type}/${this.courseMeta.content}`
},
buttonType() {
if (this.courseMeta.flag == "Start" ){
return "primary"
}
else if (this.courseMeta.flag == "Complete" ) {
return "success"
}
else {
return "info"
}
}
}
};

View File

@ -13,7 +13,7 @@ export default {
},
computed: {
getButtonName: function() {
if(this.$root.$data.checkCourseCompletion(this.course)){
if(academy.store.checkCourseCompletion(this.course)){
return 'Completed'
}
else{
@ -21,7 +21,7 @@ export default {
}
},
getClassName: function() {
if(this.$root.$data.checkCourseCompletion(this.course)){
if(academy.store.checkCourseCompletion(this.course)){
return 'btn-success'
}
}

View File

@ -8,7 +8,7 @@ export default {
data() {
return {
buttonName: '',
isLoggedIn: this.$root.$data.checkLogin(),
isLoggedIn: academy.store.checkLogin(),
nextContent: '',
nextContentType: '',
nextCourse: '',
@ -20,7 +20,7 @@ export default {
frappe.call({
method: "erpnext.www.academy.get_continue_data",
args: {
program_name: this.$route.params.code
program_name: this.$route.params.program_name
}
}).then( r => {
this.nextContent = r.message.content,
@ -30,7 +30,7 @@ export default {
}
if(this.isLoggedIn){
if(this.$root.$data.checkProgramEnrollment(this.$route.params.code)){
if(academy.store.checkProgramEnrollment(this.$route.params.program_name)){
if(this.$route.name == 'home'){
this.buttonName = 'Explore Courses'
}
@ -51,18 +51,18 @@ export default {
if(this.$route.name == 'home'){
return
}
else if(this.$route.name == 'program' && this.$root.$data.checkProgramEnrollment(this.$route.params.code)){
this.$router.push({ name: 'content', params: { code: this.$route.params.code, course: this.nextCourse, type: this.nextContentType, content: this.nextContent}})
else if(this.$route.name == 'program' && academy.store.checkProgramEnrollment(this.$route.params.program_name)){
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.academy.enroll_in_program",
args:{
program_name: this.$route.params.code,
program_name: this.$route.params.program_name,
student_email_id: frappe.session.user
}
})
this.$root.$data.updateEnrolledPrograms()
academy.store.updateEnrolledPrograms()
}
},
}

View File

@ -16,7 +16,7 @@ export default {
frappe.call({
method: "erpnext.www.academy.add_activity",
args: {
enrollment: this.$root.$data.enrolledCourses[this.$route.params.course],
enrollment: academy.store.enrolledCourses[this.$route.params.course],
content_type: this.$route.params.type,
content: this.$route.params.content
}
@ -29,7 +29,7 @@ export default {
frappe.call({
method: "erpnext.www.academy.add_activity",
args: {
enrollment: this.$root.$data.enrolledCourses[this.$route.params.course],
enrollment: academy.store.enrolledCourses[this.$route.params.course],
content_type: this.$route.params.type,
content: this.$route.params.content
}
@ -38,12 +38,12 @@ export default {
frappe.call({
method: "erpnext.www.academy.mark_course_complete",
args: {
enrollment: this.$root.$data.enrolledCourses[this.$route.params.course]
enrollment: academy.store.enrolledCourses[this.$route.params.course]
}
})
// this.$root.$data.addCompletedCourses(this.$route.params.course)
this.$root.$data.updateCompletedCourses()
this.$router.push({ name: 'program', params: { code: this.$route.params.code}})
// academy.store.addCompletedCourses(this.$route.params.course)
academy.store.updateCompletedCourses()
this.$router.push({ name: 'program', params: { program_name: this.$route.params.program_name}})
//
academy.trigger('course-completed', course_name);

View File

@ -72,7 +72,7 @@ export default {
frappe.call({
method: "erpnext.www.academy.evaluate_quiz",
args: {
enrollment: this.$root.$data.enrolledCourses[this.$route.params.course],
enrollment: academy.store.enrolledCourses[this.$route.params.course],
quiz_response: this.quizResponse,
quiz_name: this.content
}

View File

@ -12,7 +12,7 @@ import ContentVideo from "../components/ContentVideo.vue"
import ContentNavigation from "../components/ContentNavigation.vue"
export default {
props:['code', 'course', 'type', 'content'],
props:['program_name', 'course', 'type', 'content'],
name: "AcademyCoursePage",
data() {
return{

View File

@ -1,12 +1,11 @@
<template>
<div>
<AcademyTopSection v-bind:title="program.program_name" v-bind:description="program.description">
<!-- <AcademyTopSectionButton/> -->
<a-button @click="startCourse">Start Course</a-button>
<a-button @click="continueCourse">Continue Course</a-button>
<!-- <a-button @click="startCourse">Start Course</a-button>
<a-button @click="continueCourse">Continue Course</a-button> -->
</AcademyTopSection>
<AcademyList :title="'Courses'" :description="''">
<AcademyCourseCard v-for="course in course_list" :course="course" :key="course.name"/>
<AcademyCourseCard v-for="course in course_data" :course="course.course" :program_name="program_name" :courseMeta="course.meta" :key="course.meta.flag"/>
</AcademyList>
</div>
</template>
@ -15,7 +14,6 @@ import Button from '../components/Button.vue';
import AcademyTopSection from "../components/AcademyTopSection.vue"
import AcademyList from "../components/AcademyList.vue"
import AcademyCourseCard from "../components/AcademyCourseCard.vue"
import AcademyTopSectionButton from "../components/AcademyTopSectionButton.vue";
export default {
@ -25,26 +23,25 @@ export default {
AButton: Button,
AcademyTopSection,
AcademyList,
AcademyCourseCard,
AcademyTopSectionButton
AcademyCourseCard
},
data() {
return {
program: {},
course_list: []
course_data: []
}
},
beforeMount() {
if(this.$root.$data.isLogin) this.$root.$data.updateCompletedCourses()
if(academy.store.isLogin) academy.store.updateCompletedCourses()
},
mounted() {
this.getProgramDetails().then(data => this.program = data);
this.getCourses().then(data => this.course_list = data);
this.getCourses().then(data => this.course_data = data);
academy.on(`course-completed`, (course_name) => {
const course = this.course_list.findIndex(c => c.name === course_name);
this.course_list[course].completed = true;
});
// academy.on(`course-completed`, (course_name) => {
// const course = this.course_data.findIndex(c => c.name === course_name);
// this.course_data[course].completed = true;
// });
},
methods: {
startCourse() {

View File

@ -5,7 +5,7 @@ import AcademyCoursePage from "./pages/AcademyCoursePage.vue";
const routes = [
{name: 'home', path: '', component: AcademyHome},
{name: 'program', path: '/Program/:program_name', component: AcademyProgramPage, props: true},
{name: 'content', path: '/Program/:code/:course/:type/:content', component: AcademyCoursePage, props: true},
{name: 'content', path: '/Program/:program_name/:course/:type/:content', component: AcademyCoursePage, props: true},
];
export default routes;

View File

@ -33,6 +33,14 @@ def get_program(program_name):
is_enrolled = check_program_enrollment(program_name)
return {'program': program, 'is_enrolled': is_enrolled}
@frappe.whitelist(allow_guest=True)
def get_program_details(program_name):
try:
program = frappe.get_doc('Program', program_name)
return program
except:
return None
def get_enrollment(course_name):
student = get_student_id(frappe.session.user)
@ -67,14 +75,6 @@ def create_student(student_name=frappe.session.user):
return student_name
# Functions to get program & course details
@frappe.whitelist(allow_guest=True)
def get_program_details(program_name):
try:
program = frappe.get_doc('Program', program_name)
return program
except:
return None
@frappe.whitelist(allow_guest=True)
def get_courses(program_name):
program = frappe.get_doc('Program', program_name)
@ -84,6 +84,8 @@ def get_courses(program_name):
@frappe.whitelist()
def get_continue_content(course_name):
if(frappe.session.user == "Guest"):
return None
enrollment = get_enrollment(course_name)
course = frappe.get_doc("Course", enrollment.course)
last_activity = enrollment.get_last_activity()
@ -203,15 +205,16 @@ def get_continue_data(program_name):
@frappe.whitelist()
def enroll_all_courses_in_program(program_enrollment, student):
course_list = [course.name for course in get_courses(program_enrollment.program)]
program = frappe.get_doc("Program", program_enrollment.program)
course_list = [course.course for course in program.get_all_children()]
for course_name in course_list:
student.enroll_in_course(course_name=course_name, program_enrollment=program_enrollment.name)
@frappe.whitelist()
def enroll_in_program(program_name, student_email_id):
if(not get_student_id(student_email_id)):
create_student(student_email_id)
student = frappe.get_doc("Student", get_student_id(student_email_id))
def enroll_in_program(program_name):
if(not get_student_id(frappe.session.user)):
create_student(frappe.session.user)
student = frappe.get_doc("Student", get_student_id(frappe.session.user))
program_enrollment = student.enroll_in_program(program_name)
enroll_all_courses_in_program(program_enrollment, student)