fix: progress
This commit is contained in:
@@ -67,7 +67,7 @@
|
||||
{{ lesson.title }}
|
||||
<Check
|
||||
v-if="lesson.is_complete"
|
||||
class="h-4 w-4 text-green-500 stroke-1.5 ml-2"
|
||||
class="h-4 w-4 text-green-700 ml-2"
|
||||
/>
|
||||
</div>
|
||||
</router-link>
|
||||
@@ -139,9 +139,9 @@ const props = defineProps({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
membership: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
getProgress: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -150,27 +150,11 @@ const outline = createResource({
|
||||
cache: ['course_outline', props.courseName],
|
||||
params: {
|
||||
course: props.courseName,
|
||||
progress: props.getProgress,
|
||||
},
|
||||
auto: true,
|
||||
})
|
||||
|
||||
/* const isComplete = (lesson) => {
|
||||
createResource({
|
||||
url: 'lms.lms.utils.get_progress',
|
||||
makeParams() {
|
||||
console.log(lesson)
|
||||
return {
|
||||
course: lesson.course,
|
||||
lesson: lesson.name,
|
||||
}
|
||||
},
|
||||
auto: true,
|
||||
onSuccess(data) {
|
||||
console.log(data)
|
||||
}
|
||||
})
|
||||
} */
|
||||
|
||||
const openChapterDetail = (index) => {
|
||||
return index == route.params.chapterNumber || index == 1
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
</template>
|
||||
</Button>
|
||||
</header>
|
||||
<div v-if="batch.data" class="grid grid-cols-[70%,30%] h-full">
|
||||
<div v-if="batch.data" class="grid grid-cols-[70%,30%] h-screen">
|
||||
<div class="border-r-2">
|
||||
<Tabs v-model="tabIndex" :tabs="tabs" tablistClass="overflow-x-visible">
|
||||
<template #tab="{ tab, selected }" class="overflow-x-hidden">
|
||||
|
||||
@@ -173,7 +173,7 @@
|
||||
<CourseOutline
|
||||
:courseName="courseName"
|
||||
:key="chapterNumber"
|
||||
:membership="lesson.data.membership"
|
||||
:getProgress="lesson.data.membership ? true : false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ from frappe.model.document import Document
|
||||
from frappe.utils.telemetry import capture
|
||||
from lms.lms.utils import get_course_progress
|
||||
from ...md import find_macros
|
||||
import json
|
||||
|
||||
|
||||
class CourseLesson(Document):
|
||||
@@ -95,6 +96,7 @@ def save_progress(lesson, course):
|
||||
return 0
|
||||
|
||||
quiz_completed = get_quiz_progress(lesson)
|
||||
print(quiz_completed)
|
||||
if not quiz_completed:
|
||||
return 0
|
||||
|
||||
@@ -118,19 +120,46 @@ def save_progress(lesson, course):
|
||||
|
||||
|
||||
def get_quiz_progress(lesson):
|
||||
body = frappe.db.get_value("Course Lesson", lesson, "body")
|
||||
macros = find_macros(body)
|
||||
quizzes = [value for name, value in macros if name == "Quiz"]
|
||||
lesson_details = frappe.db.get_value(
|
||||
"Course Lesson", lesson, ["body", "content"], as_dict=1
|
||||
)
|
||||
quizzes = []
|
||||
|
||||
if lesson_details.content:
|
||||
content = json.loads(lesson_details.content)
|
||||
|
||||
for block in content.get("blocks"):
|
||||
if block.get("type") == "quiz":
|
||||
quizzes.append(block.get("data").get("quiz"))
|
||||
|
||||
elif lesson_details.body:
|
||||
macros = find_macros(lesson_details.body)
|
||||
quizzes = [value for name, value in macros if name == "Quiz"]
|
||||
|
||||
for quiz in quizzes:
|
||||
print(quiz)
|
||||
passing_percentage = frappe.db.get_value("LMS Quiz", quiz, "passing_percentage")
|
||||
print(frappe.session.user)
|
||||
print(passing_percentage)
|
||||
print(
|
||||
frappe.db.exists(
|
||||
"LMS Quiz Submission",
|
||||
{
|
||||
"quiz": quiz,
|
||||
"member": frappe.session.user,
|
||||
"percentage": [">=", passing_percentage],
|
||||
},
|
||||
)
|
||||
)
|
||||
if not frappe.db.exists(
|
||||
"LMS Quiz Submission",
|
||||
{
|
||||
"quiz": quiz,
|
||||
"owner": frappe.session.user,
|
||||
"member": frappe.session.user,
|
||||
"percentage": [">=", passing_percentage],
|
||||
},
|
||||
):
|
||||
print("no submission")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@@ -103,15 +103,21 @@ def quiz_summary(quiz, results):
|
||||
"passing_percentage": quiz_details.passing_percentage,
|
||||
}
|
||||
)
|
||||
submission.save(ignore_permissions=True)
|
||||
|
||||
print(
|
||||
percentage, quiz_details.passing_percentage, quiz_details.lesson, quiz_details.course
|
||||
)
|
||||
if (
|
||||
percentage >= quiz_details.passing_percentage
|
||||
and quiz_details.lesson
|
||||
and quiz_details.course
|
||||
):
|
||||
print("if")
|
||||
save_progress(quiz_details.lesson, quiz_details.course)
|
||||
elif not quiz_details.passing_percentage:
|
||||
print("elif")
|
||||
save_progress(quiz_details.lesson, quiz_details.course)
|
||||
|
||||
submission.save(ignore_permissions=True)
|
||||
|
||||
return {
|
||||
"score": score,
|
||||
|
||||
@@ -115,27 +115,27 @@ def get_chapters(course):
|
||||
return chapters
|
||||
|
||||
|
||||
def get_lessons(course, chapter=None, get_details=True):
|
||||
def get_lessons(course, chapter=None, get_details=True, progress=False):
|
||||
"""If chapter is passed, returns lessons of only that chapter.
|
||||
Else returns lessons of all chapters of the course"""
|
||||
lessons = []
|
||||
lesson_count = 0
|
||||
if chapter:
|
||||
if get_details:
|
||||
return get_lesson_details(chapter)
|
||||
return get_lesson_details(chapter, progress=progress)
|
||||
else:
|
||||
return frappe.db.count("Lesson Reference", {"parent": chapter.name})
|
||||
|
||||
for chapter in get_chapters(course):
|
||||
if get_details:
|
||||
lessons += get_lesson_details(chapter)
|
||||
lessons += get_lesson_details(chapter, progress=progress)
|
||||
else:
|
||||
lesson_count += frappe.db.count("Lesson Reference", {"parent": chapter.name})
|
||||
|
||||
return lessons if get_details else lesson_count
|
||||
|
||||
|
||||
def get_lesson_details(chapter, get_progress=False):
|
||||
def get_lesson_details(chapter, progress=False):
|
||||
lessons = []
|
||||
lesson_list = frappe.get_all(
|
||||
"Lesson Reference", {"parent": chapter.name}, ["lesson", "idx"], order_by="idx"
|
||||
@@ -162,6 +162,9 @@ def get_lesson_details(chapter, get_progress=False):
|
||||
lesson_details.number = f"{chapter.idx}.{row.idx}"
|
||||
lesson_details.icon = get_lesson_icon(lesson_details.body)
|
||||
|
||||
if progress:
|
||||
lesson_details.is_complete = get_progress(lesson_details.course, lesson_details.name)
|
||||
|
||||
lessons.append(lesson_details)
|
||||
return lessons
|
||||
|
||||
@@ -1301,7 +1304,7 @@ def get_categorized_courses(courses):
|
||||
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def get_course_outline(course):
|
||||
def get_course_outline(course, progress=False):
|
||||
"""Returns the course outline."""
|
||||
outline = []
|
||||
chapters = frappe.get_all(
|
||||
@@ -1315,7 +1318,7 @@ def get_course_outline(course):
|
||||
as_dict=True,
|
||||
)
|
||||
chapter_details["idx"] = chapter.idx
|
||||
chapter_details.lessons = get_lessons(course, chapter_details)
|
||||
chapter_details.lessons = get_lessons(course, chapter_details, progress=progress)
|
||||
outline.append(chapter_details)
|
||||
return outline
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
<meta name="twitter:title" content="{{ meta.title }}" />
|
||||
<meta name="twitter:image" content="{{ meta.image }}" />
|
||||
<meta name="twitter:description" content="{{ meta.description }}" />
|
||||
<script type="module" crossorigin src="/assets/lms/frontend/assets/index-CushEWOj.js"></script>
|
||||
<script type="module" crossorigin src="/assets/lms/frontend/assets/index-BQuTMdxr.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/assets/lms/frontend/assets/frappe-ui-BI4McHL7.js">
|
||||
<link rel="stylesheet" crossorigin href="/assets/lms/frontend/assets/frappe-ui-DzKBfka9.css">
|
||||
<link rel="stylesheet" crossorigin href="/assets/lms/frontend/assets/index-Dhpy-T0p.css">
|
||||
<link rel="stylesheet" crossorigin href="/assets/lms/frontend/assets/index-BF30Plnj.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
|
||||
Reference in New Issue
Block a user