From 48faf669768791445f83271d6065c7d5cf993a99 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 5 Jul 2018 12:30:08 +0200 Subject: [PATCH] MOBILE-2466 course: Fix calculate and download sections --- src/core/course/providers/helper.ts | 9 ++++++--- src/core/course/providers/module-prefetch-delegate.ts | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/course/providers/helper.ts b/src/core/course/providers/helper.ts index af4aeea19..d5a27649b 100644 --- a/src/core/course/providers/helper.ts +++ b/src/core/course/providers/helper.ts @@ -181,7 +181,8 @@ export class CoreCourseHelperProvider { // Set this section data. section.showDownload = result.status === CoreConstants.NOT_DOWNLOADED; - section.showRefresh = result.status === CoreConstants.OUTDATED; + section.showRefresh = result.status === CoreConstants.OUTDATED || + (!this.prefetchDelegate.canCheckUpdates() && result.status === CoreConstants.DOWNLOADED); if (result.status !== CoreConstants.DOWNLOADING || !this.prefetchDelegate.isBeingDownloaded(section.id)) { section.isDownloading = false; @@ -232,7 +233,8 @@ export class CoreCourseHelperProvider { if (allSectionsSection) { // Set "All sections" data. allSectionsSection.showDownload = allSectionsStatus === CoreConstants.NOT_DOWNLOADED; - allSectionsSection.showRefresh = allSectionsStatus === CoreConstants.OUTDATED; + allSectionsSection.showRefresh = allSectionsStatus === CoreConstants.OUTDATED || + (!this.prefetchDelegate.canCheckUpdates() && allSectionsStatus === CoreConstants.DOWNLOADED); allSectionsSection.isDownloading = allSectionsStatus === CoreConstants.DOWNLOADING; } }).finally(() => { @@ -1090,7 +1092,8 @@ export class CoreCourseHelperProvider { return this.utils.allPromises(promises).then(() => { // Set "All sections" data. section.showDownload = allSectionsStatus === CoreConstants.NOT_DOWNLOADED; - section.showRefresh = allSectionsStatus === CoreConstants.OUTDATED; + section.showRefresh = allSectionsStatus === CoreConstants.OUTDATED || + (!this.prefetchDelegate.canCheckUpdates() && allSectionsStatus === CoreConstants.DOWNLOADED); section.isDownloading = allSectionsStatus === CoreConstants.DOWNLOADING; }).finally(() => { section.isDownloading = false; diff --git a/src/core/course/providers/module-prefetch-delegate.ts b/src/core/course/providers/module-prefetch-delegate.ts index 2693c8fb8..50f0e22de 100644 --- a/src/core/course/providers/module-prefetch-delegate.ts +++ b/src/core/course/providers/module-prefetch-delegate.ts @@ -702,7 +702,7 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate { promise = this.getCourseUpdatesByCourseId(courseId); } else if (updates === false) { // Cannot check updates. - return Promise.resolve(); + return status; } else { promise = Promise.resolve(updates); } @@ -803,7 +803,7 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate { result.total++; } }).catch((error) => { - let cacheStatus = this.statusCache.getValue(packageId, 'status', true); + const cacheStatus = this.statusCache.getValue(packageId, 'status', true); if (typeof cacheStatus == 'undefined') { return Promise.reject(error); }