MOBILE-3040 submission: Hide reusing submission button if it was empty

main
Noel De Martin 2019-12-12 17:46:48 +01:00
parent 41f8bb1e23
commit 211de7ce4b
7 changed files with 77 additions and 1 deletions

View File

@ -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.
*

View File

@ -73,7 +73,7 @@
<a ion-button block text-wrap color="primary" *ngIf="!hasOffline && (!userSubmission || !userSubmission.status || userSubmission.status == statusNew)" (click)="goToEdit()">{{ 'addon.mod_assign.addsubmission' | translate }}</a>
<!-- If reopened, show addfromprevious and addnewattempt. -->
<ng-container *ngIf="!hasOffline && userSubmission && userSubmission.status == statusReopened">
<a ion-button block text-wrap color="primary" (click)="copyPrevious()">{{ 'addon.mod_assign.addnewattemptfromprevious' | translate }}</a>
<a *ngIf="!isPreviousAttemptEmpty" ion-button block text-wrap color="primary" (click)="copyPrevious()">{{ 'addon.mod_assign.addnewattemptfromprevious' | translate }}</a>
<a ion-button block text-wrap color="primary" (click)="goToEdit()">{{ 'addon.mod_assign.addnewattempt' | translate }}</a>
</ng-container>
<!-- Else show editsubmission. -->

View File

@ -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.

View File

@ -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.
*

View File

@ -43,6 +43,15 @@ export interface AddonModAssignSubmissionHandler extends CoreDelegateHandler {
canEditOffline?(assign: AddonModAssignAssign, submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin): boolean | Promise<boolean>;
/**
* 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.
*

View File

@ -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.
*

View File

@ -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).