From 54deab86f857265ce779d72fd5ff2857de101d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 10 Feb 2022 17:32:23 +0100 Subject: [PATCH] MOBILE-3814 storage: Fix course prefetch --- .../pages/course-storage/course-storage.ts | 9 ++++++++- .../courses-storage/courses-storage.html | 9 +++++---- .../pages/courses-storage/courses-storage.ts | 20 +++++++++++++++---- .../settings/services/settings-helper.ts | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/addons/storagemanager/pages/course-storage/course-storage.ts b/src/addons/storagemanager/pages/course-storage/course-storage.ts index 962737dc6..fdfef8253 100644 --- a/src/addons/storagemanager/pages/course-storage/course-storage.ts +++ b/src/addons/storagemanager/pages/course-storage/course-storage.ts @@ -549,7 +549,14 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { * Prefetch the whole course. */ async prefetchCourse(): Promise { - const course = await CoreCourses.getCourse(this.courseId); + const courses = await CoreCourses.getUserCourses(true); + let course = courses.find((course) => course.id == this.courseId); + if (!course) { + course = await CoreCourses.getCourse(this.courseId); + } + if (!course) { + return; + } try { await CoreCourseHelper.confirmAndPrefetchCourse( diff --git a/src/addons/storagemanager/pages/courses-storage/courses-storage.html b/src/addons/storagemanager/pages/courses-storage/courses-storage.html index 9bf0f92a9..00d3893a6 100644 --- a/src/addons/storagemanager/pages/courses-storage/courses-storage.html +++ b/src/addons/storagemanager/pages/courses-storage/courses-storage.html @@ -20,7 +20,7 @@ {{ 'core.settings.spaceusagehelp' | translate }}

- @@ -31,8 +31,8 @@

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

{{ totalSize | coreBytesToSize }} - + @@ -55,7 +55,8 @@ {{ course.totalSize | coreBytesToSize }} - + diff --git a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts index 300e9f16c..0697c31aa 100644 --- a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts +++ b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts @@ -103,8 +103,13 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy /** * Delete all courses that have been downloaded. + * + * @param event: Event Object. */ - async deleteCompletelyDownloadedCourses(): Promise { + async deleteCompletelyDownloadedCourses(event: Event): Promise { + event.preventDefault(); + event.stopPropagation(); + try { await CoreDomUtils.showDeleteConfirm('core.course.confirmdeletestoreddata'); } catch (error) { @@ -132,9 +137,13 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy /** * Delete course. * + * @param event: Event Object. * @param course Course to delete. */ - async deleteCourse(course: DownloadedCourse): Promise { + async deleteCourse(event: Event, course: DownloadedCourse): Promise { + event.preventDefault(); + event.stopPropagation(); + try { await CoreDomUtils.showDeleteConfirm('core.course.confirmdeletestoreddata'); } catch (error) { @@ -242,9 +251,12 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy /** * Deletes files of a site and the tables that can be cleared. * - * @param siteData Site object with space usage. + * @param event: Event Object. */ - async deleteSiteStorage(): Promise { + async deleteSiteStorage(event: Event): Promise { + event.preventDefault(); + event.stopPropagation(); + try { const siteName = CoreSites.getRequiredCurrentSite().getSiteName(); diff --git a/src/core/features/settings/services/settings-helper.ts b/src/core/features/settings/services/settings-helper.ts index 5ae1d8ed8..4dfc9eb3e 100644 --- a/src/core/features/settings/services/settings-helper.ts +++ b/src/core/features/settings/services/settings-helper.ts @@ -119,7 +119,7 @@ export class CoreSettingsHelperProvider { const title = Translate.instant('core.settings.deletesitefilestitle'); const message = Translate.instant('core.settings.deletesitefiles', { sitename: siteName }); - await CoreDomUtils.showConfirm(message, title); + await CoreDomUtils.showConfirm(message, title, Translate.instant('core.delete')); const site = await CoreSites.getSite(siteId);