diff --git a/scripts/langindex.json b/scripts/langindex.json index ec7f4e8eb..8221281fa 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1453,6 +1453,7 @@ "core.block.tour_navigation_dashboard_content": "tool_usertours", "core.block.tour_navigation_dashboard_title": "tool_usertours", "core.browser": "local_moodlemobileapp", + "core.calculating": "local_moodlemobileapp", "core.cancel": "moodle", "core.cannotconnect": "local_moodlemobileapp", "core.cannotconnecttrouble": "local_moodlemobileapp", @@ -1673,6 +1674,7 @@ "core.editor.underline": "atto_underline/pluginname", "core.editor.unorderedlist": "atto_unorderedlist/pluginname", "core.emptysplit": "local_moodlemobileapp", + "core.endonesteptour": "tool_usertours", "core.error": "moodle", "core.errorchangecompletion": "local_moodlemobileapp", "core.errordeletefile": "local_moodlemobileapp", @@ -2342,7 +2344,6 @@ "core.usernotfullysetup": "error", "core.users": "moodle", "core.usersuspended": "tool_reportbuilder", - "core.endonesteptour": "tool_usertours", "core.view": "moodle", "core.viewcode": "local_moodlemobileapp", "core.vieweditor": "local_moodlemobileapp", diff --git a/src/addons/storagemanager/pages/course-storage/course-storage.html b/src/addons/storagemanager/pages/course-storage/course-storage.html index b6353dd6c..b36d1e85d 100644 --- a/src/addons/storagemanager/pages/course-storage/course-storage.html +++ b/src/addons/storagemanager/pages/course-storage/course-storage.html @@ -24,15 +24,18 @@

{{ 'addon.storagemanager.totaldownloads' | translate }}

- {{ totalSize | coreBytesToSize }} + + {{ totalSize | coreBytesToSize }} + {{ 'core.calculating' | translate }} - + {{ prefetchCourseData.statusTranslatable | translate }} - @@ -52,18 +55,21 @@

+ *ngIf="section.sizeLoaded && section.totalSize > 0"> {{ section.totalSize | coreBytesToSize }} + + {{ 'core.calculating' | translate }} +

-
+
- + @@ -87,7 +94,8 @@ - + @@ -98,11 +106,14 @@ + *ngIf="module.sizeLoaded && module.totalSize > 0"> {{ module.totalSize | coreBytesToSize }} + + {{ 'core.calculating' | translate }} +
@@ -111,8 +122,8 @@ [canTrustDownload]="true" [loading]="module.spinner || module.handlerData.spinner" (action)="prefetchModule(module, section)"> - + diff --git a/src/addons/storagemanager/pages/course-storage/course-storage.ts b/src/addons/storagemanager/pages/course-storage/course-storage.ts index aa14b5269..5c3f371cb 100644 --- a/src/addons/storagemanager/pages/course-storage/course-storage.ts +++ b/src/addons/storagemanager/pages/course-storage/course-storage.ts @@ -48,6 +48,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { loaded = false; sections: AddonStorageManagerCourseSection[] = []; totalSize = 0; + sizeLoaded = false; downloadEnabled = false; downloadCourseEnabled = false; @@ -107,13 +108,13 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { this.sections = (await CoreCourseHelper.addHandlerDataForModules(sections, this.courseId)).sections .map((section) => ({ ...section, totalSize: 0 })); + this.loaded = true; + await Promise.all([ this.loadSizes(), this.initCoursePrefetch(), this.initModulePrefetch(), ]); - - this.loaded = true; } /** @@ -241,12 +242,15 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { */ protected async loadSizes(): Promise { this.totalSize = 0; + this.sizeLoaded = false; - const promises: Promise[] = []; - this.sections.forEach((section) => { + await Promise.all(this.sections.map(async (section) => { section.totalSize = 0; - section.modules.forEach((module) => { + section.sizeLoaded = false; + + await Promise.all(section.modules.map(async (module) => { module.totalSize = 0; + module.sizeLoaded = false; // Note: This function only gets the size for modules which are downloadable. // For other modules it always returns 0, even if they have downloaded some files. @@ -255,21 +259,22 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { // But these aren't necessarily consistent, for example mod_frog vs mmaModFrog. // There is nothing enforcing correct values. // Most modules which have large files are downloadable, so I think this is sufficient. - const promise = CoreCourseModulePrefetchDelegate.getModuleStoredSize(module, this.courseId).then((size) => { - // There are some cases where the return from this is not a valid number. - if (!isNaN(size)) { - module.totalSize = Number(size); - section.totalSize += size; - this.totalSize += size; - } + const size = await CoreCourseModulePrefetchDelegate.getModuleStoredSize(module, this.courseId); - return; - }); - promises.push(promise); - }); - }); + // There are some cases where the return from this is not a valid number. + if (!isNaN(size)) { + module.totalSize = Number(size); + section.totalSize += size; + this.totalSize += size; + } - await Promise.all(promises); + module.sizeLoaded = true; + })); + + section.sizeLoaded = true; + })); + + this.sizeLoaded = true; // Mark course as not downloaded if course size is 0. if (this.totalSize == 0) { @@ -608,11 +613,13 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { type AddonStorageManagerCourseSection = Omit & { totalSize: number; + sizeLoaded?: boolean; modules: AddonStorageManagerModule[]; }; type AddonStorageManagerModule = CoreCourseModuleData & { totalSize?: number; + sizeLoaded?: boolean; prefetchHandler?: CoreCourseModulePrefetchHandler; spinner?: boolean; downloadStatus?: string; diff --git a/src/core/lang.json b/src/core/lang.json index 8dd623b4e..a66c1a6a3 100644 --- a/src/core/lang.json +++ b/src/core/lang.json @@ -13,6 +13,7 @@ "areyousure": "Are you sure?", "back": "Back", "browser": "Browser", + "calculating": "Calculating", "cancel": "Cancel", "cannotconnect": "Cannot connect", "cannotconnecttrouble": "We're having trouble connecting to your site.",