From a35cc807e1b9992666960742253766d279a6dfea Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 16 Nov 2020 12:44:01 +0100 Subject: [PATCH] MOBILE-2272 essay: Fix issues with attachments in essay --- src/addon/mod/quiz/providers/quiz.ts | 3 +-- src/addon/qtype/essay/component/addon-qtype-essay.html | 2 +- src/addon/qtype/essay/providers/handler.ts | 2 +- src/components/attachments/attachments.ts | 3 ++- src/core/fileuploader/providers/helper.ts | 10 ++++++++++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/addon/mod/quiz/providers/quiz.ts b/src/addon/mod/quiz/providers/quiz.ts index 0c5d3599d..32c91fddd 100644 --- a/src/addon/mod/quiz/providers/quiz.ts +++ b/src/addon/mod/quiz/providers/quiz.ts @@ -1577,8 +1577,7 @@ export class AddonModQuizProvider { const question = result.questions[i]; if (!question.settings) { - // Site doesn't return settings, stop. - break; + continue; } question.settings = this.textUtils.parseJSON(question.settings, null); diff --git a/src/addon/qtype/essay/component/addon-qtype-essay.html b/src/addon/qtype/essay/component/addon-qtype-essay.html index bfdcf2329..6301a5be0 100644 --- a/src/addon/qtype/essay/component/addon-qtype-essay.html +++ b/src/addon/qtype/essay/component/addon-qtype-essay.html @@ -18,7 +18,7 @@ -

{{ 'core.question.errorinlinefilesnotsupportedinsite' | translate }}

+

{{ 'core.question.errorembeddedfilesnotsupportedinsite' | translate }}

diff --git a/src/addon/qtype/essay/providers/handler.ts b/src/addon/qtype/essay/providers/handler.ts index 39d29d9a1..6bbb4a7db 100644 --- a/src/addon/qtype/essay/providers/handler.ts +++ b/src/addon/qtype/essay/providers/handler.ts @@ -130,7 +130,7 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler { } if (!uploadFilesSupported && this.questionHelper.hasDraftFileUrls(element.innerHTML)) { - return 'core.question.errorinlinefilesnotsupportedinsite'; + return 'core.question.errorembeddedfilesnotsupportedinsite'; } } diff --git a/src/components/attachments/attachments.ts b/src/components/attachments/attachments.ts index 5b5e5f92b..b312f8d0f 100644 --- a/src/components/attachments/attachments.ts +++ b/src/components/attachments/attachments.ts @@ -69,7 +69,8 @@ export class CoreAttachmentsComponent implements OnInit { const siteInfo = currentSite && currentSite.getInfo(); if (siteInfo && siteInfo.usermaxuploadfilesize) { - this.maxSizeReadable = this.textUtils.bytesToSize(siteInfo.usermaxuploadfilesize, 2); + this.maxSize = siteInfo.usermaxuploadfilesize; + this.maxSizeReadable = this.textUtils.bytesToSize(this.maxSize, 2); } else { this.maxSizeReadable = this.translate.instant('core.unknown'); } diff --git a/src/core/fileuploader/providers/helper.ts b/src/core/fileuploader/providers/helper.ts index 9a07a1a6a..fe28bcb3e 100644 --- a/src/core/fileuploader/providers/helper.ts +++ b/src/core/fileuploader/providers/helper.ts @@ -27,6 +27,7 @@ import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreUtilsProvider, PromiseDefer } from '@providers/utils/utils'; import { CoreFileUploaderProvider, CoreFileUploaderOptions } from './fileuploader'; import { CoreFileUploaderDelegate } from './delegate'; +import { CoreSites } from '@providers/sites'; /** * Helper service to upload files. @@ -697,6 +698,15 @@ export class CoreFileUploaderHelperProvider { * @return Promise resolved when done. */ async uploadFileObject(file: any, maxSize?: number, upload?: boolean, allowOffline?: boolean, name?: string): Promise { + if (maxSize === 0) { + const currentSite = CoreSites.instance.getCurrentSite(); + const siteInfo = currentSite && currentSite.getInfo(); + + if (siteInfo && siteInfo.usermaxuploadfilesize) { + maxSize = siteInfo.usermaxuploadfilesize; + } + } + if (maxSize != -1 && file.size > maxSize) { return this.errorMaxBytes(maxSize, file.name); }