forked from CIT/Vmeda.Online
		
	MOBILE-3040 submission: Hide reusing submission button if it was empty
This commit is contained in:
		
							parent
							
								
									41f8bb1e23
								
							
						
					
					
						commit
						211de7ce4b
					
				| @ -44,6 +44,17 @@ export class AddonModAssignBaseSubmissionHandler implements AddonModAssignSubmis | |||||||
|         return false; |         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. |      * Should clear temporary data for a cancelled submission. | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -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> |                         <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. --> |                         <!-- If reopened, show addfromprevious and addnewattempt. --> | ||||||
|                         <ng-container *ngIf="!hasOffline && userSubmission && userSubmission.status == statusReopened"> |                         <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> |                             <a ion-button block text-wrap color="primary" (click)="goToEdit()">{{ 'addon.mod_assign.addnewattempt' | translate }}</a> | ||||||
|                         </ng-container> |                         </ng-container> | ||||||
|                         <!-- Else show editsubmission. --> |                         <!-- Else show editsubmission. --> | ||||||
|  | |||||||
| @ -103,6 +103,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | |||||||
|     protected siteId: string; // Current site ID.
 |     protected siteId: string; // Current site ID.
 | ||||||
|     protected currentUserId: number; // Current user ID.
 |     protected currentUserId: number; // Current user ID.
 | ||||||
|     protected previousAttempt: AddonModAssignSubmissionPreviousAttempt; // The previous attempt.
 |     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 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 originalGrades: any = {}; // Object with the original grade data, to check for changes.
 | ||||||
|     protected isDestroyed: boolean; // Whether the component has been destroyed.
 |     protected isDestroyed: boolean; // Whether the component has been destroyed.
 | ||||||
| @ -373,6 +374,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | |||||||
|         let isBlind = !!this.blindId; |         let isBlind = !!this.blindId; | ||||||
| 
 | 
 | ||||||
|         this.previousAttempt = undefined; |         this.previousAttempt = undefined; | ||||||
|  |         this.isPreviousAttemptEmpty = true; | ||||||
| 
 | 
 | ||||||
|         if (!this.submitId) { |         if (!this.submitId) { | ||||||
|             this.submitId = this.currentUserId; |             this.submitId = this.currentUserId; | ||||||
| @ -428,6 +430,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | |||||||
|                     return a.attemptnumber - b.attemptnumber; |                     return a.attemptnumber - b.attemptnumber; | ||||||
|                 }); |                 }); | ||||||
|                 this.previousAttempt = previousAttempts[previousAttempts.length - 1]; |                 this.previousAttempt = previousAttempts[previousAttempts.length - 1]; | ||||||
|  |                 this.isPreviousAttemptEmpty = this.assignHelper.isSubmissionEmpty(this.assign, this.previousAttempt.submission); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             // Treat last attempt.
 |             // Treat last attempt.
 | ||||||
|  | |||||||
| @ -181,6 +181,21 @@ export class AddonModAssignHelperProvider { | |||||||
|         return Promise.all(promises); |         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. |      * List the participants for a single assignment, with some summary info about their submissions. | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -43,6 +43,15 @@ export interface AddonModAssignSubmissionHandler extends CoreDelegateHandler { | |||||||
|     canEditOffline?(assign: AddonModAssignAssign, submission: AddonModAssignSubmission, |     canEditOffline?(assign: AddonModAssignAssign, submission: AddonModAssignSubmission, | ||||||
|             plugin: AddonModAssignPlugin): boolean | Promise<boolean>; |             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. |      * Should clear temporary data for a cancelled submission. | ||||||
|      * |      * | ||||||
| @ -368,6 +377,17 @@ export class AddonModAssignSubmissionDelegate extends CoreDelegate { | |||||||
|         return Promise.resolve(this.executeFunctionOnEnabled(pluginType, 'isEnabledForEdit')); |         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. |      * Prefetch any required data for a submission plugin. | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -61,6 +61,19 @@ export class AddonModAssignSubmissionFileHandler implements AddonModAssignSubmis | |||||||
|         return true; |         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. |      * Should clear temporary data for a cancelled submission. | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -54,6 +54,20 @@ export class AddonModAssignSubmissionOnlineTextHandler implements AddonModAssign | |||||||
|         return false; |         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. |      * 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). |      * It should add to pluginData the data to send to server based in the data in plugin (previous attempt). | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user