MOBILE-3958 assign: Remove non-null assertions in submission component
This commit is contained in:
		
							parent
							
								
									32947cbc4e
								
							
						
					
					
						commit
						260ef4d47e
					
				| @ -196,7 +196,11 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|      * @param response Response of get submission status. |      * @param response Response of get submission status. | ||||||
|      */ |      */ | ||||||
|     protected calculateTimeRemaining(response: AddonModAssignGetSubmissionStatusWSResponse): void { |     protected calculateTimeRemaining(response: AddonModAssignGetSubmissionStatusWSResponse): void { | ||||||
|         if (this.assign!.duedate <= 0) { |         if (!this.assign) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (this.assign.duedate <= 0) { | ||||||
|             this.timeRemaining = ''; |             this.timeRemaining = ''; | ||||||
|             this.timeRemainingClass = ''; |             this.timeRemainingClass = ''; | ||||||
| 
 | 
 | ||||||
| @ -206,7 +210,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         const time = CoreTimeUtils.timestamp(); |         const time = CoreTimeUtils.timestamp(); | ||||||
|         const dueDate = response.lastattempt?.extensionduedate |         const dueDate = response.lastattempt?.extensionduedate | ||||||
|             ? response.lastattempt.extensionduedate |             ? response.lastattempt.extensionduedate | ||||||
|             : this.assign!.duedate; |             : this.assign.duedate; | ||||||
|         const timeRemaining = dueDate - time; |         const timeRemaining = dueDate - time; | ||||||
| 
 | 
 | ||||||
|         if (timeRemaining > 0) { |         if (timeRemaining > 0) { | ||||||
| @ -276,6 +280,10 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|      * Copy a previous attempt and then go to edit. |      * Copy a previous attempt and then go to edit. | ||||||
|      */ |      */ | ||||||
|     async copyPrevious(): Promise<void> { |     async copyPrevious(): Promise<void> { | ||||||
|  |         if (!this.assign) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         if (!CoreApp.isOnline()) { |         if (!CoreApp.isOnline()) { | ||||||
|             CoreDomUtils.showErrorModal('core.networkerrormsg', true); |             CoreDomUtils.showErrorModal('core.networkerrormsg', true); | ||||||
| 
 | 
 | ||||||
| @ -291,7 +299,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         let modal = await CoreDomUtils.showModalLoading(); |         let modal = await CoreDomUtils.showModalLoading(); | ||||||
| 
 | 
 | ||||||
|         const size = await CoreUtils.ignoreErrors( |         const size = await CoreUtils.ignoreErrors( | ||||||
|             AddonModAssignHelper.getSubmissionSizeForCopy(this.assign!, previousSubmission), |             AddonModAssignHelper.getSubmissionSizeForCopy(this.assign, previousSubmission), | ||||||
|             -1, |             -1, | ||||||
|         ); // Error calculating size, return -1.
 |         ); // Error calculating size, return -1.
 | ||||||
| 
 | 
 | ||||||
| @ -309,15 +317,15 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         modal = await CoreDomUtils.showModalLoading('core.sending', true); |         modal = await CoreDomUtils.showModalLoading('core.sending', true); | ||||||
| 
 | 
 | ||||||
|         try { |         try { | ||||||
|             await AddonModAssignHelper.copyPreviousAttempt(this.assign!, previousSubmission); |             await AddonModAssignHelper.copyPreviousAttempt(this.assign, previousSubmission); | ||||||
|             // Now go to edit.
 |             // Now go to edit.
 | ||||||
|             this.goToEdit(); |             this.goToEdit(); | ||||||
| 
 | 
 | ||||||
|             if (!this.assign!.submissiondrafts) { |             if (!this.assign.submissiondrafts && this.userSubmission) { | ||||||
|                 // No drafts allowed, so it was submitted. Trigger event.
 |                 // No drafts allowed, so it was submitted. Trigger event.
 | ||||||
|                 CoreEvents.trigger(AddonModAssignProvider.SUBMITTED_FOR_GRADING_EVENT, { |                 CoreEvents.trigger(AddonModAssignProvider.SUBMITTED_FOR_GRADING_EVENT, { | ||||||
|                     assignmentId: this.assign!.id, |                     assignmentId: this.assign.id, | ||||||
|                     submissionId: this.userSubmission!.id, |                     submissionId: this.userSubmission.id, | ||||||
|                     userId: this.currentUserId, |                     userId: this.currentUserId, | ||||||
|                 }, this.siteId); |                 }, this.siteId); | ||||||
|             } else { |             } else { | ||||||
| @ -337,8 +345,8 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|      * @return Promise resolved when done. |      * @return Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     protected async discardDrafts(): Promise<void> { |     protected async discardDrafts(): Promise<void> { | ||||||
|         if (this.feedback && this.feedback.plugins) { |         if (this.assign && this.feedback && this.feedback.plugins) { | ||||||
|             await AddonModAssignHelper.discardFeedbackPluginData(this.assign!.id, this.submitId, this.feedback); |             await AddonModAssignHelper.discardFeedbackPluginData(this.assign.id, this.submitId, this.feedback); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -363,7 +371,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|      * @return Promise resolved with boolean: whether there's data to save. |      * @return Promise resolved with boolean: whether there's data to save. | ||||||
|      */ |      */ | ||||||
|     protected async hasDataToSave(isSubmit = false): Promise<boolean> { |     protected async hasDataToSave(isSubmit = false): Promise<boolean> { | ||||||
|         if (!this.canSaveGrades || !this.loaded) { |         if (!this.canSaveGrades || !this.loaded || !this.assign) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -379,7 +387,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Check if outcomes changed.
 |         // Check if outcomes changed.
 | ||||||
|         if (this.gradeInfo && this.gradeInfo.outcomes) { |         if (this.gradeInfo?.outcomes) { | ||||||
|             for (const x in this.gradeInfo.outcomes) { |             for (const x in this.gradeInfo.outcomes) { | ||||||
|                 const outcome = this.gradeInfo.outcomes[x]; |                 const outcome = this.gradeInfo.outcomes[x]; | ||||||
| 
 | 
 | ||||||
| @ -396,7 +404,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
| 
 | 
 | ||||||
|         try { |         try { | ||||||
|             return AddonModAssignHelper.hasFeedbackDataChanged( |             return AddonModAssignHelper.hasFeedbackDataChanged( | ||||||
|                 this.assign!, |                 this.assign, | ||||||
|                 this.userSubmission, |                 this.userSubmission, | ||||||
|                 this.feedback, |                 this.feedback, | ||||||
|                 this.submitId, |                 this.submitId, | ||||||
| @ -435,13 +443,13 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         promises.push(AddonModAssign.invalidateAssignmentData(this.courseId)); |         promises.push(AddonModAssign.invalidateAssignmentData(this.courseId)); | ||||||
|         if (this.assign) { |         if (this.assign) { | ||||||
|             promises.push(AddonModAssign.invalidateSubmissionStatusData( |             promises.push(AddonModAssign.invalidateSubmissionStatusData( | ||||||
|                 this.assign!.id, |                 this.assign.id, | ||||||
|                 this.submitId, |                 this.submitId, | ||||||
|                 undefined, |                 undefined, | ||||||
|                 !!this.blindId, |                 !!this.blindId, | ||||||
|             )); |             )); | ||||||
|             promises.push(AddonModAssign.invalidateAssignmentUserMappingsData(this.assign!.id)); |             promises.push(AddonModAssign.invalidateAssignmentUserMappingsData(this.assign.id)); | ||||||
|             promises.push(AddonModAssign.invalidateListParticipantsData(this.assign!.id)); |             promises.push(AddonModAssign.invalidateListParticipantsData(this.assign.id)); | ||||||
|         } |         } | ||||||
|         promises.push(CoreGradesHelper.invalidateGradeModuleItems(this.courseId, this.submitId)); |         promises.push(CoreGradesHelper.invalidateGradeModuleItems(this.courseId, this.submitId)); | ||||||
|         promises.push(CoreCourse.invalidateModule(this.moduleId)); |         promises.push(CoreCourse.invalidateModule(this.moduleId)); | ||||||
| @ -534,13 +542,13 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             // Treat last attempt.
 |             // Treat last attempt.
 | ||||||
|             promises = this.treatLastAttempt(submissionStatus); |             promises = this.treatLastAttempt(submissionStatus, this.lastAttempt); | ||||||
| 
 | 
 | ||||||
|             // Calculate the time remaining.
 |             // Calculate the time remaining.
 | ||||||
|             this.calculateTimeRemaining(submissionStatus); |             this.calculateTimeRemaining(submissionStatus); | ||||||
| 
 | 
 | ||||||
|             // Load the feedback.
 |             // Load the feedback.
 | ||||||
|             promises.push(this.loadFeedback(submissionStatus.feedback)); |             promises.push(this.loadFeedback(this.assign, submissionStatus.feedback)); | ||||||
| 
 | 
 | ||||||
|             // Check if there's any unsupported plugin for editing.
 |             // Check if there's any unsupported plugin for editing.
 | ||||||
|             if (!this.userSubmission || !this.userSubmission.plugins) { |             if (!this.userSubmission || !this.userSubmission.plugins) { | ||||||
| @ -575,8 +583,12 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|      * @return Promise resolved when done. |      * @return Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     protected async loadSubmissionOfflineData(): Promise<void> { |     protected async loadSubmissionOfflineData(): Promise<void> { | ||||||
|  |         if (!this.assign) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         try { |         try { | ||||||
|             const submission = await AddonModAssignOffline.getSubmission(this.assign!.id, this.submitId); |             const submission = await AddonModAssignOffline.getSubmission(this.assign.id, this.submitId); | ||||||
| 
 | 
 | ||||||
|             this.hasOffline = submission && submission.plugindata && Object.keys(submission.plugindata).length > 0; |             this.hasOffline = submission && submission.plugindata && Object.keys(submission.plugindata).length > 0; | ||||||
| 
 | 
 | ||||||
| @ -591,10 +603,11 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|     /** |     /** | ||||||
|      * Load the data to render the feedback and grade. |      * Load the data to render the feedback and grade. | ||||||
|      * |      * | ||||||
|  |      * @param assign Assign data. | ||||||
|      * @param feedback The feedback data from the submission status. |      * @param feedback The feedback data from the submission status. | ||||||
|      * @return Promise resolved when done. |      * @return Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     protected async loadFeedback(feedback?: AddonModAssignSubmissionFeedback): Promise<void> { |     protected async loadFeedback(assign: AddonModAssignAssign, feedback?: AddonModAssignSubmissionFeedback): Promise<void> { | ||||||
|         this.grade = { |         this.grade = { | ||||||
|             method: '', |             method: '', | ||||||
|             modified: 0, |             modified: 0, | ||||||
| @ -654,22 +667,22 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         // Treat the grade info.
 |         // Treat the grade info.
 | ||||||
|         await this.treatGradeInfo(); |         await this.treatGradeInfo(); | ||||||
| 
 | 
 | ||||||
|         const isManual = this.assign!.attemptreopenmethod == AddonModAssignAttemptReopenMethodValues.MANUAL; |         const isManual = assign.attemptreopenmethod == AddonModAssignAttemptReopenMethodValues.MANUAL; | ||||||
|         const isUnlimited = this.assign!.maxattempts == AddonModAssignProvider.UNLIMITED_ATTEMPTS; |         const isUnlimited = assign.maxattempts == AddonModAssignProvider.UNLIMITED_ATTEMPTS; | ||||||
|         const isLessThanMaxAttempts = !!this.userSubmission && (this.userSubmission.attemptnumber < (this.assign!.maxattempts - 1)); |         const isLessThanMaxAttempts = !!this.userSubmission && (this.userSubmission.attemptnumber < (assign.maxattempts - 1)); | ||||||
| 
 | 
 | ||||||
|         this.allowAddAttempt = isManual && (!this.userSubmission || isUnlimited || isLessThanMaxAttempts); |         this.allowAddAttempt = isManual && (!this.userSubmission || isUnlimited || isLessThanMaxAttempts); | ||||||
| 
 | 
 | ||||||
|         if (this.assign!.teamsubmission) { |         if (assign.teamsubmission) { | ||||||
|             this.grade.applyToAll = true; |             this.grade.applyToAll = true; | ||||||
|             this.originalGrades.applyToAll = true; |             this.originalGrades.applyToAll = true; | ||||||
|         } |         } | ||||||
|         if (this.assign!.markingworkflow && this.grade.gradingStatus) { |         if (assign.markingworkflow && this.grade.gradingStatus) { | ||||||
|             this.workflowStatusTranslationId = |             this.workflowStatusTranslationId = | ||||||
|                 AddonModAssign.getSubmissionGradingStatusTranslationId(this.grade.gradingStatus); |                 AddonModAssign.getSubmissionGradingStatusTranslationId(this.grade.gradingStatus); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (this.lastAttempt?.gradingstatus == 'graded' && !this.assign!.markingworkflow && this.userSubmission && feedback) { |         if (this.lastAttempt?.gradingstatus == 'graded' && !assign.markingworkflow && this.userSubmission && feedback) { | ||||||
|             if (feedback.gradeddate < this.userSubmission.timemodified) { |             if (feedback.gradeddate < this.userSubmission.timemodified) { | ||||||
|                 this.lastAttempt.gradingstatus = AddonModAssignGradingStates.GRADED_FOLLOWUP_SUBMIT; |                 this.lastAttempt.gradingstatus = AddonModAssignGradingStates.GRADED_FOLLOWUP_SUBMIT; | ||||||
| 
 | 
 | ||||||
| @ -685,7 +698,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         if (!this.feedback || !this.feedback.plugins) { |         if (!this.feedback || !this.feedback.plugins) { | ||||||
|             // Feedback plugins not present, we have to use assign configs to detect the plugins used.
 |             // Feedback plugins not present, we have to use assign configs to detect the plugins used.
 | ||||||
|             this.feedback = AddonModAssignHelper.createEmptyFeedback(); |             this.feedback = AddonModAssignHelper.createEmptyFeedback(); | ||||||
|             this.feedback.plugins = AddonModAssignHelper.getPluginsEnabled(this.assign!, 'assignfeedback'); |             this.feedback.plugins = AddonModAssignHelper.getPluginsEnabled(assign, 'assignfeedback'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Check if there's any offline data for this submission.
 |         // Check if there's any offline data for this submission.
 | ||||||
| @ -700,7 +713,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         // Submission grades aren't identified by attempt number so it can retrieve the feedback for a previous attempt.
 |         // Submission grades aren't identified by attempt number so it can retrieve the feedback for a previous attempt.
 | ||||||
|         // The app will not treat that as an special case.
 |         // The app will not treat that as an special case.
 | ||||||
|         const submissionGrade = await CoreUtils.ignoreErrors( |         const submissionGrade = await CoreUtils.ignoreErrors( | ||||||
|             AddonModAssignOffline.getSubmissionGrade(this.assign!.id, this.submitId), |             AddonModAssignOffline.getSubmissionGrade(assign.id, this.submitId), | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         this.hasOfflineGrade = false; |         this.hasOfflineGrade = false; | ||||||
| @ -725,10 +738,10 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
| 
 | 
 | ||||||
|             if (submissionGrade.outcomes && Object.keys(submissionGrade.outcomes).length && this.gradeInfo?.outcomes) { |             if (submissionGrade.outcomes && Object.keys(submissionGrade.outcomes).length && this.gradeInfo?.outcomes) { | ||||||
|                 this.gradeInfo.outcomes.forEach((outcome) => { |                 this.gradeInfo.outcomes.forEach((outcome) => { | ||||||
|                     if (submissionGrade.outcomes[outcome.itemNumber!] !== undefined) { |                     if (outcome.itemNumber !== undefined && submissionGrade.outcomes[outcome.itemNumber] !== undefined) { | ||||||
|                         // If outcome has been modified from gradebook, do not use offline.
 |                         // If outcome has been modified from gradebook, do not use offline.
 | ||||||
|                         if (outcome.modified! < submissionGrade.timemodified) { |                         if ((outcome.modified || 0) < submissionGrade.timemodified) { | ||||||
|                             outcome.selectedId = submissionGrade.outcomes[outcome.itemNumber!]; |                             outcome.selectedId = submissionGrade.outcomes[outcome.itemNumber]; | ||||||
|                             this.originalGrades.outcomes[outcome.id] = outcome.selectedId; |                             this.originalGrades.outcomes[outcome.id] = outcome.selectedId; | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
| @ -752,11 +765,15 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|      * @param status Submission status. |      * @param status Submission status. | ||||||
|      */ |      */ | ||||||
|     protected setStatusNameAndClass(status: AddonModAssignGetSubmissionStatusWSResponse): void { |     protected setStatusNameAndClass(status: AddonModAssignGetSubmissionStatusWSResponse): void { | ||||||
|  |         if (!this.assign) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         if (this.hasOffline || this.submittedOffline) { |         if (this.hasOffline || this.submittedOffline) { | ||||||
|             // Offline data.
 |             // Offline data.
 | ||||||
|             this.statusTranslated = Translate.instant('core.notsent'); |             this.statusTranslated = Translate.instant('core.notsent'); | ||||||
|             this.statusColor = 'warning'; |             this.statusColor = 'warning'; | ||||||
|         } else if (!this.assign!.teamsubmission) { |         } else if (!this.assign.teamsubmission) { | ||||||
| 
 | 
 | ||||||
|             // Single submission.
 |             // Single submission.
 | ||||||
|             if (this.userSubmission && this.userSubmission.status != this.statusNew) { |             if (this.userSubmission && this.userSubmission.status != this.statusNew) { | ||||||
| @ -775,7 +792,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         } else { |         } else { | ||||||
| 
 | 
 | ||||||
|             // Team submission.
 |             // Team submission.
 | ||||||
|             if (!status.lastattempt?.submissiongroup && this.assign!.preventsubmissionnotingroup) { |             if (!status.lastattempt?.submissiongroup && this.assign.preventsubmissionnotingroup) { | ||||||
|                 this.statusTranslated = Translate.instant('addon.mod_assign.nosubmission'); |                 this.statusTranslated = Translate.instant('addon.mod_assign.nosubmission'); | ||||||
|                 this.statusColor = AddonModAssign.getSubmissionStatusColor(AddonModAssignSubmissionStatusValues.NO_SUBMISSION); |                 this.statusColor = AddonModAssign.getSubmissionStatusColor(AddonModAssignSubmissionStatusValues.NO_SUBMISSION); | ||||||
|             } else if (this.userSubmission && this.userSubmission.status != this.statusNew) { |             } else if (this.userSubmission && this.userSubmission.status != this.statusNew) { | ||||||
| @ -816,7 +833,11 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|      * @param acceptStatement Whether the statement has been accepted. |      * @param acceptStatement Whether the statement has been accepted. | ||||||
|      */ |      */ | ||||||
|     async submitForGrading(acceptStatement: boolean): Promise<void> { |     async submitForGrading(acceptStatement: boolean): Promise<void> { | ||||||
|         if (this.assign!.requiresubmissionstatement && !acceptStatement) { |         if (!this.assign || !this.userSubmission) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (this.assign.requiresubmissionstatement && !acceptStatement) { | ||||||
|             CoreDomUtils.showErrorModal('addon.mod_assign.acceptsubmissionstatement', true); |             CoreDomUtils.showErrorModal('addon.mod_assign.acceptsubmissionstatement', true); | ||||||
| 
 | 
 | ||||||
|             return; |             return; | ||||||
| @ -830,17 +851,17 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
| 
 | 
 | ||||||
|             try { |             try { | ||||||
|                 await AddonModAssign.submitForGrading( |                 await AddonModAssign.submitForGrading( | ||||||
|                     this.assign!.id, |                     this.assign.id, | ||||||
|                     this.courseId, |                     this.courseId, | ||||||
|                     acceptStatement, |                     acceptStatement, | ||||||
|                     this.userSubmission!.timemodified, |                     this.userSubmission.timemodified, | ||||||
|                     this.hasOffline, |                     this.hasOffline, | ||||||
|                 ); |                 ); | ||||||
| 
 | 
 | ||||||
|                 // Submitted, trigger event.
 |                 // Submitted, trigger event.
 | ||||||
|                 CoreEvents.trigger(AddonModAssignProvider.SUBMITTED_FOR_GRADING_EVENT, { |                 CoreEvents.trigger(AddonModAssignProvider.SUBMITTED_FOR_GRADING_EVENT, { | ||||||
|                     assignmentId: this.assign!.id, |                     assignmentId: this.assign.id, | ||||||
|                     submissionId: this.userSubmission!.id, |                     submissionId: this.userSubmission.id, | ||||||
|                     userId: this.currentUserId, |                     userId: this.currentUserId, | ||||||
|                 }, this.siteId); |                 }, this.siteId); | ||||||
|             } catch (error) { |             } catch (error) { | ||||||
| @ -861,7 +882,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|     async submitGrade(): Promise<void> { |     async submitGrade(): Promise<void> { | ||||||
|         // Check if there's something to be saved.
 |         // Check if there's something to be saved.
 | ||||||
|         const modified = await this.hasDataToSave(true); |         const modified = await this.hasDataToSave(true); | ||||||
|         if (!modified) { |         if (!modified || !this.assign) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -880,22 +901,21 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         const modal = await CoreDomUtils.showModalLoading('core.sending', true); |         const modal = await CoreDomUtils.showModalLoading('core.sending', true); | ||||||
| 
 | 
 | ||||||
|         (this.gradeInfo?.outcomes || []).forEach((outcome) => { |         (this.gradeInfo?.outcomes || []).forEach((outcome) => { | ||||||
|             if (outcome.itemNumber) { |             if (outcome.itemNumber && outcome.selectedId) { | ||||||
|                 outcomes[outcome.itemNumber] = outcome.selectedId!; |                 outcomes[outcome.itemNumber] = outcome.selectedId; | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         let pluginData: AddonModAssignSavePluginData = {}; |         let pluginData: AddonModAssignSavePluginData = {}; | ||||||
|         try { |         try { | ||||||
|             if (this.feedback && this.feedback.plugins) { |             if (this.feedback && this.feedback.plugins) { | ||||||
|                 pluginData = |                 pluginData = await AddonModAssignHelper.prepareFeedbackPluginData(this.assign.id, this.submitId, this.feedback); | ||||||
|                     await AddonModAssignHelper.prepareFeedbackPluginData(this.assign!.id, this.submitId, this.feedback); |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             try { |             try { | ||||||
|                 // We have all the data, now send it.
 |                 // We have all the data, now send it.
 | ||||||
|                 await AddonModAssign.submitGradingForm( |                 await AddonModAssign.submitGradingForm( | ||||||
|                     this.assign!.id, |                     this.assign.id, | ||||||
|                     this.submitId, |                     this.submitId, | ||||||
|                     this.courseId, |                     this.courseId, | ||||||
|                     grade || 0, |                     grade || 0, | ||||||
| @ -914,7 +934,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|                 this.invalidateAndRefresh(true); |                 this.invalidateAndRefresh(true); | ||||||
| 
 | 
 | ||||||
|                 CoreEvents.trigger(AddonModAssignProvider.GRADED_EVENT, { |                 CoreEvents.trigger(AddonModAssignProvider.GRADED_EVENT, { | ||||||
|                     assignmentId: this.assign!.id, |                     assignmentId: this.assign.id, | ||||||
|                     submissionId: this.submitId, |                     submissionId: this.submitId, | ||||||
|                     userId: this.currentUserId, |                     userId: this.currentUserId, | ||||||
|                 }, this.siteId); |                 }, this.siteId); | ||||||
| @ -939,21 +959,21 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         this.isGrading = true; |         this.isGrading = true; | ||||||
| 
 | 
 | ||||||
|         // Make sure outcomes is an array.
 |         // Make sure outcomes is an array.
 | ||||||
|         this.gradeInfo.outcomes = this.gradeInfo.outcomes || []; |         const gradeInfo = this.gradeInfo; | ||||||
|  |         gradeInfo.outcomes = gradeInfo.outcomes || []; | ||||||
| 
 | 
 | ||||||
|         // Check if grading method is simple or not.
 |         // Check if grading method is simple or not.
 | ||||||
|         if (this.gradeInfo.advancedgrading && this.gradeInfo.advancedgrading[0] && |         if (gradeInfo.advancedgrading && gradeInfo.advancedgrading[0] && gradeInfo.advancedgrading[0].method !== undefined) { | ||||||
|                 this.gradeInfo.advancedgrading[0].method !== undefined) { |             this.grade.method = gradeInfo.advancedgrading[0].method || 'simple'; | ||||||
|             this.grade.method = this.gradeInfo.advancedgrading[0].method || 'simple'; |  | ||||||
|         } else { |         } else { | ||||||
|             this.grade.method = 'simple'; |             this.grade.method = 'simple'; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.canSaveGrades = this.grade.method == 'simple'; // Grades can be saved if simple grading.
 |         this.canSaveGrades = this.grade.method == 'simple'; // Grades can be saved if simple grading.
 | ||||||
| 
 | 
 | ||||||
|         if (this.gradeInfo.scale) { |         if (gradeInfo.scale) { | ||||||
|             this.grade.scale = |             this.grade.scale = | ||||||
|                 CoreUtils.makeMenuFromList(this.gradeInfo.scale, Translate.instant('core.nograde')); |                 CoreUtils.makeMenuFromList(gradeInfo.scale, Translate.instant('core.nograde')); | ||||||
|         } else { |         } else { | ||||||
|             // Format the grade.
 |             // Format the grade.
 | ||||||
|             this.grade.grade = CoreUtils.formatFloat(this.grade.grade); |             this.grade.grade = CoreUtils.formatFloat(this.grade.grade); | ||||||
| @ -964,8 +984,8 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Treat outcomes.
 |         // Treat outcomes.
 | ||||||
|         if (this.gradeInfo.outcomes) { |         if (gradeInfo.outcomes) { | ||||||
|             this.gradeInfo.outcomes.forEach((outcome) => { |             gradeInfo.outcomes.forEach((outcome) => { | ||||||
|                 if (outcome.scale) { |                 if (outcome.scale) { | ||||||
|                     outcome.options = |                     outcome.options = | ||||||
|                         CoreUtils.makeMenuFromList<number>( |                         CoreUtils.makeMenuFromList<number>( | ||||||
| @ -1005,7 +1025,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|             } else if (grade.outcomeid) { |             } else if (grade.outcomeid) { | ||||||
| 
 | 
 | ||||||
|                 // Only show outcomes with info on it, outcomeid could be null if outcomes are disabled on site.
 |                 // Only show outcomes with info on it, outcomeid could be null if outcomes are disabled on site.
 | ||||||
|                 this.gradeInfo!.outcomes && this.gradeInfo!.outcomes.forEach((outcome) => { |                 gradeInfo.outcomes?.forEach((outcome) => { | ||||||
|                     if (outcome.id == String(grade.outcomeid)) { |                     if (outcome.id == String(grade.outcomeid)) { | ||||||
|                         outcome.selected = grade.gradeformatted; |                         outcome.selected = grade.gradeformatted; | ||||||
|                         outcome.modified = grade.gradedategraded; |                         outcome.modified = grade.gradedategraded; | ||||||
| @ -1018,38 +1038,42 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|                         outcomes.push(outcome); |                         outcomes.push(outcome); | ||||||
|                     } |                     } | ||||||
|                 }); |                 }); | ||||||
|                 this.gradeInfo!.disabled = grade.gradeislocked || grade.gradeisoverridden; |                 gradeInfo.disabled = grade.gradeislocked || grade.gradeisoverridden; | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         this.gradeInfo.outcomes = outcomes; |         gradeInfo.outcomes = outcomes; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Treat the last attempt. |      * Treat the last attempt. | ||||||
|      * |      * | ||||||
|      * @param submissionStatus Response of get submission status. |      * @param submissionStatus Response of get submission status. | ||||||
|  |      * @param lastAttempt Last attempt (if any). | ||||||
|      * @param promises List where to add the promises. |      * @param promises List where to add the promises. | ||||||
|      */ |      */ | ||||||
|     protected treatLastAttempt(submissionStatus: AddonModAssignGetSubmissionStatusWSResponse): Promise<void>[] { |     protected treatLastAttempt( | ||||||
|  |         submissionStatus: AddonModAssignGetSubmissionStatusWSResponse, | ||||||
|  |         lastAttempt?: AddonModAssignSubmissionAttemptFormatted, | ||||||
|  |     ): Promise<void>[] { | ||||||
|         const promises: Promise<void>[] =[]; |         const promises: Promise<void>[] =[]; | ||||||
| 
 | 
 | ||||||
|         if (!submissionStatus.lastattempt) { |         if (!lastAttempt || !this.assign) { | ||||||
|             return []; |             return []; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const submissionStatementMissing = !!this.assign!.requiresubmissionstatement && |         const submissionStatementMissing = !!this.assign.requiresubmissionstatement && | ||||||
|             this.assign!.submissionstatement === undefined; |             this.assign.submissionstatement === undefined; | ||||||
| 
 | 
 | ||||||
|         this.canSubmit = !this.isSubmittedForGrading && !this.submittedOffline && (submissionStatus.lastattempt.cansubmit || |         this.canSubmit = !this.isSubmittedForGrading && !this.submittedOffline && (lastAttempt.cansubmit || | ||||||
|             (this.hasOffline && AddonModAssign.canSubmitOffline(this.assign!, submissionStatus))); |             (this.hasOffline && AddonModAssign.canSubmitOffline(this.assign, submissionStatus))); | ||||||
| 
 | 
 | ||||||
|         this.canEdit = !this.isSubmittedForGrading && submissionStatus.lastattempt.canedit && |         this.canEdit = !this.isSubmittedForGrading && lastAttempt.canedit && | ||||||
|             (!this.submittedOffline || !this.assign!.submissiondrafts); |             (!this.submittedOffline || !this.assign.submissiondrafts); | ||||||
| 
 | 
 | ||||||
|         // Get submission statement if needed.
 |         // Get submission statement if needed.
 | ||||||
|         if (this.assign!.requiresubmissionstatement && this.assign!.submissiondrafts && this.submitId == this.currentUserId) { |         if (this.assign.requiresubmissionstatement && this.assign.submissiondrafts && this.submitId == this.currentUserId) { | ||||||
|             this.submissionStatement = this.assign!.submissionstatement; |             this.submissionStatement = this.assign.submissionstatement; | ||||||
|             this.acceptStatement = false; |             this.acceptStatement = false; | ||||||
|         } else { |         } else { | ||||||
|             this.submissionStatement = undefined; |             this.submissionStatement = undefined; | ||||||
| @ -1057,26 +1081,26 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Show error if submission statement should be shown but it couldn't be retrieved.
 |         // Show error if submission statement should be shown but it couldn't be retrieved.
 | ||||||
|         this.showErrorStatementEdit = submissionStatementMissing && !this.assign!.submissiondrafts && |         this.showErrorStatementEdit = submissionStatementMissing && !this.assign.submissiondrafts && | ||||||
|             this.submitId == this.currentUserId; |             this.submitId == this.currentUserId; | ||||||
| 
 | 
 | ||||||
|         this.showErrorStatementSubmit = submissionStatementMissing && !!this.assign!.submissiondrafts; |         this.showErrorStatementSubmit = submissionStatementMissing && !!this.assign.submissiondrafts; | ||||||
| 
 | 
 | ||||||
|         this.userSubmission = AddonModAssign.getSubmissionObjectFromAttempt(this.assign!, submissionStatus.lastattempt); |         this.userSubmission = AddonModAssign.getSubmissionObjectFromAttempt(this.assign, lastAttempt); | ||||||
| 
 | 
 | ||||||
|         if (this.assign!.attemptreopenmethod != this.attemptReopenMethodNone && this.userSubmission) { |         if (this.assign.attemptreopenmethod != this.attemptReopenMethodNone && this.userSubmission) { | ||||||
|             this.currentAttempt = this.userSubmission.attemptnumber + 1; |             this.currentAttempt = this.userSubmission.attemptnumber + 1; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.setStatusNameAndClass(submissionStatus); |         this.setStatusNameAndClass(submissionStatus); | ||||||
| 
 | 
 | ||||||
|         if (this.assign!.teamsubmission) { |         if (this.assign.teamsubmission) { | ||||||
|             if (submissionStatus.lastattempt.submissiongroup) { |             if (lastAttempt.submissiongroup) { | ||||||
|                 // Get the name of the group.
 |                 // Get the name of the group.
 | ||||||
|                 promises.push(CoreGroups.getActivityAllowedGroups(this.assign!.cmid).then((result) => { |                 promises.push(CoreGroups.getActivityAllowedGroups(this.assign.cmid).then((result) => { | ||||||
|                     const group = result.groups.find((group) => group.id == submissionStatus.lastattempt!.submissiongroup); |                     const group = result.groups.find((group) => group.id === lastAttempt.submissiongroup); | ||||||
|                     if (group) { |                     if (group) { | ||||||
|                         this.lastAttempt!.submissiongroupname = group.name; |                         lastAttempt.submissiongroupname = group.name; | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     return; |                     return; | ||||||
| @ -1086,9 +1110,9 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|             // Get the members that need to submit.
 |             // Get the members that need to submit.
 | ||||||
|             if (this.userSubmission && |             if (this.userSubmission && | ||||||
|                 this.userSubmission.status != this.statusNew && |                 this.userSubmission.status != this.statusNew && | ||||||
|                 submissionStatus.lastattempt.submissiongroupmemberswhoneedtosubmit |                 lastAttempt.submissiongroupmemberswhoneedtosubmit | ||||||
|             ) { |             ) { | ||||||
|                 submissionStatus.lastattempt.submissiongroupmemberswhoneedtosubmit.forEach((member) => { |                 lastAttempt.submissiongroupmemberswhoneedtosubmit.forEach((member) => { | ||||||
|                     if (!this.blindMarking) { |                     if (!this.blindMarking) { | ||||||
|                         promises.push(CoreUser.getProfile(member, this.courseId).then((profile) => { |                         promises.push(CoreUser.getProfile(member, this.courseId).then((profile) => { | ||||||
|                             this.membersToSubmit.push(profile); |                             this.membersToSubmit.push(profile); | ||||||
| @ -1101,23 +1125,20 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Get grading text and color.
 |         // Get grading text and color.
 | ||||||
|         this.gradingStatusTranslationId = AddonModAssign.getSubmissionGradingStatusTranslationId( |         this.gradingStatusTranslationId = AddonModAssign.getSubmissionGradingStatusTranslationId(lastAttempt.gradingstatus); | ||||||
|             submissionStatus.lastattempt.gradingstatus, |         this.gradingColor = AddonModAssign.getSubmissionGradingStatusColor(lastAttempt.gradingstatus); | ||||||
|         ); |  | ||||||
|         this.gradingColor = AddonModAssign.getSubmissionGradingStatusColor(submissionStatus.lastattempt.gradingstatus); |  | ||||||
| 
 | 
 | ||||||
|         // Get the submission plugins.
 |         // Get the submission plugins.
 | ||||||
|         if (this.userSubmission) { |         if (this.userSubmission) { | ||||||
|             if (!this.assign!.teamsubmission || |             if (!this.assign.teamsubmission || | ||||||
|                 !submissionStatus.lastattempt.submissiongroup || |                 !lastAttempt.submissiongroup || | ||||||
|                 !this.assign!.preventsubmissionnotingroup |                 !this.assign.preventsubmissionnotingroup | ||||||
|             ) { |             ) { | ||||||
|                 if (this.previousAttempt && this.previousAttempt.submission!.plugins && |                 if (this.previousAttempt?.submission?.plugins && this.userSubmission.status === this.statusReopened) { | ||||||
|                         this.userSubmission.status == this.statusReopened) { |  | ||||||
|                     // Get latest attempt if available.
 |                     // Get latest attempt if available.
 | ||||||
|                     this.submissionPlugins = this.previousAttempt.submission!.plugins; |                     this.submissionPlugins = this.previousAttempt.submission.plugins; | ||||||
|                 } else { |                 } else { | ||||||
|                     this.submissionPlugins = this.userSubmission.plugins!; |                     this.submissionPlugins = this.userSubmission.plugins || []; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @ -1135,7 +1156,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const syncId = AddonModAssignSync.getGradeSyncId(this.assign!.id, this.submitId); |         const syncId = AddonModAssignSync.getGradeSyncId(this.assign.id, this.submitId); | ||||||
| 
 | 
 | ||||||
|         if (block) { |         if (block) { | ||||||
|             CoreSync.blockOperation(AddonModAssignProvider.COMPONENT, syncId); |             CoreSync.blockOperation(AddonModAssignProvider.COMPONENT, syncId); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user