mirror of
https://github.com/frappe/lms.git
synced 2026-04-20 23:28:00 +03:00
Merge pull request #2247 from raizasafeel/fix/course-progress
fix: course progress updated for scorm and video end event
This commit is contained in:
@@ -75,6 +75,12 @@
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<Check
|
||||
v-if="
|
||||
chapter.is_scorm_package && isScormChapterComplete(chapter)
|
||||
"
|
||||
class="h-4 w-4 text-green-700"
|
||||
/>
|
||||
</DisclosureButton>
|
||||
<DisclosurePanel v-if="!chapter.is_scorm_package">
|
||||
<Draggable
|
||||
@@ -401,6 +407,10 @@ const redirectToChapter = (chapter) => {
|
||||
})
|
||||
}
|
||||
|
||||
const isScormChapterComplete = (chapter) => {
|
||||
return chapter.lessons?.length && chapter.lessons.every((l) => l.is_complete)
|
||||
}
|
||||
|
||||
const isActiveLesson = (lessonNumber) => {
|
||||
return (
|
||||
route.params.chapterNumber == lessonNumber.split('-')[0] &&
|
||||
|
||||
@@ -700,6 +700,31 @@ const updateVideoWatchDuration = () => {
|
||||
}
|
||||
})
|
||||
}
|
||||
attachVideoEndedListeners()
|
||||
}
|
||||
|
||||
const attachVideoEndedListeners = () => {
|
||||
const onVideoEnded = () => {
|
||||
markProgress()
|
||||
trackVideoWatchDuration()
|
||||
}
|
||||
|
||||
document.querySelectorAll('video').forEach((video) => {
|
||||
if (!video._lmsEndedAttached) {
|
||||
video.addEventListener('ended', onVideoEnded)
|
||||
video._lmsEndedAttached = true
|
||||
}
|
||||
})
|
||||
|
||||
plyrSources.value.forEach((plyrSource) => {
|
||||
if (!plyrSource._lmsEndedAttached) {
|
||||
plyrSource.on('ended', onVideoEnded)
|
||||
plyrSource.on('statechange', (event) => {
|
||||
if (event.detail?.code === 0) onVideoEnded()
|
||||
})
|
||||
plyrSource._lmsEndedAttached = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const updatePlyrVideoTime = (video) => {
|
||||
|
||||
@@ -109,9 +109,10 @@ const getDataFromLMS = (key) => {
|
||||
|
||||
let saveTimeout = null
|
||||
const debouncedSaveProgress = (scormDetails) => {
|
||||
if (isSuccessfullyCompleted.value) return
|
||||
clearTimeout(saveTimeout)
|
||||
saveTimeout = setTimeout(() => {
|
||||
saveProgress(scormDetails)
|
||||
if (!isSuccessfullyCompleted.value) saveProgress(scormDetails)
|
||||
}, 300)
|
||||
}
|
||||
|
||||
@@ -124,6 +125,7 @@ const saveDataToLMS = (key, value) => {
|
||||
(key === 'cmi.completion_status' && value === 'incomplete')
|
||||
|
||||
if (isLessonStatus || isCompletionStatus) {
|
||||
if (isSuccessfullyCompleted.value) return
|
||||
isSuccessfullyCompleted.value = true
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ def save_progress(lesson: str, course: str, scorm_details: dict = None):
|
||||
if not membership:
|
||||
return 0
|
||||
|
||||
frappe.db.set_value("LMS Enrollment", membership, "current_lesson", lesson)
|
||||
frappe.db.set_value("LMS Enrollment", membership, "current_lesson", lesson, update_modified=False)
|
||||
progress_already_exists = frappe.db.exists(
|
||||
"LMS Course Progress", {"lesson": lesson, "member": frappe.session.user}
|
||||
)
|
||||
@@ -133,6 +133,7 @@ def save_progress(lesson: str, course: str, scorm_details: dict = None):
|
||||
# Had to get doc, as on_change doesn't trigger when you use set_value. The trigger is necessary for badge to get assigned.
|
||||
enrollment = frappe.get_doc("LMS Enrollment", membership)
|
||||
enrollment.progress = progress
|
||||
enrollment.flags.ignore_version = True
|
||||
enrollment.save()
|
||||
enrollment.run_method("on_change")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user