From d03845caa7f29e80d59779bd40d3b711d2fa9ed5 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Fri, 2 Aug 2019 12:13:00 +0100 Subject: [PATCH] MOBILE-3054 Courses: Trigger update of "All sections" download icon --- .../components/format/core-course-format.html | 3 ++- src/core/course/components/format/format.ts | 13 +++++++++++-- src/core/course/components/module/module.ts | 9 ++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/core/course/components/format/core-course-format.html b/src/core/course/components/format/core-course-format.html index 02be4858e..028dc2785 100644 --- a/src/core/course/components/format/core-course-format.html +++ b/src/core/course/components/format/core-course-format.html @@ -86,7 +86,8 @@ - + diff --git a/src/core/course/components/format/format.ts b/src/core/course/components/format/format.ts index cf2744238..b515cf7ac 100644 --- a/src/core/course/components/format/format.ts +++ b/src/core/course/components/format/format.ts @@ -488,9 +488,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { if (this.downloadEnabled) { // The download status of a section might have been changed from within a module page. if (this.selectedSection && this.selectedSection.id !== CoreCourseProvider.ALL_SECTIONS_ID) { - this.courseHelper.calculateSectionStatus(this.selectedSection, this.course.id); + this.courseHelper.calculateSectionStatus(this.selectedSection, this.course.id, false, false); } else { - this.courseHelper.calculateSectionsStatus(this.sections, this.course.id); + this.courseHelper.calculateSectionsStatus(this.sections, this.course.id, false, false); } } } @@ -538,4 +538,13 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { // Emit a new event for other components. this.completionChanged.emit(completionData); } + + /** + * Recalculate the download status of each section, in response to a module being downloaded. + * + * @param {any} eventData + */ + onModuleStatusChange(eventData: any): void { + this.courseHelper.calculateSectionsStatus(this.sections, this.course.id, false, false); + } } diff --git a/src/core/course/components/module/module.ts b/src/core/course/components/module/module.ts index 2cde98503..3bdb1a898 100644 --- a/src/core/course/components/module/module.ts +++ b/src/core/course/components/module/module.ts @@ -50,6 +50,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { } } @Output() completionChanged?: EventEmitter; // Will emit an event when the module completion changes. + @Output() statusChanged?: EventEmitter; // Will emit an event when the download status changes. downloadStatus: string; canCheckUpdates: boolean; @@ -66,6 +67,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { protected eventsProvider: CoreEventsProvider, protected sitesProvider: CoreSitesProvider, protected courseProvider: CoreCourseProvider) { this.completionChanged = new EventEmitter(); + this.statusChanged = new EventEmitter(); } /** @@ -149,7 +151,12 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { this.prefetchHandler.getDownloadSize(this.module, this.courseId, true).then((size) => { return this.courseHelper.prefetchModule(this.prefetchHandler, this.module, size, this.courseId, refresh); }).then(() => { - this.courseHelper.calculateSectionStatus(this.section, this.courseId, false, false); + const eventData = { + sectionId: this.section.id, + moduleId: this.module.id, + courseId: this.courseId + }; + this.statusChanged.emit(eventData); }).catch((error) => { // Error, hide spinner. this.spinner = false;