Merge pull request #3363 from dpalou/MOBILE-4121

MOBILE-4121 completion: Invalidate when data sent in scorm/lesson
main
Pau Ferrer Ocaña 2022-09-01 11:38:31 +02:00 committed by GitHub
commit d2c932b365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View File

@ -417,8 +417,16 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo
this.dataSentObserver?.off();
this.dataSentObserver = CoreEvents.on(AddonModLessonProvider.DATA_SENT_EVENT, (data) => {
// Ignore launch sending because it only affects timers.
if (data.lessonId === this.lesson?.id && data.type != 'launch') {
if (data.lessonId !== this.lesson?.id || data.type === 'launch') {
// Ignore launch sending because it only affects timers.
return;
}
if (data.type === 'finish') {
// Lesson finished, check completion now.
this.dataSent = false;
this.checkCompletion();
} else {
this.dataSent = true;
}
}, this.siteId);

View File

@ -16,6 +16,7 @@ import { CoreConstants } from '@/core/constants';
import { Component, OnInit, Optional } from '@angular/core';
import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component';
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
import { CoreCourse } from '@features/course/services/course';
import { IonContent } from '@ionic/angular';
import { CoreNavigator } from '@services/navigator';
import { CoreSync } from '@services/sync';
@ -542,6 +543,11 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom
this.dataSentObserver = CoreEvents.on(AddonModScormProvider.DATA_SENT_EVENT, (data) => {
if (data.scormId === this.scorm!.id) {
this.dataSent = true;
if (this.module.completiondata && CoreCourse.isIncompleteAutomaticCompletion(this.module.completiondata)) {
// Always invalidate section data when data is sent, the SCORM could have a link to a section.
CoreCourse.invalidateSections(this.courseId);
}
}
}, this.siteId);

View File

@ -227,8 +227,7 @@ export class CoreCourseProvider {
* @param completion Completion status of the module.
*/
checkModuleCompletion(courseId: number, completion?: CoreCourseModuleCompletionData): void {
if (completion && completion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_AUTOMATIC &&
completion.state === CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE) {
if (completion && this.isIncompleteAutomaticCompletion(completion)) {
this.invalidateSections(courseId).finally(() => {
CoreEvents.trigger(CoreEvents.COMPLETION_MODULE_VIEWED, {
courseId: courseId,
@ -238,6 +237,17 @@ export class CoreCourseProvider {
}
}
/**
* Given some completion data, return whether it's an automatic completion that hasn't been completed yet.
*
* @param completion Completion data.
* @return Whether it's an automatic completion that hasn't been completed yet.
*/
isIncompleteAutomaticCompletion(completion: CoreCourseModuleCompletionData): boolean {
return completion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_AUTOMATIC &&
completion.state === CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE;
}
/**
* Clear all courses status in a site.
*