From 332e7025d77438b008ed1ea7597f5056fc8e95bd Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 25 Jul 2018 15:40:40 +0200 Subject: [PATCH] MOBILE-2531 siteplugins: Fix prefetch loading forever --- .../handlers/module-prefetch-handler.ts | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/core/siteplugins/classes/handlers/module-prefetch-handler.ts b/src/core/siteplugins/classes/handlers/module-prefetch-handler.ts index a9db53e91..434838b75 100644 --- a/src/core/siteplugins/classes/handlers/module-prefetch-handler.ts +++ b/src/core/siteplugins/classes/handlers/module-prefetch-handler.ts @@ -52,18 +52,15 @@ export class CoreSitePluginsModulePrefetchHandler extends CoreCourseActivityPref } /** - * Download or prefetch the content. + * Download the module. * * @param {any} module The module object returned by WS. * @param {number} courseId Course ID. - * @param {boolean} [prefetch] True to prefetch, false to download right away. - * @param {string} [dirPath] Path of the directory where to store all the content files. This is to keep the files - * relative paths and make the package work in an iframe. Undefined to download the files - * in the filepool root folder. - * @return {Promise} Promise resolved when all content is downloaded. Data returned is not reliable. + * @param {string} [dirPath] Path of the directory where to store all the content files. + * @return {Promise} Promise resolved when all content is downloaded. */ - downloadOrPrefetch(module: any, courseId: number, prefetch?: boolean, dirPath?: string): Promise { - return this.prefetchPackage(module, courseId, false, this.downloadPrefetchPlugin.bind(this), undefined, prefetch, dirPath); + download(module: any, courseId: number, dirPath?: string): Promise { + return this.prefetchPackage(module, courseId, false, this.downloadPrefetchPlugin.bind(this), undefined, false, dirPath); } /** @@ -137,6 +134,20 @@ export class CoreSitePluginsModulePrefetchHandler extends CoreCourseActivityPref }); } + /** + * Get the download size of a module. + * + * @param {any} module Module. + * @param {Number} courseId Course ID the module belongs to. + * @param {boolean} [single] True if we're downloading a single module, false if we're downloading a whole section. + * @return {Promise<{size: number, total: boolean}>} Promise resolved with the size and a boolean indicating if it was able + * to calculate the total size. + */ + getDownloadSize(module: any, courseId: number, single?: boolean): Promise<{ size: number, total: boolean }> { + // In most cases, to calculate the size we'll have to do all the WS calls. Just return unknown size. + return Promise.resolve({ size: -1, total: false }); + } + /** * Invalidate the prefetched content. * @@ -196,4 +207,17 @@ export class CoreSitePluginsModulePrefetchHandler extends CoreCourseActivityPref return Promise.resolve(); } + + /** + * Prefetch a module. + * + * @param {any} module Module. + * @param {number} courseId Course ID the module belongs to. + * @param {boolean} [single] True if we're downloading a single module, false if we're downloading a whole section. + * @param {string} [dirPath] Path of the directory where to store all the content files. + * @return {Promise} Promise resolved when done. + */ + prefetch(module: any, courseId?: number, single?: boolean, dirPath?: string): Promise { + return this.prefetchPackage(module, courseId, false, this.downloadPrefetchPlugin.bind(this), undefined, true, dirPath); + } }