Merge pull request #2856 from dpalou/MOBILE-3320

MOBILE-3320 dashboard: Fix download issues in recent access courses
main
Pau Ferrer Ocaña 2021-06-29 16:24:08 +02:00 committed by GitHub
commit 6700f92a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 26 deletions

View File

@ -221,7 +221,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
const initialIcon = this.prefetchCoursesData.icon; const initialIcon = this.prefetchCoursesData.icon;
try { try {
return CoreCourseHelper.prefetchCourses(this.courses, this.prefetchCoursesData); await CoreCourseHelper.prefetchCourses(this.courses, this.prefetchCoursesData);
} catch (error) { } catch (error) {
if (!this.isDestroyed) { if (!this.isDestroyed) {
CoreDomUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true); CoreDomUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true);

View File

@ -374,42 +374,45 @@ export class CoreCourseHelperProvider {
menuHandlers?: CoreCourseOptionsMenuHandlerToDisplay[], menuHandlers?: CoreCourseOptionsMenuHandlerToDisplay[],
): Promise<void> { ): Promise<void> {
const initialIcon = data.icon; const initialIcon = data.icon;
const initialStatus = data.statusTranslatable; const initialStatus = data.status;
const initialStatusTranslatable = data.statusTranslatable;
const siteId = CoreSites.getCurrentSiteId(); const siteId = CoreSites.getCurrentSiteId();
data.downloadSucceeded = false; data.downloadSucceeded = false;
data.icon = CoreConstants.ICON_DOWNLOADING; data.icon = CoreConstants.ICON_DOWNLOADING;
data.status = CoreConstants.DOWNLOADING;
data.statusTranslatable = 'core.downloading'; data.statusTranslatable = 'core.downloading';
// Get the sections first if needed.
if (!sections) {
sections = await CoreCourse.getSections(course.id, false, true);
}
try { try {
// Get the sections first if needed.
if (!sections) {
sections = await CoreCourse.getSections(course.id, false, true);
}
// Confirm the download. // Confirm the download.
await this.confirmDownloadSizeSection(course.id, undefined, sections, true); await this.confirmDownloadSizeSection(course.id, undefined, sections, true);
// User confirmed, get the course handlers if needed.
if (!courseHandlers) {
courseHandlers = await CoreCourseOptionsDelegate.getHandlersToDisplay(course);
}
if (!menuHandlers) {
menuHandlers = await CoreCourseOptionsDelegate.getMenuHandlersToDisplay(course);
}
// Now we have all the data, download the course.
await this.prefetchCourse(course, sections, courseHandlers, menuHandlers, siteId);
// Download successful.
data.downloadSucceeded = true;
} catch (error) { } catch (error) {
// User cancelled or there was an error calculating the size. // User cancelled or there was an error.
data.icon = initialIcon; data.icon = initialIcon;
data.statusTranslatable = initialStatus; data.status = initialStatus;
data.statusTranslatable = initialStatusTranslatable;
throw error; throw error;
} }
// User confirmed, get the course handlers if needed.
if (!courseHandlers) {
courseHandlers = await CoreCourseOptionsDelegate.getHandlersToDisplay(course);
}
if (!menuHandlers) {
menuHandlers = await CoreCourseOptionsDelegate.getMenuHandlersToDisplay(course);
}
// Now we have all the data, download the course.
await this.prefetchCourse(course, sections, courseHandlers, menuHandlers, siteId);
// Download successful.
data.downloadSucceeded = true;
} }
/** /**

View File

@ -41,7 +41,7 @@
[statusTranslatable]="prefetchCourseData.statusTranslatable" [statusTranslatable]="prefetchCourseData.statusTranslatable"
canTrustDownload="false" canTrustDownload="false"
[loading]="prefetchCourseData.loading" [loading]="prefetchCourseData.loading"
action="prefetchCourse()"></core-download-refresh> (action)="prefetchCourse()"></core-download-refresh>
</div> </div>
<div class="core-button-spinner" *ngIf="courseOptionMenuEnabled" slot="end"> <div class="core-button-spinner" *ngIf="courseOptionMenuEnabled" slot="end">

View File

@ -107,8 +107,7 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
// Determine course prefetch icon. // Determine course prefetch icon.
const status = await CoreCourse.getCourseStatus(this.course.id); const status = await CoreCourse.getCourseStatus(this.course.id);
this.prefetchCourseData = CoreCourseHelper.getCoursePrefetchStatusInfo(status); this.updateCourseStatus(status);
this.courseStatus = status;
if (this.prefetchCourseData.loading) { if (this.prefetchCourseData.loading) {
// Course is being downloaded. Get the download promise. // Course is being downloaded. Get the download promise.