From 211de7ce4b51a0133300166c76fd77e92673aa46 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 12 Dec 2019 17:46:48 +0100 Subject: [PATCH] MOBILE-3040 submission: Hide reusing submission button if it was empty --- .../assign/classes/base-submission-handler.ts | 11 ++++++++++ .../addon-mod-assign-submission.html | 2 +- .../components/submission/submission.ts | 3 +++ src/addon/mod/assign/providers/helper.ts | 15 ++++++++++++++ .../assign/providers/submission-delegate.ts | 20 +++++++++++++++++++ .../submission/file/providers/handler.ts | 13 ++++++++++++ .../onlinetext/providers/handler.ts | 14 +++++++++++++ 7 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/addon/mod/assign/classes/base-submission-handler.ts b/src/addon/mod/assign/classes/base-submission-handler.ts index 95ab92636..6d147d882 100644 --- a/src/addon/mod/assign/classes/base-submission-handler.ts +++ b/src/addon/mod/assign/classes/base-submission-handler.ts @@ -44,6 +44,17 @@ export class AddonModAssignBaseSubmissionHandler implements AddonModAssignSubmis return false; } + /** + * Check if a plugin has no data. + * + * @param assign The assignment. + * @param plugin The plugin object. + * @return Whether the plugin is empty. + */ + isEmpty(assign: AddonModAssignAssign, plugin: AddonModAssignPlugin): boolean { + return true; + } + /** * Should clear temporary data for a cancelled submission. * diff --git a/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html b/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html index 3d236da4b..e4cb512e5 100644 --- a/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html +++ b/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html @@ -73,7 +73,7 @@ {{ 'addon.mod_assign.addsubmission' | translate }} - {{ 'addon.mod_assign.addnewattemptfromprevious' | translate }} + {{ 'addon.mod_assign.addnewattemptfromprevious' | translate }} {{ 'addon.mod_assign.addnewattempt' | translate }} diff --git a/src/addon/mod/assign/components/submission/submission.ts b/src/addon/mod/assign/components/submission/submission.ts index 865c37ae6..9c231cabf 100644 --- a/src/addon/mod/assign/components/submission/submission.ts +++ b/src/addon/mod/assign/components/submission/submission.ts @@ -103,6 +103,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { protected siteId: string; // Current site ID. protected currentUserId: number; // Current user ID. protected previousAttempt: AddonModAssignSubmissionPreviousAttempt; // The previous attempt. + protected isPreviousAttemptEmpty: boolean; // Whether the previous attempt contains an empty submission. protected submissionStatusAvailable: boolean; // Whether we were able to retrieve the submission status. protected originalGrades: any = {}; // Object with the original grade data, to check for changes. protected isDestroyed: boolean; // Whether the component has been destroyed. @@ -373,6 +374,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { let isBlind = !!this.blindId; this.previousAttempt = undefined; + this.isPreviousAttemptEmpty = true; if (!this.submitId) { this.submitId = this.currentUserId; @@ -428,6 +430,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { return a.attemptnumber - b.attemptnumber; }); this.previousAttempt = previousAttempts[previousAttempts.length - 1]; + this.isPreviousAttemptEmpty = this.assignHelper.isSubmissionEmpty(this.assign, this.previousAttempt.submission); } // Treat last attempt. diff --git a/src/addon/mod/assign/providers/helper.ts b/src/addon/mod/assign/providers/helper.ts index afea6aae7..37d6ed427 100644 --- a/src/addon/mod/assign/providers/helper.ts +++ b/src/addon/mod/assign/providers/helper.ts @@ -181,6 +181,21 @@ export class AddonModAssignHelperProvider { return Promise.all(promises); } + /** + * Check if a submission has no content. + * + * @param assign Assignment object. + * @param submission Submission to inspect. + * @return Whether the submission is empty. + */ + isSubmissionEmpty(assign: AddonModAssignAssign, submission?: AddonModAssignSubmission): boolean { + if (!submission) { + return true; + } + + return !!submission.plugins.find((plugin) => this.submissionDelegate.isPluginEmpty(assign, plugin)); + } + /** * List the participants for a single assignment, with some summary info about their submissions. * diff --git a/src/addon/mod/assign/providers/submission-delegate.ts b/src/addon/mod/assign/providers/submission-delegate.ts index 673955cb1..89e29e5cf 100644 --- a/src/addon/mod/assign/providers/submission-delegate.ts +++ b/src/addon/mod/assign/providers/submission-delegate.ts @@ -43,6 +43,15 @@ export interface AddonModAssignSubmissionHandler extends CoreDelegateHandler { canEditOffline?(assign: AddonModAssignAssign, submission: AddonModAssignSubmission, plugin: AddonModAssignPlugin): boolean | Promise; + /** + * Check if a plugin has no data. + * + * @param assign The assignment. + * @param plugin The plugin object. + * @return Whether the plugin is empty. + */ + isEmpty?(assign: AddonModAssignAssign, plugin: AddonModAssignPlugin): boolean; + /** * Should clear temporary data for a cancelled submission. * @@ -368,6 +377,17 @@ export class AddonModAssignSubmissionDelegate extends CoreDelegate { return Promise.resolve(this.executeFunctionOnEnabled(pluginType, 'isEnabledForEdit')); } + /** + * Check if a plugin has no data. + * + * @param assign The assignment. + * @param plugin The plugin object. + * @return Whether the plugin is empty. + */ + isPluginEmpty(assign: AddonModAssignAssign, plugin: AddonModAssignPlugin): boolean { + return this.executeFunctionOnEnabled(plugin.type, 'isEmpty', [assign, plugin]); + } + /** * Prefetch any required data for a submission plugin. * diff --git a/src/addon/mod/assign/submission/file/providers/handler.ts b/src/addon/mod/assign/submission/file/providers/handler.ts index 8ff4f6599..3966b526f 100644 --- a/src/addon/mod/assign/submission/file/providers/handler.ts +++ b/src/addon/mod/assign/submission/file/providers/handler.ts @@ -61,6 +61,19 @@ export class AddonModAssignSubmissionFileHandler implements AddonModAssignSubmis return true; } + /** + * Check if a plugin has no data. + * + * @param assign The assignment. + * @param plugin The plugin object. + * @return Whether the plugin is empty. + */ + isEmpty(assign: AddonModAssignAssign, plugin: AddonModAssignPlugin): boolean { + const files = this.assignProvider.getSubmissionPluginAttachments(plugin); + + return files.length === 0; + } + /** * Should clear temporary data for a cancelled submission. * diff --git a/src/addon/mod/assign/submission/onlinetext/providers/handler.ts b/src/addon/mod/assign/submission/onlinetext/providers/handler.ts index bc800d716..18bee29fa 100644 --- a/src/addon/mod/assign/submission/onlinetext/providers/handler.ts +++ b/src/addon/mod/assign/submission/onlinetext/providers/handler.ts @@ -54,6 +54,20 @@ export class AddonModAssignSubmissionOnlineTextHandler implements AddonModAssign return false; } + /** + * Check if a plugin has no data. + * + * @param assign The assignment. + * @param plugin The plugin object. + * @return Whether the plugin is empty. + */ + isEmpty(assign: AddonModAssignAssign, plugin: AddonModAssignPlugin): boolean { + const text = this.assignProvider.getSubmissionPluginText(plugin, true), + files = this.assignProvider.getSubmissionPluginAttachments(plugin); + + return text.length === 0 && files.length === 0; + } + /** * This function will be called when the user wants to create a new submission based on the previous one. * It should add to pluginData the data to send to server based in the data in plugin (previous attempt).