Merge pull request #4059 from dpalou/MOBILE-4470

Mobile 4470
main
Pau Ferrer Ocaña 2024-05-22 16:42:56 +02:00 committed by GitHub
commit f7a3b65de6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 11 deletions

View File

@ -87,9 +87,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
}
}
this.spaceUsage = await CoreSettingsHelper.getSiteSpaceUsage(this.siteId);
this.setDownloadedCourses(downloadedCourses);
await this.setDownloadedCourses(downloadedCourses);
this.loaded = true;
}
@ -126,7 +124,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
try {
await Promise.all(deletedCourseIds.map((courseId) => CoreCourseHelper.deleteCourseFiles(courseId)));
this.setDownloadedCourses(this.downloadedCourses.filter((course) => !deletedCourseIds.includes(course.id)));
await this.setDownloadedCourses(this.downloadedCourses.filter((course) => !deletedCourseIds.includes(course.id)));
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile'));
} finally {
@ -162,7 +160,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
try {
await CoreCourseHelper.deleteCourseFiles(course.id);
this.setDownloadedCourses(CoreArray.withoutItem(this.downloadedCourses, course));
await this.setDownloadedCourses(CoreArray.withoutItem(this.downloadedCourses, course));
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile'));
} finally {
@ -177,7 +175,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
*/
private async onCourseUpdated(courseId: number, status: DownloadStatus): Promise<void> {
if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
this.setDownloadedCourses([]);
await this.setDownloadedCourses([]);
return;
}
@ -191,7 +189,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
course.isDownloading = status === DownloadStatus.DOWNLOADING;
course.totalSize = await this.calculateDownloadedCourseSize(course.id);
this.setDownloadedCourses(this.downloadedCourses);
await this.setDownloadedCourses(this.downloadedCourses);
}
/**
@ -199,7 +197,10 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
*
* @param courses Courses info.
*/
private setDownloadedCourses(courses: DownloadedCourse[]): void {
private async setDownloadedCourses(courses: DownloadedCourse[]): Promise<void> {
// Downloaded courses changed, update site usage too.
this.spaceUsage = await CoreSettingsHelper.getSiteSpaceUsage(this.siteId);
this.downloadedCourses = courses.sort((a, b) => b.totalSize - a.totalSize);
this.completelyDownloadedCourses = courses.filter((course) => !course.isDownloading);
this.totalSize = this.downloadedCourses.reduce((totalSize, course) => totalSize + course.totalSize, 0);

View File

@ -99,6 +99,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
protected emptyText = '';
protected domPromises: CoreCancellablePromise<void>[] = [];
protected domElementPromise?: CoreCancellablePromise<void>;
protected externalContentInstances: CoreExternalContentDirective[] = [];
constructor(
element: ElementRef,
@ -145,6 +146,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
this.domElementPromise?.cancel();
this.domPromises.forEach((promise) => { promise.cancel();});
this.elementControllers.forEach(controller => controller.destroy());
this.externalContentInstances.forEach(extContent => extContent.ngOnDestroy());
}
/**
@ -191,6 +193,8 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
extContent.ngAfterViewInit();
this.externalContentInstances.push(extContent);
const changeDetectorRef = this.viewContainerRef.injector.get(ChangeDetectorRef);
changeDetectorRef.markForCheck();
@ -342,6 +346,10 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
* Format contents and render.
*/
protected async formatAndRenderContents(): Promise<void> {
// Destroy previous instances of external-content.
this.externalContentInstances.forEach(extContent => extContent.ngOnDestroy());
this.externalContentInstances = [];
if (!this.text) {
this.element.innerHTML = this.emptyText; // Remove current contents.

View File

@ -1912,12 +1912,14 @@ export class CoreCourseHelperProvider {
* @returns Promise to be resolved once the course files are deleted.
*/
async deleteCourseFiles(courseId: number): Promise<void> {
const siteId = CoreSites.getCurrentSiteId();
const sections = await CoreCourse.getSections(courseId);
const modules = sections.map((section) => section.modules).flat();
await Promise.all(
modules.map((module) => this.removeModuleStoredData(module, courseId)),
);
await Promise.all([
...modules.map((module) => this.removeModuleStoredData(module, courseId)),
siteId && CoreFilepool.removeFilesByComponent(siteId, CoreCourseProvider.COMPONENT, courseId),
]);
await CoreCourse.setCourseStatus(courseId, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED);
}