From 757b1b1bc31d5f82908bb2df55d9c73019becf19 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Thu, 28 Mar 2019 10:52:03 +0100 Subject: [PATCH 1/2] MOBILE-2915 assign: Display specific message when exceeding word limit --- scripts/langindex.json | 1 + .../assign/submission/onlinetext/lang/en.json | 3 ++- .../submission/onlinetext/providers/handler.ts | 16 +++++++++++++++- src/assets/lang/en.json | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/langindex.json b/scripts/langindex.json index 2bbbdb083..c9384e9b6 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -344,6 +344,7 @@ "addon.mod_assign_submission_comments.pluginname": "assignsubmission_comments", "addon.mod_assign_submission_file.pluginname": "assignsubmission_file", "addon.mod_assign_submission_onlinetext.pluginname": "assignsubmission_onlinetext", + "addon.mod_assign_submission_onlinetext.wordlimitexceeded": "assignsubmission_onlinetext", "addon.mod_book.errorchapter": "book", "addon.mod_book.modulenameplural": "book", "addon.mod_book.toc": "book", diff --git a/src/addon/mod/assign/submission/onlinetext/lang/en.json b/src/addon/mod/assign/submission/onlinetext/lang/en.json index 9b8a3d9f9..e49362133 100644 --- a/src/addon/mod/assign/submission/onlinetext/lang/en.json +++ b/src/addon/mod/assign/submission/onlinetext/lang/en.json @@ -1,3 +1,4 @@ { - "pluginname": "Online text submissions" + "pluginname": "Online text submissions", + "wordlimitexceeded": "The word limit for this assignment is {{$a.limit}} words and you are attempting to submit {{$a.count}} words. Please review your submission and try again." } \ No newline at end of file diff --git a/src/addon/mod/assign/submission/onlinetext/providers/handler.ts b/src/addon/mod/assign/submission/onlinetext/providers/handler.ts index 718a13f51..80745907b 100644 --- a/src/addon/mod/assign/submission/onlinetext/providers/handler.ts +++ b/src/addon/mod/assign/submission/onlinetext/providers/handler.ts @@ -14,6 +14,7 @@ // limitations under the License. import { Injectable, Injector } from '@angular/core'; +import { TranslateService } from '@ngx-translate/core'; import { CoreSitesProvider } from '@providers/sites'; import { CoreWSProvider } from '@providers/ws'; import { CoreTextUtilsProvider } from '@providers/utils/text'; @@ -31,7 +32,7 @@ export class AddonModAssignSubmissionOnlineTextHandler implements AddonModAssign name = 'AddonModAssignSubmissionOnlineTextHandler'; type = 'onlinetext'; - constructor(private sitesProvider: CoreSitesProvider, private wsProvider: CoreWSProvider, + constructor(private translate: TranslateService, private sitesProvider: CoreSitesProvider, private wsProvider: CoreWSProvider, private textUtils: CoreTextUtilsProvider, private assignProvider: AddonModAssignProvider, private assignOfflineProvider: AddonModAssignOfflineProvider, private assignHelper: AddonModAssignHelperProvider) { } @@ -238,6 +239,19 @@ export class AddonModAssignSubmissionOnlineTextHandler implements AddonModAssign let text = this.getTextToSubmit(plugin, inputData); + // Check word limit. + const configs = this.assignHelper.getPluginConfig(assign, 'assignsubmission', plugin.type); + if (parseInt(configs.wordlimitenabled, 10)) { + const words = this.textUtils.countWords(text); + const wordlimit = parseInt(configs.wordlimit, 10); + if (words > wordlimit) { + const params = {$a: {count: words, limit: wordlimit}}; + const message = this.translate.instant('addon.mod_assign_submission_onlinetext.wordlimitexceeded', params); + + return Promise.reject(message); + } + } + // Add some HTML to the text if needed. text = this.textUtils.formatHtmlLines(text); diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 9f14d682a..ec03a1bfe 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -344,6 +344,7 @@ "addon.mod_assign_submission_comments.pluginname": "Submission comments", "addon.mod_assign_submission_file.pluginname": "File submissions", "addon.mod_assign_submission_onlinetext.pluginname": "Online text submissions", + "addon.mod_assign_submission_onlinetext.wordlimitexceeded": "The word limit for this assignment is {{$a.limit}} words and you are attempting to submit {{$a.count}} words. Please review your submission and try again.", "addon.mod_book.errorchapter": "Error reading chapter of book.", "addon.mod_book.modulenameplural": "Books", "addon.mod_book.toc": "Table of contents", From d3ff0824540d5d31aa9d42e922439af2edf56e27 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Thu, 28 Mar 2019 11:31:42 +0100 Subject: [PATCH 2/2] MOBILE-2915 assign: Fix prefetch for teachers --- src/addon/mod/assign/providers/assign.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/addon/mod/assign/providers/assign.ts b/src/addon/mod/assign/providers/assign.ts index 72320b5f7..93e8204f0 100644 --- a/src/addon/mod/assign/providers/assign.ts +++ b/src/addon/mod/assign/providers/assign.ts @@ -379,9 +379,13 @@ export class AddonModAssignProvider { * * @param {any} assign Assign. * @param {any} attempt Attempt. - * @return {any} Submission object. + * @return {any} Submission object or null. */ getSubmissionObjectFromAttempt(assign: any, attempt: any): any { + if (!attempt) { + return null; + } + return assign.teamsubmission ? attempt.teamsubmission : attempt.submission; }