MOBILE-3954 storage: Add site home to manage storage page
parent
94fbd9e0e2
commit
9caa1f06d5
|
@ -24,7 +24,7 @@ import {
|
||||||
import {
|
import {
|
||||||
CoreCourseModulePrefetchDelegate,
|
CoreCourseModulePrefetchDelegate,
|
||||||
CoreCourseModulePrefetchHandler } from '@features/course/services/module-prefetch-delegate';
|
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 { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
|
@ -43,7 +43,6 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
})
|
})
|
||||||
export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
course?: CoreEnrolledCourseData;
|
|
||||||
courseId!: number;
|
courseId!: number;
|
||||||
title = '';
|
title = '';
|
||||||
loaded = false;
|
loaded = false;
|
||||||
|
@ -70,7 +69,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
constructor() {
|
constructor() {
|
||||||
// Refresh the enabled flags if site is updated.
|
// Refresh the enabled flags if site is updated.
|
||||||
this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
|
this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
|
||||||
this.downloadCourseEnabled = !!this.course && !CoreCourses.isDownloadCourseDisabledInSite();
|
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
||||||
this.downloadEnabled = !CoreSites.getRequiredCurrentSite().isOfflineDisabled();
|
this.downloadEnabled = !CoreSites.getRequiredCurrentSite().isOfflineDisabled();
|
||||||
|
|
||||||
this.initCoursePrefetch();
|
this.initCoursePrefetch();
|
||||||
|
@ -92,15 +91,14 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.course = CoreNavigator.getRouteParam<CoreEnrolledCourseData>('course');
|
this.title = CoreNavigator.getRouteParam<string>('title') || '';
|
||||||
this.title = this.course?.displayname ?? this.course?.fullname ?? '';
|
|
||||||
if (!this.title && this.courseId == CoreSites.getCurrentSiteHomeId()) {
|
if (!this.title && this.courseId == CoreSites.getCurrentSiteHomeId()) {
|
||||||
this.title = Translate.instant('core.sitehome.sitehome');
|
this.title = Translate.instant('core.sitehome.sitehome');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest');
|
this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest');
|
||||||
|
|
||||||
this.downloadCourseEnabled = !!this.course && !CoreCourses.isDownloadCourseDisabledInSite();
|
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
||||||
this.downloadEnabled = !CoreSites.getRequiredCurrentSite().isOfflineDisabled();
|
this.downloadEnabled = !CoreSites.getRequiredCurrentSite().isOfflineDisabled();
|
||||||
|
|
||||||
const sections = await CoreCourse.getSections(this.courseId, false, true);
|
const sections = await CoreCourse.getSections(this.courseId, false, true);
|
||||||
|
@ -551,14 +549,12 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
* Prefetch the whole course.
|
* Prefetch the whole course.
|
||||||
*/
|
*/
|
||||||
async prefetchCourse(): Promise<void> {
|
async prefetchCourse(): Promise<void> {
|
||||||
if (!this.course) {
|
const course = await CoreCourses.getCourse(this.courseId);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await CoreCourseHelper.confirmAndPrefetchCourse(
|
await CoreCourseHelper.confirmAndPrefetchCourse(
|
||||||
this.prefetchCourseData,
|
this.prefetchCourseData,
|
||||||
this.course,
|
course,
|
||||||
{
|
{
|
||||||
sections: this.sections,
|
sections: this.sections,
|
||||||
isGuest: this.isGuest,
|
isGuest: this.isGuest,
|
||||||
|
|
|
@ -31,10 +31,9 @@
|
||||||
<ion-card *ngIf="downloadedCourses.length">
|
<ion-card *ngIf="downloadedCourses.length">
|
||||||
<ion-card-content class="ion-no-padding">
|
<ion-card-content class="ion-no-padding">
|
||||||
<ion-list>
|
<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">
|
<ion-label class="ion-text-wrap">
|
||||||
<p class="item-heading" *ngIf="course.displayname">{{ course.displayname }}</p>
|
<p class="item-heading">{{ course.title }}</p>
|
||||||
<p class="item-heading" *ngIf="!course.displayname">{{ course.fullname }}</p>
|
|
||||||
<p class="item-heading item-heading-secondary" *ngIf="course.isDownloading">
|
<p class="item-heading item-heading-secondary" *ngIf="course.isDownloading">
|
||||||
{{ 'core.downloading' | translate }}
|
{{ 'core.downloading' | translate }}
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -18,6 +18,9 @@ import { CoreCourse, CoreCourseProvider } from '@features/course/services/course
|
||||||
import { CoreCourseHelper } from '@features/course/services/course-helper';
|
import { CoreCourseHelper } from '@features/course/services/course-helper';
|
||||||
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
|
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
|
||||||
import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses';
|
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 { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { Translate } from '@singletons';
|
import { Translate } from '@singletons';
|
||||||
import { CoreArray } from '@singletons/array';
|
import { CoreArray } from '@singletons/array';
|
||||||
|
@ -42,7 +45,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
courseStatusObserver?: CoreEventObserver;
|
courseStatusObserver?: CoreEventObserver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View loaded.
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
this.userCourses = await CoreCourses.getUserCourses();
|
this.userCourses = await CoreCourses.getUserCourses();
|
||||||
|
@ -58,6 +61,22 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
.map((course) => this.getDownloadedCourse(course)),
|
.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.setDownloadedCourses(downloadedCourses);
|
||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
|
@ -173,7 +192,8 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
const status = await CoreCourse.getCourseStatus(course.id);
|
const status = await CoreCourse.getCourseStatus(course.id);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...course,
|
id: course.id,
|
||||||
|
title: course.displayname || course.fullname,
|
||||||
totalSize,
|
totalSize,
|
||||||
isDownloading: status === CoreConstants.DOWNLOADING,
|
isDownloading: status === CoreConstants.DOWNLOADING,
|
||||||
};
|
};
|
||||||
|
@ -198,12 +218,23 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
return moduleSizes.reduce((totalSize, moduleSize) => totalSize + moduleSize, 0);
|
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.
|
* Downloaded course data.
|
||||||
*/
|
*/
|
||||||
interface DownloadedCourse extends CoreEnrolledCourseData {
|
interface DownloadedCourse {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
totalSize: number;
|
totalSize: number;
|
||||||
isDownloading: boolean;
|
isDownloading: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,9 @@ export class AddonStorageManagerCourseMenuHandlerService implements CoreCourseOp
|
||||||
icon: 'fas-archive',
|
icon: 'fas-archive',
|
||||||
title: 'addon.storagemanager.managecoursestorage',
|
title: 'addon.storagemanager.managecoursestorage',
|
||||||
page: 'storage/' + course.id,
|
page: 'storage/' + course.id,
|
||||||
|
pageParams: {
|
||||||
|
title: course.displayname ?? course.fullname,
|
||||||
|
},
|
||||||
class: 'addon-storagemanager-coursemenu-handler',
|
class: 'addon-storagemanager-coursemenu-handler',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue