diff --git a/src/addons/storagemanager/pages/course-storage/course-storage.ts b/src/addons/storagemanager/pages/course-storage/course-storage.ts index 3abf047de..962737dc6 100644 --- a/src/addons/storagemanager/pages/course-storage/course-storage.ts +++ b/src/addons/storagemanager/pages/course-storage/course-storage.ts @@ -24,7 +24,7 @@ import { import { CoreCourseModulePrefetchDelegate, CoreCourseModulePrefetchHandler } from '@features/course/services/module-prefetch-delegate'; -import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses'; +import { CoreCourses } from '@features/courses/services/courses'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; @@ -43,7 +43,6 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events'; }) export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { - course?: CoreEnrolledCourseData; courseId!: number; title = ''; loaded = false; @@ -70,7 +69,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { constructor() { // Refresh the enabled flags if site is updated. this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { - this.downloadCourseEnabled = !!this.course && !CoreCourses.isDownloadCourseDisabledInSite(); + this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); this.downloadEnabled = !CoreSites.getRequiredCurrentSite().isOfflineDisabled(); this.initCoursePrefetch(); @@ -92,15 +91,14 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { return; } - this.course = CoreNavigator.getRouteParam('course'); - this.title = this.course?.displayname ?? this.course?.fullname ?? ''; + this.title = CoreNavigator.getRouteParam('title') || ''; if (!this.title && this.courseId == CoreSites.getCurrentSiteHomeId()) { this.title = Translate.instant('core.sitehome.sitehome'); } this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest'); - this.downloadCourseEnabled = !!this.course && !CoreCourses.isDownloadCourseDisabledInSite(); + this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); this.downloadEnabled = !CoreSites.getRequiredCurrentSite().isOfflineDisabled(); const sections = await CoreCourse.getSections(this.courseId, false, true); @@ -551,14 +549,12 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { * Prefetch the whole course. */ async prefetchCourse(): Promise { - if (!this.course) { - return; - } + const course = await CoreCourses.getCourse(this.courseId); try { await CoreCourseHelper.confirmAndPrefetchCourse( this.prefetchCourseData, - this.course, + course, { sections: this.sections, isGuest: this.isGuest, diff --git a/src/addons/storagemanager/pages/courses-storage/courses-storage.html b/src/addons/storagemanager/pages/courses-storage/courses-storage.html index e91ab12bc..0e1371d15 100644 --- a/src/addons/storagemanager/pages/courses-storage/courses-storage.html +++ b/src/addons/storagemanager/pages/courses-storage/courses-storage.html @@ -31,10 +31,9 @@ - + -

{{ course.displayname }}

-

{{ course.fullname }}

+

{{ course.title }}

{{ 'core.downloading' | translate }}

diff --git a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts index ccae867a4..cd46c3c1e 100644 --- a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts +++ b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts @@ -18,6 +18,9 @@ import { CoreCourse, CoreCourseProvider } from '@features/course/services/course import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses'; +import { CoreSiteHome } from '@features/sitehome/services/sitehome'; +import { CoreNavigator } from '@services/navigator'; +import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { Translate } from '@singletons'; import { CoreArray } from '@singletons/array'; @@ -42,7 +45,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy courseStatusObserver?: CoreEventObserver; /** - * View loaded. + * @inheritdoc */ async ngOnInit(): Promise { this.userCourses = await CoreCourses.getUserCourses(); @@ -58,6 +61,22 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy .map((course) => this.getDownloadedCourse(course)), ); + const siteHomeEnabled = await CoreSiteHome.isAvailable(this.siteId); + if (siteHomeEnabled) { + const siteHomeId = CoreSites.getCurrentSiteHomeId(); + const size = await this.calculateDownloadedCourseSize(siteHomeId); + if (size > 0) { + const status = await CoreCourse.getCourseStatus(siteHomeId); + + downloadedCourses.push({ + id: siteHomeId, + title: Translate.instant('core.sitehome.sitehome'), + totalSize: size, + isDownloading: status === CoreConstants.DOWNLOADING, + }); + } + } + this.setDownloadedCourses(downloadedCourses); this.loaded = true; @@ -173,7 +192,8 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy const status = await CoreCourse.getCourseStatus(course.id); return { - ...course, + id: course.id, + title: course.displayname || course.fullname, totalSize, isDownloading: status === CoreConstants.DOWNLOADING, }; @@ -198,12 +218,23 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy return moduleSizes.reduce((totalSize, moduleSize) => totalSize + moduleSize, 0); } + /** + * Open course storage. + * + * @param courseId Course Id. + */ + openCourse(courseId: number, title: string): void { + CoreNavigator.navigateToSitePath('/storage/' + courseId, { params: { title } }); + } + } /** * Downloaded course data. */ -interface DownloadedCourse extends CoreEnrolledCourseData { +interface DownloadedCourse { + id: number; + title: string; totalSize: number; isDownloading: boolean; } diff --git a/src/addons/storagemanager/services/handlers/course-menu.ts b/src/addons/storagemanager/services/handlers/course-menu.ts index 14111d513..a0e5c2653 100644 --- a/src/addons/storagemanager/services/handlers/course-menu.ts +++ b/src/addons/storagemanager/services/handlers/course-menu.ts @@ -51,6 +51,9 @@ export class AddonStorageManagerCourseMenuHandlerService implements CoreCourseOp icon: 'fas-archive', title: 'addon.storagemanager.managecoursestorage', page: 'storage/' + course.id, + pageParams: { + title: course.displayname ?? course.fullname, + }, class: 'addon-storagemanager-coursemenu-handler', }; }