From 38b1308f0b44322a12fb6dbdcb51f804110921a5 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 8 Apr 2019 10:45:14 +0200 Subject: [PATCH] MOBILE-2901 file: Support offline files for Nextcloud --- src/addon/mod/resource/providers/helper.ts | 3 ++- src/addon/mod/resource/providers/prefetch-handler.ts | 7 ++++++- src/assets/lang/en.json | 1 + src/classes/site.ts | 3 ++- src/core/course/components/module/module.ts | 7 +++++-- src/core/course/providers/module-prefetch-delegate.ts | 2 ++ 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/addon/mod/resource/providers/helper.ts b/src/addon/mod/resource/providers/helper.ts index b6d0f3aa6..ad461c6a5 100644 --- a/src/addon/mod/resource/providers/helper.ts +++ b/src/addon/mod/resource/providers/helper.ts @@ -113,7 +113,8 @@ export class AddonModResourceHelperProvider { * @return {boolean} Whether the resource should be displayed embeded. */ isDisplayedEmbedded(module: any, display: number): boolean { - if (!module.contents.length || !this.fileProvider.isAvailable() || this.isNextcloudFile(module)) { + if (!module.contents.length || !this.fileProvider.isAvailable() || + (!this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7') && this.isNextcloudFile(module))) { return false; } diff --git a/src/addon/mod/resource/providers/prefetch-handler.ts b/src/addon/mod/resource/providers/prefetch-handler.ts index 7c05f8fbc..bd439d42d 100644 --- a/src/addon/mod/resource/providers/prefetch-handler.ts +++ b/src/addon/mod/resource/providers/prefetch-handler.ts @@ -130,7 +130,12 @@ export class AddonModResourcePrefetchHandler extends CoreCourseResourcePrefetchH * @return {Promise} Promise resolved with true if downloadable, resolved with false otherwise. */ isDownloadable(module: any, courseId: number): Promise { - // Don't allow downloading Nextcloud files for now. + if (this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7')) { + // Nextcloud files are downloadable from 3.7 onwards. + return Promise.resolve(true); + } + + // Don't allow downloading Nextcloud files in older sites. return this.loadContents(module, courseId, false).then(() => { return !this.resourceHelper.isNextcloudFile(module); }); diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 8fd9e1499..8e7ff5128 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1342,6 +1342,7 @@ "core.favourites": "Starred", "core.filename": "Filename", "core.filenameexist": "File name already exists: {{$a}}", + "core.filenotfound": "File not found, sorry.", "core.fileuploader.addfiletext": "Add file", "core.fileuploader.audio": "Audio", "core.fileuploader.camera": "Camera", diff --git a/src/classes/site.ts b/src/classes/site.ts index b9068bd13..9d4bc1e7c 100644 --- a/src/classes/site.ts +++ b/src/classes/site.ts @@ -176,7 +176,8 @@ export class CoreSite { 3.3: 2017051503, 3.4: 2017111300, 3.5: 2018051700, - 3.6: 2018120300 + 3.6: 2018120300, + 3.7: 2019030700 // @todo: Replace it with the right 3.7 date when released }; // Rest of variables. diff --git a/src/core/course/components/module/module.ts b/src/core/course/components/module/module.ts index a22125152..ed1c7bbf4 100644 --- a/src/core/course/components/module/module.ts +++ b/src/core/course/components/module/module.ts @@ -86,12 +86,15 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { if (data.componentId === this.module.id && this.prefetchHandler && data.component === this.prefetchHandler.component) { + // Call determineModuleStatus to get the right status to display. + const status = this.prefetchDelegate.determineModuleStatus(this.module, data.status); + if (this.downloadEnabled) { // Download is enabled, show the status. - this.showStatus(data.status); + this.showStatus(status); } else if (this.module.handlerData.updateStatus) { // Download isn't enabled but the handler defines a updateStatus function, call it anyway. - this.module.handlerData.updateStatus(data.status); + this.module.handlerData.updateStatus(status); } } }, this.sitesProvider.getCurrentSiteId()); diff --git a/src/core/course/providers/module-prefetch-delegate.ts b/src/core/course/providers/module-prefetch-delegate.ts index 24ca8c933..c81e20b43 100644 --- a/src/core/course/providers/module-prefetch-delegate.ts +++ b/src/core/course/providers/module-prefetch-delegate.ts @@ -377,6 +377,8 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate { } } else if (handler.determineStatus) { // The handler implements a determineStatus function. Apply it. + canCheck = canCheck || this.canCheckUpdates(); + return handler.determineStatus(module, status, canCheck); } }