commit
f7a3b65de6
|
@ -87,9 +87,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.spaceUsage = await CoreSettingsHelper.getSiteSpaceUsage(this.siteId);
|
await this.setDownloadedCourses(downloadedCourses);
|
||||||
|
|
||||||
this.setDownloadedCourses(downloadedCourses);
|
|
||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +124,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
try {
|
try {
|
||||||
await Promise.all(deletedCourseIds.map((courseId) => CoreCourseHelper.deleteCourseFiles(courseId)));
|
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) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile'));
|
CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile'));
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -162,7 +160,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
try {
|
try {
|
||||||
await CoreCourseHelper.deleteCourseFiles(course.id);
|
await CoreCourseHelper.deleteCourseFiles(course.id);
|
||||||
|
|
||||||
this.setDownloadedCourses(CoreArray.withoutItem(this.downloadedCourses, course));
|
await this.setDownloadedCourses(CoreArray.withoutItem(this.downloadedCourses, course));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile'));
|
CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile'));
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -177,7 +175,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
*/
|
*/
|
||||||
private async onCourseUpdated(courseId: number, status: DownloadStatus): Promise<void> {
|
private async onCourseUpdated(courseId: number, status: DownloadStatus): Promise<void> {
|
||||||
if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
|
if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
|
||||||
this.setDownloadedCourses([]);
|
await this.setDownloadedCourses([]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -191,7 +189,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
course.isDownloading = status === DownloadStatus.DOWNLOADING;
|
course.isDownloading = status === DownloadStatus.DOWNLOADING;
|
||||||
course.totalSize = await this.calculateDownloadedCourseSize(course.id);
|
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.
|
* @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.downloadedCourses = courses.sort((a, b) => b.totalSize - a.totalSize);
|
||||||
this.completelyDownloadedCourses = courses.filter((course) => !course.isDownloading);
|
this.completelyDownloadedCourses = courses.filter((course) => !course.isDownloading);
|
||||||
this.totalSize = this.downloadedCourses.reduce((totalSize, course) => totalSize + course.totalSize, 0);
|
this.totalSize = this.downloadedCourses.reduce((totalSize, course) => totalSize + course.totalSize, 0);
|
||||||
|
|
|
@ -99,6 +99,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
|
||||||
protected emptyText = '';
|
protected emptyText = '';
|
||||||
protected domPromises: CoreCancellablePromise<void>[] = [];
|
protected domPromises: CoreCancellablePromise<void>[] = [];
|
||||||
protected domElementPromise?: CoreCancellablePromise<void>;
|
protected domElementPromise?: CoreCancellablePromise<void>;
|
||||||
|
protected externalContentInstances: CoreExternalContentDirective[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
element: ElementRef,
|
element: ElementRef,
|
||||||
|
@ -145,6 +146,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
|
||||||
this.domElementPromise?.cancel();
|
this.domElementPromise?.cancel();
|
||||||
this.domPromises.forEach((promise) => { promise.cancel();});
|
this.domPromises.forEach((promise) => { promise.cancel();});
|
||||||
this.elementControllers.forEach(controller => controller.destroy());
|
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();
|
extContent.ngAfterViewInit();
|
||||||
|
|
||||||
|
this.externalContentInstances.push(extContent);
|
||||||
|
|
||||||
const changeDetectorRef = this.viewContainerRef.injector.get(ChangeDetectorRef);
|
const changeDetectorRef = this.viewContainerRef.injector.get(ChangeDetectorRef);
|
||||||
changeDetectorRef.markForCheck();
|
changeDetectorRef.markForCheck();
|
||||||
|
|
||||||
|
@ -342,6 +346,10 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
|
||||||
* Format contents and render.
|
* Format contents and render.
|
||||||
*/
|
*/
|
||||||
protected async formatAndRenderContents(): Promise<void> {
|
protected async formatAndRenderContents(): Promise<void> {
|
||||||
|
// Destroy previous instances of external-content.
|
||||||
|
this.externalContentInstances.forEach(extContent => extContent.ngOnDestroy());
|
||||||
|
this.externalContentInstances = [];
|
||||||
|
|
||||||
if (!this.text) {
|
if (!this.text) {
|
||||||
this.element.innerHTML = this.emptyText; // Remove current contents.
|
this.element.innerHTML = this.emptyText; // Remove current contents.
|
||||||
|
|
||||||
|
|
|
@ -1912,12 +1912,14 @@ export class CoreCourseHelperProvider {
|
||||||
* @returns Promise to be resolved once the course files are deleted.
|
* @returns Promise to be resolved once the course files are deleted.
|
||||||
*/
|
*/
|
||||||
async deleteCourseFiles(courseId: number): Promise<void> {
|
async deleteCourseFiles(courseId: number): Promise<void> {
|
||||||
|
const siteId = CoreSites.getCurrentSiteId();
|
||||||
const sections = await CoreCourse.getSections(courseId);
|
const sections = await CoreCourse.getSections(courseId);
|
||||||
const modules = sections.map((section) => section.modules).flat();
|
const modules = sections.map((section) => section.modules).flat();
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all([
|
||||||
modules.map((module) => this.removeModuleStoredData(module, courseId)),
|
...modules.map((module) => this.removeModuleStoredData(module, courseId)),
|
||||||
);
|
siteId && CoreFilepool.removeFilesByComponent(siteId, CoreCourseProvider.COMPONENT, courseId),
|
||||||
|
]);
|
||||||
|
|
||||||
await CoreCourse.setCourseStatus(courseId, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED);
|
await CoreCourse.setCourseStatus(courseId, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue