diff --git a/src/components/icon/icon.ts b/src/components/icon/icon.ts index bfedf4001..82e53d165 100644 --- a/src/components/icon/icon.ts +++ b/src/components/icon/icon.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input, OnInit, OnDestroy, ElementRef } from '@angular/core'; +import { Component, Input, OnChanges, OnDestroy, ElementRef, SimpleChange } from '@angular/core'; import { Config } from 'ionic-angular'; /** @@ -25,7 +25,7 @@ import { Config } from 'ionic-angular'; selector: 'core-icon', templateUrl: 'core-icon.html', }) -export class CoreIconComponent implements OnInit, OnDestroy { +export class CoreIconComponent implements OnChanges, OnDestroy { // Common params. @Input() name: string; @Input('color') color?: string; @@ -49,9 +49,15 @@ export class CoreIconComponent implements OnInit, OnDestroy { } /** - * Component being initialized. + * Detect changes on input properties. */ - ngOnInit(): void { + ngOnChanges(changes: {[name: string]: SimpleChange}): void { + if (!changes.name || !this.name) { + return; + } + + const oldElement = this.newElement ? this.newElement : this.element; + // Use a new created element to avoid ion-icon working. // This is necessary to make the FontAwesome stuff work. // It is also required to stop Ionic overriding the aria-label attribute. @@ -99,7 +105,7 @@ export class CoreIconComponent implements OnInit, OnDestroy { this.newElement.classList.add('icon-slash'); } - this.element.parentElement.replaceChild(this.newElement, this.element); + oldElement.parentElement.replaceChild(this.newElement, oldElement); } /** diff --git a/src/core/course/pages/section/section.ts b/src/core/course/pages/section/section.ts index e8b3d75bb..468cbf8b3 100644 --- a/src/core/course/pages/section/section.ts +++ b/src/core/course/pages/section/section.ts @@ -114,7 +114,7 @@ export class CoreCourseSectionPage implements OnDestroy { if (this.downloadCourseEnabled) { // Listen for changes in course status. this.courseStatusObserver = eventsProvider.on(CoreEventsProvider.COURSE_STATUS_CHANGED, (data) => { - if (data.courseId == this.course.id) { + if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { this.updateCourseStatus(data.status); } }, sitesProvider.getCurrentSiteId()); diff --git a/src/core/course/providers/course.ts b/src/core/course/providers/course.ts index e5207faca..af6daecd4 100644 --- a/src/core/course/providers/course.ts +++ b/src/core/course/providers/course.ts @@ -38,6 +38,7 @@ export class CoreCourseProvider { static STEALTH_MODULES_SECTION_ID = -1; static ACCESS_GUEST = 'courses_access_guest'; static ACCESS_DEFAULT = 'courses_access_default'; + static ALL_COURSES_CLEARED = -1; static COMPLETION_TRACKING_NONE = 0; static COMPLETION_TRACKING_MANUAL = 1; @@ -158,7 +159,7 @@ export class CoreCourseProvider { this.logger.debug('Clear all course status for site ' + site.id); return site.getDb().deleteRecords(this.COURSE_STATUS_TABLE).then(() => { - this.triggerCourseStatusChanged(-1, CoreConstants.NOT_DOWNLOADED, site.id); + this.triggerCourseStatusChanged(CoreCourseProvider.ALL_COURSES_CLEARED, CoreConstants.NOT_DOWNLOADED, site.id); }); }); } diff --git a/src/core/courses/components/course-progress/course-progress.ts b/src/core/courses/components/course-progress/course-progress.ts index f91778759..8c0a9811b 100644 --- a/src/core/courses/components/course-progress/course-progress.ts +++ b/src/core/courses/components/course-progress/course-progress.ts @@ -97,7 +97,7 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy { // Listen for status change in course. this.courseStatusObserver = this.eventsProvider.on(CoreEventsProvider.COURSE_STATUS_CHANGED, (data) => { - if (data.courseId == this.course.id) { + if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { this.updateCourseStatus(data.status); } }, this.sitesProvider.getCurrentSiteId()); diff --git a/src/core/courses/pages/course-preview/course-preview.ts b/src/core/courses/pages/course-preview/course-preview.ts index 53fc896dd..b230fee56 100644 --- a/src/core/courses/pages/course-preview/course-preview.ts +++ b/src/core/courses/pages/course-preview/course-preview.ts @@ -81,7 +81,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { if (this.downloadCourseEnabled) { // Listen for status change in course. this.courseStatusObserver = this.eventsProvider.on(CoreEventsProvider.COURSE_STATUS_CHANGED, (data) => { - if (data.courseId == this.course.id) { + if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { this.updateCourseStatus(data.status); } }, this.sitesProvider.getCurrentSiteId()); diff --git a/src/core/settings/pages/space-usage/space-usage.ts b/src/core/settings/pages/space-usage/space-usage.ts index 457ee82b2..afd45fcd2 100644 --- a/src/core/settings/pages/space-usage/space-usage.ts +++ b/src/core/settings/pages/space-usage/space-usage.ts @@ -20,6 +20,7 @@ import { CoreFilepoolProvider } from '@providers/filepool'; import { CoreSitesProvider } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreCourseProvider } from '@core/course/providers/course'; /** * Page that displays the space usage settings. @@ -39,7 +40,8 @@ export class CoreSettingsSpaceUsagePage { constructor(private filePoolProvider: CoreFilepoolProvider, private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider, - private translate: TranslateService, private domUtils: CoreDomUtilsProvider, appProvider: CoreAppProvider) { + private translate: TranslateService, private domUtils: CoreDomUtilsProvider, appProvider: CoreAppProvider, + private courseProvider: CoreCourseProvider) { this.currentSiteId = this.sitesProvider.getCurrentSiteId(); } @@ -178,6 +180,7 @@ export class CoreSettingsSpaceUsagePage { this.filePoolProvider.clearAllPackagesStatus(site.id); this.filePoolProvider.clearFilepool(site.id); this.updateSiteUsage(siteData, 0); + this.courseProvider.clearAllCoursesStatus(site.id); }).catch((error) => { if (error && error.code === FileError.NOT_FOUND_ERR) { // Not found, set size 0. diff --git a/src/providers/filepool.ts b/src/providers/filepool.ts index 2be089ba3..09d873f94 100644 --- a/src/providers/filepool.ts +++ b/src/providers/filepool.ts @@ -2573,7 +2573,7 @@ export class CoreFilepoolProvider { // Some Android devices restrict the amount of usable storage using quotas. // If this quota would be exceeded by the download, it throws an exception. // We catch this exception here, and report a meaningful error message to the user. - if (errorObject instanceof FileTransferError && errorObject.exception.includes('EDQUOT')) { + if (errorObject instanceof FileTransferError && errorObject.exception && errorObject.exception.includes('EDQUOT')) { errorMessage = 'core.course.insufficientavailablequota'; } diff --git a/src/providers/utils/utils.ts b/src/providers/utils/utils.ts index 1569b505d..d3d09bf47 100644 --- a/src/providers/utils/utils.ts +++ b/src/providers/utils/utils.ts @@ -84,17 +84,19 @@ export class CoreUtilsProvider { return new Promise((resolve, reject): void => { const total = promises.length; let count = 0, + hasFailed = false, error; promises.forEach((promise) => { promise.catch((err) => { + hasFailed = true; error = err; }).finally(() => { count++; if (count === total) { // All promises have finished, reject/resolve. - if (error) { + if (hasFailed) { reject(error); } else { resolve();