MOBILE-3332 course: Display more data in errordownloadingsomefiles
parent
9dcd84c903
commit
3aea77ae01
|
@ -119,6 +119,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
|
||||||
protected fetchContent(refresh?: boolean): Promise<any> {
|
protected fetchContent(refresh?: boolean): Promise<any> {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
let downloadFailed = false;
|
let downloadFailed = false;
|
||||||
|
let downloadFailError;
|
||||||
|
|
||||||
// Try to get the book data.
|
// Try to get the book data.
|
||||||
promises.push(this.bookProvider.getBook(this.courseId, this.module.id).then((book) => {
|
promises.push(this.bookProvider.getBook(this.courseId, this.module.id).then((book) => {
|
||||||
|
@ -129,9 +130,10 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Download content. This function also loads module contents if needed.
|
// Download content. This function also loads module contents if needed.
|
||||||
promises.push(this.prefetchDelegate.download(this.module, this.courseId).catch(() => {
|
promises.push(this.prefetchDelegate.download(this.module, this.courseId).catch((error) => {
|
||||||
// Mark download as failed but go on since the main files could have been downloaded.
|
// Mark download as failed but go on since the main files could have been downloaded.
|
||||||
downloadFailed = true;
|
downloadFailed = true;
|
||||||
|
downloadFailError = error;
|
||||||
|
|
||||||
if (!this.module.contents.length) {
|
if (!this.module.contents.length) {
|
||||||
// Try to load module contents for offline usage.
|
// Try to load module contents for offline usage.
|
||||||
|
@ -163,7 +165,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
|
||||||
return this.loadChapter(this.currentChapter).then(() => {
|
return this.loadChapter(this.currentChapter).then(() => {
|
||||||
if (downloadFailed && this.appProvider.isOnline()) {
|
if (downloadFailed && this.appProvider.isOnline()) {
|
||||||
// We could load the main file but the download failed. Show error message.
|
// We could load the main file but the download failed. Show error message.
|
||||||
this.domUtils.showErrorModal('core.errordownloadingsomefiles', true);
|
this.showErrorDownloadingSomeFiles(downloadFailError);
|
||||||
}
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// Ignore errors, they're handled inside the loadChapter function.
|
// Ignore errors, they're handled inside the loadChapter function.
|
||||||
|
|
|
@ -76,6 +76,7 @@ export class AddonModImscpIndexComponent extends CoreCourseModuleMainResourceCom
|
||||||
*/
|
*/
|
||||||
protected fetchContent(refresh?: boolean): Promise<any> {
|
protected fetchContent(refresh?: boolean): Promise<any> {
|
||||||
let downloadFailed = false;
|
let downloadFailed = false;
|
||||||
|
let downloadFailError;
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
promises.push(this.imscpProvider.getImscp(this.courseId, this.module.id).then((imscp) => {
|
promises.push(this.imscpProvider.getImscp(this.courseId, this.module.id).then((imscp) => {
|
||||||
|
@ -83,9 +84,10 @@ export class AddonModImscpIndexComponent extends CoreCourseModuleMainResourceCom
|
||||||
this.dataRetrieved.emit(imscp);
|
this.dataRetrieved.emit(imscp);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
promises.push(this.imscpPrefetch.download(this.module, this.courseId).catch(() => {
|
promises.push(this.imscpPrefetch.download(this.module, this.courseId).catch((error) => {
|
||||||
// Mark download as failed but go on since the main files could have been downloaded.
|
// Mark download as failed but go on since the main files could have been downloaded.
|
||||||
downloadFailed = true;
|
downloadFailed = true;
|
||||||
|
downloadFailError = error;
|
||||||
|
|
||||||
return this.courseProvider.loadModuleContents(this.module, this.courseId).catch((error) => {
|
return this.courseProvider.loadModuleContents(this.module, this.courseId).catch((error) => {
|
||||||
// Error getting module contents, fail.
|
// Error getting module contents, fail.
|
||||||
|
@ -109,7 +111,7 @@ export class AddonModImscpIndexComponent extends CoreCourseModuleMainResourceCom
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (downloadFailed && this.appProvider.isOnline()) {
|
if (downloadFailed && this.appProvider.isOnline()) {
|
||||||
// We could load the main file but the download failed. Show error message.
|
// We could load the main file but the download failed. Show error message.
|
||||||
this.domUtils.showErrorModal('core.errordownloadingsomefiles', true);
|
this.showErrorDownloadingSomeFiles(downloadFailError);
|
||||||
}
|
}
|
||||||
|
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
|
|
|
@ -78,11 +78,13 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp
|
||||||
*/
|
*/
|
||||||
protected fetchContent(refresh?: boolean): Promise<any> {
|
protected fetchContent(refresh?: boolean): Promise<any> {
|
||||||
let downloadFailed = false;
|
let downloadFailed = false;
|
||||||
|
let downloadFailError;
|
||||||
|
|
||||||
// Download content. This function also loads module contents if needed.
|
// Download content. This function also loads module contents if needed.
|
||||||
return this.pagePrefetch.download(this.module, this.courseId).catch(() => {
|
return this.pagePrefetch.download(this.module, this.courseId).catch((error) => {
|
||||||
// Mark download as failed but go on since the main files could have been downloaded.
|
// Mark download as failed but go on since the main files could have been downloaded.
|
||||||
downloadFailed = true;
|
downloadFailed = true;
|
||||||
|
downloadFailError = error;
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (!this.module.contents.length) {
|
if (!this.module.contents.length) {
|
||||||
// Try to load module contents for offline usage.
|
// Try to load module contents for offline usage.
|
||||||
|
@ -132,7 +134,7 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp
|
||||||
|
|
||||||
if (downloadFailed && this.appProvider.isOnline()) {
|
if (downloadFailed && this.appProvider.isOnline()) {
|
||||||
// We could load the main file but the download failed. Show error message.
|
// We could load the main file but the download failed. Show error message.
|
||||||
this.domUtils.showErrorModal('core.errordownloadingsomefiles', true);
|
this.showErrorDownloadingSomeFiles(downloadFailError);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -110,10 +110,12 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
|
||||||
|
|
||||||
if (this.resourceHelper.isDisplayedInIframe(this.module)) {
|
if (this.resourceHelper.isDisplayedInIframe(this.module)) {
|
||||||
let downloadFailed = false;
|
let downloadFailed = false;
|
||||||
|
let downloadFailError;
|
||||||
|
|
||||||
return this.prefetchHandler.download(this.module, this.courseId).catch(() => {
|
return this.prefetchHandler.download(this.module, this.courseId).catch((error) => {
|
||||||
// Mark download as failed but go on since the main files could have been downloaded.
|
// Mark download as failed but go on since the main files could have been downloaded.
|
||||||
downloadFailed = true;
|
downloadFailed = true;
|
||||||
|
downloadFailError = error;
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return this.resourceHelper.getIframeSrc(this.module).then((src) => {
|
return this.resourceHelper.getIframeSrc(this.module).then((src) => {
|
||||||
this.mode = 'iframe';
|
this.mode = 'iframe';
|
||||||
|
@ -131,7 +133,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
|
||||||
|
|
||||||
if (downloadFailed && this.appProvider.isOnline()) {
|
if (downloadFailed && this.appProvider.isOnline()) {
|
||||||
// We could load the main file but the download failed. Show error message.
|
// We could load the main file but the download failed. Show error message.
|
||||||
this.domUtils.showErrorModal('core.errordownloadingsomefiles', true);
|
this.showErrorDownloadingSomeFiles(downloadFailError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,7 +17,7 @@ import { NavController } from 'ionic-angular';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { CoreLoggerProvider } from '@providers/logger';
|
import { CoreLoggerProvider } from '@providers/logger';
|
||||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
import { CoreTextUtilsProvider, CoreTextErrorObject } from '@providers/utils/text';
|
||||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||||
import { CoreCourseModuleMainComponent, CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
|
import { CoreCourseModuleMainComponent, CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
|
||||||
import { CoreCourseSectionPage } from '@core/course/pages/section/section.ts';
|
import { CoreCourseSectionPage } from '@core/course/pages/section/section.ts';
|
||||||
|
@ -265,6 +265,20 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
|
||||||
this.courseHelper.confirmAndRemoveFiles(this.module, this.courseId);
|
this.courseHelper.confirmAndRemoveFiles(this.module, this.courseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show an error occurred while downloading files.
|
||||||
|
*
|
||||||
|
* @param error The specific error.
|
||||||
|
*/
|
||||||
|
protected showErrorDownloadingSomeFiles(error: string | CoreTextErrorObject): void {
|
||||||
|
const errorMessage = this.textUtils.buildSeveralParagraphsMessage([
|
||||||
|
this.translate.instant('core.errordownloadingsomefiles'),
|
||||||
|
error,
|
||||||
|
]);
|
||||||
|
|
||||||
|
this.domUtils.showErrorModal(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component being destroyed.
|
* Component being destroyed.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -178,8 +178,9 @@ export class CoreCoursesCourseLinkHandler extends CoreContentLinksHandlerBase {
|
||||||
error = this.translate.instant('core.courses.notenroled');
|
error = this.translate.instant('core.courses.notenroled');
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = this.translate.instant('core.twoparagraphs',
|
const body = this.textUtils.buildSeveralParagraphsMessage(
|
||||||
{ p1: error, p2: this.translate.instant('core.confirmopeninbrowser') });
|
[error, this.translate.instant('core.confirmopeninbrowser')]);
|
||||||
|
|
||||||
this.domUtils.showConfirm(body).then(() => {
|
this.domUtils.showConfirm(body).then(() => {
|
||||||
this.sitesProvider.getCurrentSite().openInBrowserWithAutoLogin(url);
|
this.sitesProvider.getCurrentSite().openInBrowserWithAutoLogin(url);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
|
|
|
@ -18,6 +18,16 @@ import { ModalController, Platform } from 'ionic-angular';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { CoreLangProvider } from '../lang';
|
import { CoreLangProvider } from '../lang';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Different type of errors the app can treat.
|
||||||
|
*/
|
||||||
|
export type CoreTextErrorObject = {
|
||||||
|
message?: string;
|
||||||
|
error?: string;
|
||||||
|
content?: string;
|
||||||
|
body?: string;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "Utils" service with helper functions for text.
|
* "Utils" service with helper functions for text.
|
||||||
*/
|
*/
|
||||||
|
@ -122,6 +132,38 @@ export class CoreTextUtilsProvider {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a message with several paragraphs.
|
||||||
|
*
|
||||||
|
* @param paragraphs List of paragraphs.
|
||||||
|
* @return Built message.
|
||||||
|
*/
|
||||||
|
buildSeveralParagraphsMessage(paragraphs: (string | CoreTextErrorObject)[]): string {
|
||||||
|
// Filter invalid messages, and convert them to messages in case they're errors.
|
||||||
|
const messages: string[] = [];
|
||||||
|
|
||||||
|
paragraphs.forEach((paragraph) => {
|
||||||
|
// If it's an error, get its message.
|
||||||
|
const message = this.getErrorMessageFromError(paragraph);
|
||||||
|
|
||||||
|
if (paragraph) {
|
||||||
|
messages.push(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (messages.length < 2) {
|
||||||
|
return messages[0] || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
let builtMessage = messages[0];
|
||||||
|
|
||||||
|
for (let i = 1; i < messages.length; i++) {
|
||||||
|
builtMessage = this.translate.instant('core.twoparagraphs', { p1: builtMessage, p2: messages[i] });
|
||||||
|
}
|
||||||
|
|
||||||
|
return builtMessage;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert size in bytes into human readable format
|
* Convert size in bytes into human readable format
|
||||||
*
|
*
|
||||||
|
@ -449,7 +491,7 @@ export class CoreTextUtilsProvider {
|
||||||
* @param error Error object.
|
* @param error Error object.
|
||||||
* @return Error message, undefined if not found.
|
* @return Error message, undefined if not found.
|
||||||
*/
|
*/
|
||||||
getErrorMessageFromError(error: any): string {
|
getErrorMessageFromError(error: string | CoreTextErrorObject): string {
|
||||||
if (typeof error == 'string') {
|
if (typeof error == 'string') {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue