MOBILE-3787 assign: Fix non-null checks
This commit is contained in:
		
							parent
							
								
									7cc309275c
								
							
						
					
					
						commit
						9b93a0450c
					
				| @ -79,8 +79,8 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | ||||
|     submissionStatusDraft = AddonModAssignProvider.SUBMISSION_STATUS_DRAFT; | ||||
|     needGrading = AddonModAssignProvider.NEED_GRADING; | ||||
| 
 | ||||
|     protected currentUserId?: number; // Current user ID.
 | ||||
|     protected currentSite?: CoreSite; // Current user ID.
 | ||||
|     protected currentUserId!: number; // Current user ID.
 | ||||
|     protected currentSite!: CoreSite; // Current site.
 | ||||
|     protected syncEventName = AddonModAssignSyncProvider.AUTO_SYNCED; | ||||
| 
 | ||||
|     // Observers.
 | ||||
| @ -93,6 +93,9 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | ||||
|         @Optional() courseContentsPage?: CoreCourseContentsPage, | ||||
|     ) { | ||||
|         super('AddonModLessonIndexComponent', content, courseContentsPage); | ||||
| 
 | ||||
|         this.currentSite = CoreSites.getRequiredCurrentSite(); | ||||
|         this.currentUserId = this.currentSite.getUserId(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -101,9 +104,6 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         super.ngOnInit(); | ||||
| 
 | ||||
|         this.currentUserId = CoreSites.getCurrentSiteUserId(); | ||||
|         this.currentSite = CoreSites.getCurrentSite(); | ||||
| 
 | ||||
|         // Listen to events.
 | ||||
|         this.savedObserver = CoreEvents.on( | ||||
|             AddonModAssignProvider.SUBMISSION_SAVED_EVENT, | ||||
| @ -139,8 +139,12 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | ||||
| 
 | ||||
|         await this.loadContent(false, true); | ||||
| 
 | ||||
|         if (!this.assign) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             await AddonModAssign.logView(this.assign!.id, this.assign!.name); | ||||
|             await AddonModAssign.logView(this.assign.id, this.assign.name); | ||||
|             CoreCourse.checkModuleCompletion(this.courseId, this.module.completiondata); | ||||
|         } catch { | ||||
|             // Ignore errors. Just don't check Module completion.
 | ||||
| @ -148,10 +152,10 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | ||||
| 
 | ||||
|         if (this.canViewAllSubmissions) { | ||||
|             // User can see all submissions, log grading view.
 | ||||
|             CoreUtils.ignoreErrors(AddonModAssign.logGradingView(this.assign!.id, this.assign!.name)); | ||||
|             CoreUtils.ignoreErrors(AddonModAssign.logGradingView(this.assign.id, this.assign.name)); | ||||
|         } else if (this.canViewOwnSubmission) { | ||||
|             // User can only see their own submission, log view the user submission.
 | ||||
|             CoreUtils.ignoreErrors(AddonModAssign.logSubmissionView(this.assign!.id, this.assign!.name)); | ||||
|             CoreUtils.ignoreErrors(AddonModAssign.logSubmissionView(this.assign.id, this.assign.name)); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -266,7 +270,11 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | ||||
|     async setGroup(groupId = 0): Promise<void> { | ||||
|         this.group = groupId; | ||||
| 
 | ||||
|         const submissionStatus = await AddonModAssign.getSubmissionStatus(this.assign!.id, { | ||||
|         if (!this.assign) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const submissionStatus = await AddonModAssign.getSubmissionStatus(this.assign.id, { | ||||
|             groupId: this.group, | ||||
|             cmId: this.module.id, | ||||
|         }); | ||||
| @ -278,10 +286,10 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         if (this.summary?.warnofungroupedusers === true) { | ||||
|         if (this.summary.warnofungroupedusers === true) { | ||||
|             this.summary.warnofungroupedusers = 'ungroupedusers'; | ||||
|         } else { | ||||
|             switch (this.summary?.warnofungroupedusers) { | ||||
|             switch (this.summary.warnofungroupedusers) { | ||||
|                 case AddonModAssignProvider.WARN_GROUPS_REQUIRED: | ||||
|                     this.summary.warnofungroupedusers = 'ungroupedusers'; | ||||
|                     break; | ||||
| @ -386,16 +394,16 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | ||||
|      * @return True if refresh is needed, false otherwise. | ||||
|      */ | ||||
|     protected isRefreshSyncNeeded(syncEventData: AddonModAssignAutoSyncData): boolean { | ||||
|         if (this.assign && syncEventData.assignId == this.assign.id) { | ||||
|             if (syncEventData.warnings && syncEventData.warnings.length) { | ||||
|                 // Show warnings.
 | ||||
|                 CoreDomUtils.showErrorModal(syncEventData.warnings[0]); | ||||
|             } | ||||
| 
 | ||||
|             return true; | ||||
|         if (!this.assign || syncEventData.assignId != this.assign.id) { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         return false; | ||||
|         if (syncEventData.warnings && syncEventData.warnings.length) { | ||||
|             // Show warnings.
 | ||||
|             CoreDomUtils.showErrorModal(syncEventData.warnings[0]); | ||||
|         } | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -403,8 +411,12 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | ||||
|      * | ||||
|      * @return Promise resolved when done. | ||||
|      */ | ||||
|     protected sync(): Promise<AddonModAssignSyncResult> { | ||||
|         return AddonModAssignSync.syncAssign(this.assign!.id); | ||||
|     protected async sync(): Promise<AddonModAssignSyncResult | void> { | ||||
|         if (!this.assign) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         await AddonModAssignSync.syncAssign(this.assign.id); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -612,11 +612,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | ||||
| 
 | ||||
|             // If we have data about the grader, get its profile.
 | ||||
|             if (feedback.grade && feedback.grade.grader > 0) { | ||||
|                 try { | ||||
|                     this.grader = await CoreUser.getProfile(feedback.grade.grader, this.courseId); | ||||
|                 } catch { | ||||
|                     // Ignore errors.
 | ||||
|                 } | ||||
|                 this.grader = await CoreUtils.ignoreErrors(CoreUser.getProfile(feedback.grade.grader, this.courseId)); | ||||
|             } else { | ||||
|                 delete this.grader; | ||||
|             } | ||||
| @ -633,7 +629,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can | ||||
|             if (feedback.grade && feedback.grade.grade && !this.grade.grade) { | ||||
|                 const parsedGrade = parseFloat(feedback.grade.grade); | ||||
| 
 | ||||
|                 this.grade!.grade = parsedGrade >= 0 ? parsedGrade : undefined; | ||||
|                 this.grade.grade = parsedGrade >= 0 ? parsedGrade : undefined; | ||||
|                 this.grade.gradebookGrade = CoreUtils.formatFloat(this.grade.grade); | ||||
|                 this.originalGrades.grade = this.grade.grade; | ||||
|             } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user