MOBILE-3320 course: Fix progress bar reactivity

main
Noel De Martin 2021-06-03 17:00:17 +02:00
parent dd111fce31
commit 51661054ed
1 changed files with 23 additions and 2 deletions

View File

@ -191,8 +191,8 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
this.displaySectionSelector = CoreCourseFormatDelegate.displaySectionSelector(this.course); this.displaySectionSelector = CoreCourseFormatDelegate.displaySectionSelector(this.course);
this.displayBlocks = CoreCourseFormatDelegate.displayBlocks(this.course); this.displayBlocks = CoreCourseFormatDelegate.displayBlocks(this.course);
this.progress = 'progress' in this.course && typeof this.course.progress == 'number' && this.updateProgress();
this.course.progress >= 0 && this.course.completionusertracked !== false ? this.course.progress : undefined;
if ('overviewfiles' in this.course) { if ('overviewfiles' in this.course) {
this.imageThumb = this.course.overviewfiles?.[0]?.fileurl; this.imageThumb = this.course.overviewfiles?.[0]?.fileurl;
} }
@ -641,6 +641,8 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
} else { } else {
this.course.progress = Math.max(0, this.course.progress - moduleProgressPercent); this.course.progress = Math.max(0, this.course.progress - moduleProgressPercent);
} }
this.updateProgress();
} }
/** /**
@ -654,4 +656,23 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
CoreCourseHelper.calculateSectionsStatus(this.sections, this.course.id, false, false); CoreCourseHelper.calculateSectionsStatus(this.sections, this.course.id, false, false);
} }
/**
* Update course progress.
*/
protected updateProgress(): void {
if (
!this.course ||
!('progress' in this.course) ||
typeof this.course.progress !== 'number' ||
this.course.progress < 0 ||
this.course.completionusertracked === false
) {
this.progress = undefined;
return;
}
this.progress = this.course.progress;
}
} }