MOBILE-3954 storage: Add site home to manage storage page
parent
94fbd9e0e2
commit
9caa1f06d5
|
@ -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<CoreEnrolledCourseData>('course');
|
||||
this.title = this.course?.displayname ?? this.course?.fullname ?? '';
|
||||
this.title = CoreNavigator.getRouteParam<string>('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<void> {
|
||||
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,
|
||||
|
|
|
@ -31,10 +31,9 @@
|
|||
<ion-card *ngIf="downloadedCourses.length">
|
||||
<ion-card-content class="ion-no-padding">
|
||||
<ion-list>
|
||||
<ion-item *ngFor="let course of downloadedCourses" class="course" (click)="openCourse(course)" button>
|
||||
<ion-item *ngFor="let course of downloadedCourses" class="course" (click)="openCourse(course.id)" button>
|
||||
<ion-label class="ion-text-wrap">
|
||||
<p class="item-heading" *ngIf="course.displayname">{{ course.displayname }}</p>
|
||||
<p class="item-heading" *ngIf="!course.displayname">{{ course.fullname }}</p>
|
||||
<p class="item-heading">{{ course.title }}</p>
|
||||
<p class="item-heading item-heading-secondary" *ngIf="course.isDownloading">
|
||||
{{ 'core.downloading' | translate }}
|
||||
</p>
|
||||
|
|
|
@ -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<void> {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue