MOBILE-3833 navigator: Add required route params functions
This commit is contained in:
		
							parent
							
								
									0d3123d2af
								
							
						
					
					
						commit
						34f9c3ab57
					
				| @ -147,7 +147,16 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { | ||||
|      * View loaded. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.eventId = CoreNavigator.getRouteNumberParam('id')!; | ||||
|         try { | ||||
|             this.eventId = CoreNavigator.getRequiredRouteNumberParam('id'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.syncIcon = CoreConstants.ICON_LOADING; | ||||
| 
 | ||||
|         this.fetchEvent(); | ||||
|  | ||||
| @ -60,11 +60,19 @@ export class AddonCompetencyCompetencyPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.competencyId = CoreNavigator.getRouteNumberParam('competencyId')!; | ||||
|         this.planId = CoreNavigator.getRouteNumberParam('planId'); | ||||
|         if (!this.planId) { | ||||
|             this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|             this.userId = CoreNavigator.getRouteNumberParam('userId'); | ||||
|         try { | ||||
|             this.competencyId = CoreNavigator.getRequiredRouteNumberParam('competencyId'); | ||||
|             this.planId = CoreNavigator.getRouteNumberParam('planId'); | ||||
|             if (!this.planId) { | ||||
|                 this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|                 this.userId = CoreNavigator.getRouteNumberParam('userId'); | ||||
|             } | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|  | ||||
| @ -40,9 +40,17 @@ export class AddonCompetencyCompetencySummaryPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.competencyId = CoreNavigator.getRouteNumberParam('competencyId')!; | ||||
|         this.contextLevel = CoreNavigator.getRouteParam<ContextLevel>('contextLevel'); | ||||
|         this.contextInstanceId = CoreNavigator.getRouteNumberParam('contextInstanceId'); | ||||
|         try { | ||||
|             this.competencyId = CoreNavigator.getRequiredRouteNumberParam('competencyId'); | ||||
|             this.contextLevel = CoreNavigator.getRouteParam<ContextLevel>('contextLevel'); | ||||
|             this.contextInstanceId = CoreNavigator.getRouteNumberParam('contextInstanceId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             await this.fetchCompetency(); | ||||
|  | ||||
| @ -42,8 +42,16 @@ export class AddonCompetencyCourseCompetenciesPage implements OnInit { | ||||
|      * View loaded. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.userId = CoreNavigator.getRouteNumberParam('userId')!; | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.userId = CoreNavigator.getRequiredRouteNumberParam('userId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.fetchCourseCompetencies().finally(() => { | ||||
|             this.competenciesLoaded = true; | ||||
|  | ||||
| @ -39,7 +39,15 @@ export class AddonCompetencyPlanPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.planId = CoreNavigator.getRouteNumberParam('planId')!; | ||||
|         try { | ||||
|             this.planId = CoreNavigator.getRequiredRouteNumberParam('planId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.fetchLearningPlan().finally(() => { | ||||
|             this.loaded = true; | ||||
|  | ||||
| @ -44,11 +44,15 @@ export class AddonCourseCompletionReportPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId(); | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId(); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|         if (!this.userId) { | ||||
|             this.userId = CoreSites.getCurrentSiteUserId(); | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.fetchCompletion().finally(() => { | ||||
|  | ||||
| @ -78,9 +78,17 @@ export class AddonModAssignEditPage implements OnInit, OnDestroy, CanLeave { | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.moduleId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.isBlind = !!CoreNavigator.getRouteNumberParam('blindId'); | ||||
|         try { | ||||
|             this.moduleId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.isBlind = !!CoreNavigator.getRouteNumberParam('blindId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.fetchAssignment().finally(() => { | ||||
|             this.loaded = true; | ||||
|  | ||||
| @ -120,10 +120,18 @@ export class AddonModAssignSubmissionListPage implements AfterViewInit, OnDestro | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngAfterViewInit(): void { | ||||
|         this.moduleId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.groupId = CoreNavigator.getRouteNumberParam('groupId') || 0; | ||||
|         this.selectedStatus = CoreNavigator.getRouteParam('status'); | ||||
|         try { | ||||
|             this.moduleId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.groupId = CoreNavigator.getRouteNumberParam('groupId') || 0; | ||||
|             this.selectedStatus = CoreNavigator.getRouteParam('status'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         if (this.selectedStatus) { | ||||
|             if (this.selectedStatus == AddonModAssignProvider.NEED_GRADING) { | ||||
|  | ||||
| @ -55,10 +55,18 @@ export class AddonModAssignSubmissionReviewPage implements OnInit, CanLeave { | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.route.queryParams.subscribe((params) => { | ||||
|             this.moduleId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|             this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|             this.submitId = CoreNavigator.getRouteNumberParam('submitId') || 0; | ||||
|             this.blindId = CoreNavigator.getRouteNumberParam('blindId', { params }); | ||||
|             try { | ||||
|                 this.moduleId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|                 this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|                 this.submitId = CoreNavigator.getRouteNumberParam('submitId') || 0; | ||||
|                 this.blindId = CoreNavigator.getRouteNumberParam('blindId', { params }); | ||||
|             } catch (error) { | ||||
|                 CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|                 CoreNavigator.back(); | ||||
| 
 | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             this.fetchSubmission().finally(() => { | ||||
|                 this.loaded = true; | ||||
|  | ||||
| @ -78,12 +78,12 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.chatId = CoreNavigator.getRouteNumberParam('chatId')!; | ||||
|         this.title = CoreNavigator.getRouteParam('title') || ''; | ||||
| 
 | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.chatId = CoreNavigator.getRequiredRouteNumberParam('chatId'); | ||||
|             this.title = CoreNavigator.getRouteParam('title') || ''; | ||||
| 
 | ||||
|             await this.loginUser(); | ||||
| 
 | ||||
|             await this.fetchMessages(); | ||||
|  | ||||
| @ -47,12 +47,20 @@ export class AddonModChatSessionMessagesPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.sessionStart = CoreNavigator.getRouteNumberParam('sessionStart')!; | ||||
|         this.sessionEnd = CoreNavigator.getRouteNumberParam('sessionEnd')!; | ||||
|         this.chatId = CoreNavigator.getRouteNumberParam('chatId')!; | ||||
|         this.groupId = CoreNavigator.getRouteNumberParam('groupId') || 0; | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.sessionStart = CoreNavigator.getRequiredRouteNumberParam('sessionStart'); | ||||
|             this.sessionEnd = CoreNavigator.getRequiredRouteNumberParam('sessionEnd'); | ||||
|             this.chatId = CoreNavigator.getRequiredRouteNumberParam('chatId'); | ||||
|             this.groupId = CoreNavigator.getRouteNumberParam('groupId') || 0; | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.currentUserId = CoreSites.getCurrentSiteUserId(); | ||||
| 
 | ||||
|  | ||||
| @ -53,10 +53,18 @@ export class AddonModChatSessionsPage implements AfterViewInit, OnDestroy { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngAfterViewInit(): Promise<void> { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.chatId = CoreNavigator.getRouteNumberParam('chatId')!; | ||||
|         this.sessions.setChatId(this.chatId); | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.chatId = CoreNavigator.getRequiredRouteNumberParam('chatId'); | ||||
|             this.sessions.setChatId(this.chatId); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         await this.fetchSessions(); | ||||
| 
 | ||||
|  | ||||
| @ -53,7 +53,7 @@ export class AddonModDataFieldPluginComponent implements OnInit, OnChanges { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try{ | ||||
|         try { | ||||
|             // Check if the plugin has defined its own component to render itself.
 | ||||
|             this.fieldComponent = await AddonModDataFieldsDelegate.getComponentForField(this.field); | ||||
| 
 | ||||
|  | ||||
| @ -96,10 +96,18 @@ export class AddonModDataEditPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.module = CoreNavigator.getRouteParam<CoreCourseModule>('module')!; | ||||
|         this.entryId = CoreNavigator.getRouteNumberParam('entryId') || undefined; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; | ||||
|         try { | ||||
|             this.module = CoreNavigator.getRequiredRouteParam<CoreCourseModule>('module'); | ||||
|             this.entryId = CoreNavigator.getRouteNumberParam('entryId') || undefined; | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         // If entryId is lower than 0 or null, it is a new entry or an offline entry.
 | ||||
|         this.isEditing = typeof this.entryId != 'undefined' && this.entryId > 0; | ||||
|  | ||||
| @ -132,11 +132,20 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.module = CoreNavigator.getRouteParam<CoreCourseModule>('module')!; | ||||
|         this.entryId = CoreNavigator.getRouteNumberParam('entryId') || undefined; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; | ||||
|         this.offset = CoreNavigator.getRouteNumberParam('offset'); | ||||
|         try { | ||||
|             this.module = CoreNavigator.getRequiredRouteParam<CoreCourseModule>('module'); | ||||
|             this.entryId = CoreNavigator.getRouteNumberParam('entryId') || undefined; | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; | ||||
|             this.offset = CoreNavigator.getRouteNumberParam('offset'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.title = this.module.name; | ||||
| 
 | ||||
|         this.commentsEnabled = !CoreComments.areCommentsDisabledInSite(); | ||||
|  | ||||
| @ -49,9 +49,17 @@ export class AddonModFeedbackAttemptPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.attemptId = CoreNavigator.getRouteNumberParam('attemptId')!; | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.attemptId = CoreNavigator.getRequiredRouteNumberParam('attemptId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.fetchData(); | ||||
|     } | ||||
|  | ||||
| @ -92,12 +92,20 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.currentPage = CoreNavigator.getRouteNumberParam('page'); | ||||
|         this.title = CoreNavigator.getRouteParam('title'); | ||||
|         this.preview = !!CoreNavigator.getRouteBooleanParam('preview'); | ||||
|         this.fromIndex = !!CoreNavigator.getRouteBooleanParam('fromIndex'); | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.currentPage = CoreNavigator.getRouteNumberParam('page'); | ||||
|             this.title = CoreNavigator.getRouteParam('title'); | ||||
|             this.preview = !!CoreNavigator.getRouteBooleanParam('preview'); | ||||
|             this.fromIndex = !!CoreNavigator.getRouteBooleanParam('fromIndex'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         await this.fetchData(); | ||||
| 
 | ||||
|  | ||||
| @ -47,9 +47,17 @@ export class AddonModFeedbackNonRespondentsPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.fetchData(); | ||||
|     } | ||||
|  | ||||
| @ -63,9 +63,17 @@ export class AddonModFeedbackRespondentsPage implements AfterViewInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngAfterViewInit(): Promise<void> { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         await this.fetchData(); | ||||
| 
 | ||||
|  | ||||
| @ -65,7 +65,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|     discussionId!: number; | ||||
|     forum: Partial<AddonModForumData> = {}; | ||||
|     accessInfo: AddonModForumAccessInformation = {}; | ||||
|     discussion!: AddonModForumDiscussion; | ||||
|     discussion?: AddonModForumDiscussion; | ||||
|     startingPost?: Post; | ||||
|     posts!: Post[]; | ||||
|     discussionLoaded = false; | ||||
| @ -100,8 +100,8 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|     leavingPage = false; | ||||
| 
 | ||||
|     protected forumId!: number; | ||||
|     protected postId!: number; | ||||
|     protected parent!: number; | ||||
|     protected postId?: number; | ||||
|     protected parent?: number; | ||||
|     protected onlineObserver?: Subscription; | ||||
|     protected syncObserver?: CoreEventObserver; | ||||
|     protected syncManualObserver?: CoreEventObserver; | ||||
| @ -122,16 +122,25 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|     } | ||||
| 
 | ||||
|     ngOnInit(): void { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.forumId = CoreNavigator.getRouteNumberParam('forumId')!; | ||||
|         this.discussion = CoreNavigator.getRouteParam<AddonModForumDiscussion>('discussion')!; | ||||
|         this.discussionId = this.discussion | ||||
|             ? this.discussion.discussion | ||||
|             : CoreNavigator.getRouteNumberParam('discussionId')!; | ||||
|         this.trackPosts = CoreNavigator.getRouteBooleanParam('trackPosts')!; | ||||
|         this.postId = CoreNavigator.getRouteNumberParam('postId')!; | ||||
|         this.parent = CoreNavigator.getRouteNumberParam('parent')!; | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.forumId = CoreNavigator.getRequiredRouteNumberParam('forumId'); | ||||
|             this.discussion = CoreNavigator.getRouteParam<AddonModForumDiscussion>('discussion'); | ||||
|             this.discussionId = this.discussion | ||||
|                 ? this.discussion.discussion | ||||
|                 : CoreNavigator.getRequiredRouteNumberParam('discussionId'); | ||||
|             this.trackPosts = CoreNavigator.getRouteBooleanParam('trackPosts') || false; | ||||
|             this.postId = CoreNavigator.getRouteNumberParam('postId'); | ||||
|             this.parent = CoreNavigator.getRouteNumberParam('parent'); | ||||
| 
 | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             this.goBack(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.isOnline = CoreApp.isOnline(); | ||||
|         this.onlineObserver = Network.onChange().subscribe(() => { | ||||
| @ -148,11 +157,9 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|      * View loaded. | ||||
|      */ | ||||
|     async ngAfterViewInit(): Promise<void> { | ||||
|         if (this.parent) { | ||||
|             this.sort = 'nested'; // Force nested order.
 | ||||
|         } else { | ||||
|             this.sort = await this.getUserSort(); | ||||
|         } | ||||
|         this.sort = this.parent | ||||
|             ? 'nested' // Force nested order.
 | ||||
|             : await this.getUserSort(); | ||||
| 
 | ||||
|         await this.fetchPosts(true, false, true); | ||||
| 
 | ||||
| @ -183,6 +190,16 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|             await this.loadDiscussion(this.forumId, this.cmId, this.discussionId); | ||||
|         } | ||||
| 
 | ||||
|         if (!this.discussion) { | ||||
|             CoreDomUtils.showErrorModal('Cannot get the discussion'); | ||||
| 
 | ||||
|             this.goBack(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const discussion = this.discussion; | ||||
| 
 | ||||
|         // Refresh data if this discussion is synchronized automatically.
 | ||||
|         this.syncObserver = CoreEvents.on(AddonModForumSyncProvider.AUTO_SYNCED, data => { | ||||
|             if (data.forumId == this.forumId && this.discussionId == data.discussionId | ||||
| @ -204,7 +221,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|         }, CoreSites.getCurrentSiteId()); | ||||
| 
 | ||||
|         // Invalidate discussion list if it was not read.
 | ||||
|         if (this.discussion.numunread > 0) { | ||||
|         if (discussion.numunread > 0) { | ||||
|             AddonModForum.invalidateDiscussionsList(this.forumId); | ||||
|         } | ||||
| 
 | ||||
| @ -227,22 +244,18 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|             if ((this.forumId && this.forumId === data.forumId) || data.cmId === this.cmId) { | ||||
|                 AddonModForum.invalidateDiscussionsList(this.forumId).finally(() => { | ||||
|                     if (typeof data.locked != 'undefined') { | ||||
|                         this.discussion.locked = data.locked; | ||||
|                         discussion.locked = data.locked; | ||||
|                     } | ||||
|                     if (typeof data.pinned != 'undefined') { | ||||
|                         this.discussion.pinned = data.pinned; | ||||
|                         discussion.pinned = data.pinned; | ||||
|                     } | ||||
|                     if (typeof data.starred != 'undefined') { | ||||
|                         this.discussion.starred = data.starred; | ||||
|                         discussion.starred = data.starred; | ||||
|                     } | ||||
| 
 | ||||
|                     if (typeof data.deleted != 'undefined' && data.deleted) { | ||||
|                         if (!data.post?.parentid) { | ||||
|                             if (this.splitView?.outletActivated) { | ||||
|                                 CoreNavigator.navigate('../'); | ||||
|                             } else { | ||||
|                                 CoreNavigator.back(); | ||||
|                             } | ||||
|                             this.goBack(); | ||||
|                         } else { | ||||
|                             this.discussionLoaded = false; | ||||
|                             this.refreshPosts(); | ||||
| @ -272,6 +285,17 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Helper function to go back. | ||||
|      */ | ||||
|     protected goBack(): void { | ||||
|         if (this.splitView?.outletActivated) { | ||||
|             CoreNavigator.navigate('../'); | ||||
|         } else { | ||||
|             CoreNavigator.back(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Runs when the page is about to leave and no longer be the active page. | ||||
|      */ | ||||
| @ -515,7 +539,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|             this.syncIcon = CoreConstants.ICON_SYNC; | ||||
| 
 | ||||
|             if (forceMarkAsRead || (hasUnreadPosts && this.trackPosts)) { | ||||
|                 // // Add log in Moodle and mark unread posts as readed.
 | ||||
|                 // Add log in Moodle and mark unread posts as readed.
 | ||||
|                 AddonModForum.logDiscussionView(this.discussionId, this.forumId || -1, this.forum.name).catch(() => { | ||||
|                     // Ignore errors.
 | ||||
|                 }).finally(() => { | ||||
| @ -543,14 +567,8 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             const discussion = await AddonModForumHelper.getDiscussionById(forumId, cmId, discussionId); | ||||
| 
 | ||||
|             this.discussion = discussion; | ||||
|             this.discussionId = this.discussion.discussion; | ||||
|         } catch (error) { | ||||
|             // Ignore errors.
 | ||||
|         } | ||||
|         this.discussion = await AddonModForumHelper.getDiscussionById(forumId, cmId, discussionId); | ||||
|         this.discussionId = this.discussion.discussion; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -630,7 +648,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|      * @param showErrors Whether to show errors in a modal. | ||||
|      * @return Promise resolved when done. | ||||
|      */ | ||||
|     refreshPosts(sync?: boolean, showErrors?: boolean): Promise<void> { | ||||
|     async refreshPosts(sync?: boolean, showErrors?: boolean): Promise<void> { | ||||
|         this.content.scrollToTop(); | ||||
|         this.refreshIcon = CoreConstants.ICON_LOADING; | ||||
|         this.syncIcon = CoreConstants.ICON_LOADING; | ||||
| @ -642,9 +660,9 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|             AddonModForum.invalidateCanAddDiscussion(this.forumId), | ||||
|         ]; | ||||
| 
 | ||||
|         return CoreUtils.allPromises(promises).catch(() => { | ||||
|             // Ignore errors.
 | ||||
|         }).then(() => this.fetchPosts(sync, showErrors)); | ||||
|         await CoreUtils.ignoreErrors(CoreUtils.allPromises(promises)); | ||||
| 
 | ||||
|         await this.fetchPosts(sync, showErrors); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -668,6 +686,10 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|      * @param locked True to lock the discussion, false to unlock. | ||||
|      */ | ||||
|     async setLockState(locked: boolean): Promise<void> { | ||||
|         if (!this.discussion) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const modal = await CoreDomUtils.showModalLoading('core.sending', true); | ||||
| 
 | ||||
|         try { | ||||
| @ -696,6 +718,10 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|      * @param pinned True to pin the discussion, false to unpin it. | ||||
|      */ | ||||
|     async setPinState(pinned: boolean): Promise<void> { | ||||
|         if (!this.discussion) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const modal = await CoreDomUtils.showModalLoading('core.sending', true); | ||||
| 
 | ||||
|         try { | ||||
| @ -725,6 +751,10 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes | ||||
|      * @param starred True to star the discussion, false to unstar it. | ||||
|      */ | ||||
|     async toggleFavouriteState(starred: boolean): Promise<void> { | ||||
|         if (!this.discussion) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const modal = await CoreDomUtils.showModalLoading('core.sending', true); | ||||
| 
 | ||||
|         try { | ||||
|  | ||||
| @ -103,10 +103,18 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.forumId = CoreNavigator.getRouteNumberParam('forumId')!; | ||||
|         this.timeCreated = CoreNavigator.getRouteNumberParam('timeCreated')!; | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.forumId = CoreNavigator.getRequiredRouteNumberParam('forumId'); | ||||
|             this.timeCreated = CoreNavigator.getRequiredRouteNumberParam('timeCreated'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             this.goBack(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.fetchDiscussionData().finally(() => { | ||||
|             this.groupsLoaded = true; | ||||
| @ -595,6 +603,17 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea | ||||
|         delete this.syncObserver; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Helper function to go back. | ||||
|      */ | ||||
|     protected goBack(): void { | ||||
|         if (this.splitView?.outletActivated) { | ||||
|             CoreNavigator.navigate('../../'); | ||||
|         } else { | ||||
|             CoreNavigator.back(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Page destroyed. | ||||
|      */ | ||||
|  | ||||
| @ -73,7 +73,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { | ||||
|     }; | ||||
| 
 | ||||
|     protected timecreated!: number; | ||||
|     protected concept?: string; | ||||
|     protected concept = ''; | ||||
|     protected syncId?: string; | ||||
|     protected syncObserver?: CoreEventObserver; | ||||
|     protected isDestroyed = false; | ||||
| @ -86,11 +86,19 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.timecreated = CoreNavigator.getRouteNumberParam('timecreated')!; | ||||
|         this.concept = CoreNavigator.getRouteParam<string>('concept')!; | ||||
|         this.editorExtraParams.timecreated = this.timecreated; | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.timecreated = CoreNavigator.getRequiredRouteNumberParam('timecreated'); | ||||
|             this.concept = CoreNavigator.getRouteParam<string>('concept') || ''; | ||||
|             this.editorExtraParams.timecreated = this.timecreated; | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             this.goBack(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.fetchData(); | ||||
|     } | ||||
| @ -116,7 +124,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingglossary', true); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
|             this.goBack(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -126,7 +134,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { | ||||
|      * @return Promise resolved when done. | ||||
|      */ | ||||
|     protected async loadOfflineData(): Promise<void> { | ||||
|         const entry = await AddonModGlossaryOffline.getNewEntry(this.glossary!.id, this.concept || '', this.timecreated); | ||||
|         const entry = await AddonModGlossaryOffline.getNewEntry(this.glossary!.id, this.concept, this.timecreated); | ||||
| 
 | ||||
|         this.entry.concept = entry.concept || ''; | ||||
|         this.entry.definition = entry.definition || ''; | ||||
| @ -367,4 +375,15 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Helper function to go back. | ||||
|      */ | ||||
|     protected goBack(): void { | ||||
|         if (this.splitView?.outletActivated) { | ||||
|             CoreNavigator.navigate('../../'); | ||||
|         } else { | ||||
|             CoreNavigator.back(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -57,10 +57,18 @@ export class AddonModGlossaryEntryPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.entryId = CoreNavigator.getRouteNumberParam('entryId')!; | ||||
|         this.tagsEnabled = CoreTag.areTagsAvailableInSite(); | ||||
|         this.commentsEnabled = !CoreComments.areCommentsDisabledInSite(); | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.entryId = CoreNavigator.getRequiredRouteNumberParam('entryId'); | ||||
|             this.tagsEnabled = CoreTag.areTagsAvailableInSite(); | ||||
|             this.commentsEnabled = !CoreComments.areCommentsDisabledInSite(); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             await this.fetchEntry(); | ||||
|  | ||||
| @ -50,9 +50,17 @@ export class AddonModH5PActivityAttemptResultsPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.attemptId = CoreNavigator.getRouteNumberParam('attemptId')!; | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.attemptId = CoreNavigator.getRequiredRouteNumberParam('attemptId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             await this.fetchData(); | ||||
|  | ||||
| @ -51,9 +51,18 @@ export class AddonModH5PActivityUserAttemptsPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId(); | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId(); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.isCurrentUser = this.userId == CoreSites.getCurrentSiteUserId(); | ||||
| 
 | ||||
|         try { | ||||
|  | ||||
| @ -49,8 +49,16 @@ export class AddonModH5PActivityUsersAttemptsPage implements OnInit { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             await this.fetchData(); | ||||
|  | ||||
| @ -119,12 +119,20 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave { | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.password = CoreNavigator.getRouteParam('password'); | ||||
|         this.review = !!CoreNavigator.getRouteBooleanParam('review'); | ||||
|         this.currentPage = CoreNavigator.getRouteNumberParam('pageId'); | ||||
|         this.retakeToReview = CoreNavigator.getRouteNumberParam('retake'); | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.password = CoreNavigator.getRouteParam('password'); | ||||
|             this.review = !!CoreNavigator.getRouteBooleanParam('review'); | ||||
|             this.currentPage = CoreNavigator.getRouteNumberParam('pageId'); | ||||
|             this.retakeToReview = CoreNavigator.getRouteNumberParam('retake'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             // Fetch the Lesson data.
 | ||||
|  | ||||
| @ -64,10 +64,18 @@ export class AddonModLessonUserRetakePage implements OnInit { | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId(); | ||||
|         this.retakeNumber = CoreNavigator.getRouteNumberParam('retake'); | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId(); | ||||
|             this.retakeNumber = CoreNavigator.getRouteNumberParam('retake'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         // Fetch the data.
 | ||||
|         this.fetchData().finally(() => { | ||||
|  | ||||
| @ -52,9 +52,17 @@ export class AddonModQuizAttemptPage implements OnInit { | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.attemptId = CoreNavigator.getRouteNumberParam('attemptId')!; | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.attemptId = CoreNavigator.getRequiredRouteNumberParam('attemptId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.fetchQuizData().finally(() => { | ||||
|             this.loaded = true; | ||||
|  | ||||
| @ -106,9 +106,17 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave { | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.moduleUrl = CoreNavigator.getRouteParam('moduleUrl'); | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.moduleUrl = CoreNavigator.getRouteParam('moduleUrl'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         // Create the auto save instance.
 | ||||
|         this.autoSave = new AddonModQuizAutoSave( | ||||
|  | ||||
| @ -83,11 +83,19 @@ export class AddonModQuizReviewPage implements OnInit { | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.attemptId = CoreNavigator.getRouteNumberParam('attemptId')!; | ||||
|         this.currentPage = CoreNavigator.getRouteNumberParam('page') || -1; | ||||
|         this.showAll = this.currentPage == -1; | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.attemptId = CoreNavigator.getRequiredRouteNumberParam('attemptId'); | ||||
|             this.currentPage = CoreNavigator.getRouteNumberParam('page') || -1; | ||||
|             this.showAll = this.currentPage == -1; | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             await this.fetchData(); | ||||
|  | ||||
| @ -88,14 +88,22 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy { | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.mode = CoreNavigator.getRouteParam('mode') || AddonModScormProvider.MODENORMAL; | ||||
|         this.moduleUrl = CoreNavigator.getRouteParam('moduleUrl') || ''; | ||||
|         this.newAttempt = !!CoreNavigator.getRouteBooleanParam('newAttempt'); | ||||
|         this.organizationId = CoreNavigator.getRouteParam('organizationId'); | ||||
|         this.initialScoId = CoreNavigator.getRouteNumberParam('scoId'); | ||||
|         this.siteId = CoreSites.getCurrentSiteId(); | ||||
|         try { | ||||
|             this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.mode = CoreNavigator.getRouteParam('mode') || AddonModScormProvider.MODENORMAL; | ||||
|             this.moduleUrl = CoreNavigator.getRouteParam('moduleUrl') || ''; | ||||
|             this.newAttempt = !!CoreNavigator.getRouteBooleanParam('newAttempt'); | ||||
|             this.organizationId = CoreNavigator.getRouteParam('organizationId'); | ||||
|             this.initialScoId = CoreNavigator.getRouteNumberParam('scoId'); | ||||
|             this.siteId = CoreSites.getCurrentSiteId(); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             // Fetch the SCORM data.
 | ||||
|  | ||||
| @ -117,10 +117,18 @@ export class AddonModWorkshopAssessmentPage implements OnInit, OnDestroy, CanLea | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.assessment = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionAssessmentWithFormData>('assessment')!; | ||||
|         this.submission = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionData>('submission')!; | ||||
|         this.profile = CoreNavigator.getRouteParam<CoreUserProfile>('profile')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         try { | ||||
|             this.assessment = CoreNavigator.getRequiredRouteParam<AddonModWorkshopSubmissionAssessmentWithFormData>('assessment'); | ||||
|             this.submission = CoreNavigator.getRequiredRouteParam<AddonModWorkshopSubmissionData>('submission'); | ||||
|             this.profile = CoreNavigator.getRequiredRouteParam<CoreUserProfile>('profile'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.assessmentId = this.assessment.id; | ||||
|         this.workshopId = this.submission.workshopid; | ||||
|  | ||||
| @ -99,10 +99,18 @@ export class AddonModWorkshopEditSubmissionPage implements OnInit, OnDestroy, Ca | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.module = CoreNavigator.getRouteParam<CoreCourseModule>('module')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.access = CoreNavigator.getRouteParam<AddonModWorkshopGetWorkshopAccessInformationWSResponse>('access')!; | ||||
|         this.submissionId = CoreNavigator.getRouteNumberParam('submissionId') || 0; | ||||
|         try { | ||||
|             this.module = CoreNavigator.getRequiredRouteParam<CoreCourseModule>('module'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.access = CoreNavigator.getRequiredRouteParam<AddonModWorkshopGetWorkshopAccessInformationWSResponse>('access'); | ||||
|             this.submissionId = CoreNavigator.getRouteNumberParam('submissionId') || 0; | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         if (this.submissionId > 0) { | ||||
|             this.editorExtraParams.id = this.submissionId; | ||||
|  | ||||
| @ -130,15 +130,22 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy, CanLea | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         try { | ||||
|             this.submissionId = CoreNavigator.getRequiredRouteNumberParam('submissionId'); | ||||
|             this.module = CoreNavigator.getRequiredRouteParam<CoreCourseModule>('module'); | ||||
|             this.workshop = CoreNavigator.getRequiredRouteParam<AddonModWorkshopData>('workshop'); | ||||
|             this.access = CoreNavigator.getRequiredRouteParam<AddonModWorkshopGetWorkshopAccessInformationWSResponse>('access'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.profile = CoreNavigator.getRouteParam<CoreUserProfile>('profile'); | ||||
|             this.submissionInfo = CoreNavigator.getRequiredRouteParam<AddonModWorkshopSubmissionDataWithOfflineData>('submission'); | ||||
|             this.assessment = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionAssessmentWithFormData>('assessment'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|         this.submissionId = CoreNavigator.getRouteNumberParam('submissionId')!; | ||||
|         this.module = CoreNavigator.getRouteParam<CoreCourseModule>('module')!; | ||||
|         this.workshop = CoreNavigator.getRouteParam<AddonModWorkshopData>('workshop')!; | ||||
|         this.access = CoreNavigator.getRouteParam<AddonModWorkshopGetWorkshopAccessInformationWSResponse>('access')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.profile = CoreNavigator.getRouteParam<CoreUserProfile>('profile'); | ||||
|         this.submissionInfo = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionDataWithOfflineData>('submission')!; | ||||
|         this.assessment = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionAssessmentWithFormData>('assessment'); | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.title = this.module.name; | ||||
|         this.workshopId = this.module.instance || this.workshop.id; | ||||
|  | ||||
| @ -40,7 +40,7 @@ export class AddonNotesListPage implements OnInit, OnDestroy { | ||||
| 
 | ||||
|      @ViewChild(IonContent) content?: IonContent; | ||||
| 
 | ||||
|     courseId: number; | ||||
|     courseId!: number; | ||||
|     userId?: number; | ||||
|     type: AddonNotesPublishState = 'course'; | ||||
|     refreshIcon = CoreConstants.ICON_LOADING; | ||||
| @ -51,13 +51,21 @@ export class AddonNotesListPage implements OnInit, OnDestroy { | ||||
|     user?: CoreUserProfile; | ||||
|     showDelete = false; | ||||
|     canDeleteNotes = false; | ||||
|     currentUserId: number; | ||||
|     currentUserId!: number; | ||||
| 
 | ||||
|     protected syncObserver: CoreEventObserver; | ||||
|     protected syncObserver!: CoreEventObserver; | ||||
| 
 | ||||
|     constructor() { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.userId = CoreNavigator.getRouteNumberParam('userId'); | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.userId = CoreNavigator.getRouteNumberParam('userId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         // Refresh data if notes are synchronized automatically.
 | ||||
|         this.syncObserver = CoreEvents.on(AddonNotesSyncProvider.AUTO_SYNCED, (data) => { | ||||
|  | ||||
| @ -69,19 +69,27 @@ export class AddonPrivateFilesIndexPage implements OnInit, OnDestroy { | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.root = CoreNavigator.getRouteParam('root'); | ||||
|         const contextId = CoreNavigator.getRouteNumberParam('contextid'); | ||||
|         try { | ||||
|             this.root = CoreNavigator.getRouteParam('root'); | ||||
|             const contextId = CoreNavigator.getRouteNumberParam('contextid'); | ||||
| 
 | ||||
|         if (contextId) { | ||||
|             // Loading a certain folder.
 | ||||
|             this.path = { | ||||
|                 contextid: contextId, | ||||
|                 component: CoreNavigator.getRouteParam<string>('component')!, | ||||
|                 filearea: CoreNavigator.getRouteParam<string>('filearea')!, | ||||
|                 itemid: CoreNavigator.getRouteNumberParam('itemid')!, | ||||
|                 filepath: CoreNavigator.getRouteParam<string>('filepath')!, | ||||
|                 filename: CoreNavigator.getRouteParam<string>('filename')!, | ||||
|             }; | ||||
|             if (contextId) { | ||||
|                 // Loading a certain folder.
 | ||||
|                 this.path = { | ||||
|                     contextid: contextId, | ||||
|                     component: CoreNavigator.getRequiredRouteParam<string>('component'), | ||||
|                     filearea: CoreNavigator.getRequiredRouteParam<string>('filearea'), | ||||
|                     itemid: CoreNavigator.getRequiredRouteNumberParam('itemid'), | ||||
|                     filepath: CoreNavigator.getRequiredRouteParam<string>('filepath'), | ||||
|                     filename: CoreNavigator.getRequiredRouteParam<string>('filename'), | ||||
|                 }; | ||||
|             } | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.title = this.path?.filename || Translate.instant('addon.privatefiles.files'); | ||||
|  | ||||
| @ -42,7 +42,15 @@ export class AddonStorageManagerCourseStoragePage implements OnInit { | ||||
|      * View loaded. | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         this.course = CoreNavigator.getRouteParam<CoreEnrolledCourseData>('course')!; | ||||
|         try { | ||||
|             this.course = CoreNavigator.getRequiredRouteParam<CoreEnrolledCourseData>('course'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.sections = await CoreCourse.getSections(this.course.id, false, true); | ||||
|         CoreCourseHelper.addHandlerDataForModules(this.sections, this.course.id); | ||||
|  | ||||
| @ -66,14 +66,8 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy { | ||||
|         this.disableScrollOnParent(); | ||||
| 
 | ||||
|         this.subscriptions = [ | ||||
|             this.contentOutlet.activateEvents.subscribe(() => { | ||||
|                 this.updateClasses(); | ||||
|                 this.outletRouteSubject.next(this.contentOutlet.activatedRoute.snapshot); | ||||
|             }), | ||||
|             this.contentOutlet.deactivateEvents.subscribe(() => { | ||||
|                 this.updateClasses(); | ||||
|                 this.outletRouteSubject.next(null); | ||||
|             }), | ||||
|             this.contentOutlet.activateEvents.subscribe(() => this.updateOutletRoute()), | ||||
|             this.contentOutlet.deactivateEvents.subscribe(() => this.updateOutletRoute()), | ||||
|             CoreScreen.layoutObservable.subscribe(() => this.updateClasses()), | ||||
|         ]; | ||||
| 
 | ||||
| @ -89,6 +83,17 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy { | ||||
|         this.enableScrollOnParent(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Update outlet status. | ||||
|      */ | ||||
|     private updateOutletRoute(): void { | ||||
|         const outletRoute = this.contentOutlet.isActivated ? this.contentOutlet.activatedRoute.snapshot : null; | ||||
| 
 | ||||
|         this.updateClasses(); | ||||
| 
 | ||||
|         this.outletRouteSubject.next(outletRoute); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Update host classes. | ||||
|      */ | ||||
|  | ||||
| @ -110,19 +110,28 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy { | ||||
|      * View loaded. | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         try { | ||||
|             this.contextLevel = CoreNavigator.getRequiredRouteParam<ContextLevel>('contextLevel'); | ||||
|             this.instanceId = CoreNavigator.getRequiredRouteNumberParam('instanceId'); | ||||
|             this.componentName = CoreNavigator.getRequiredRouteParam<string>('componentName'); | ||||
|             this.itemId = CoreNavigator.getRequiredRouteNumberParam('itemId'); | ||||
|             this.area = CoreNavigator.getRouteParam('area') || ''; | ||||
|             this.title = CoreNavigator.getRouteNumberParam('title') || | ||||
|                 Translate.instant('core.comments.comments'); | ||||
|             this.courseId = CoreNavigator.getRouteNumberParam('courseId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         // Is implicit the user can delete if he can add.
 | ||||
|         this.addDeleteCommentsAvailable = await CoreComments.isAddCommentsAvailable(); | ||||
|         this.currentUserId = CoreSites.getCurrentSiteUserId(); | ||||
| 
 | ||||
|         this.commentsLoaded = false; | ||||
|         this.contextLevel = CoreNavigator.getRouteParam<ContextLevel>('contextLevel')!; | ||||
|         this.instanceId = CoreNavigator.getRouteNumberParam('instanceId')!; | ||||
|         this.componentName = CoreNavigator.getRouteParam<string>('componentName')!; | ||||
|         this.itemId = CoreNavigator.getRouteNumberParam('itemId')!; | ||||
|         this.area = CoreNavigator.getRouteParam('area') || ''; | ||||
|         this.title = CoreNavigator.getRouteNumberParam('title') || | ||||
|             Translate.instant('core.comments.comments'); | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId'); | ||||
| 
 | ||||
|         await this.fetchComments(true); | ||||
|     } | ||||
|  | ||||
| @ -14,10 +14,10 @@ | ||||
| 
 | ||||
| import { Component, OnInit } from '@angular/core'; | ||||
| import { CoreNavigator } from '@services/navigator'; | ||||
| import { CoreDomUtils } from '@services/utils/dom'; | ||||
| import { CoreCourseAnyModuleData } from '../services/course'; | ||||
| import { CoreCourseModuleMainResourceComponent } from './main-resource-component'; | ||||
| 
 | ||||
| /** | ||||
| /** | ||||
|  * Template class to easily create CoreCourseModuleMainComponent of resources (or activities without syncing). | ||||
|  */ | ||||
| @ -36,8 +36,17 @@ export class CoreCourseModuleMainActivityPage<ActivityType extends CoreCourseMod | ||||
|      * Component being initialized. | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.module = CoreNavigator.getRouteParam<CoreCourseAnyModuleData>('module')!; | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         try { | ||||
|             this.module = CoreNavigator.getRequiredRouteParam<CoreCourseAnyModuleData>('module'); | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.title = this.module?.name; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -59,7 +59,7 @@ export class CoreCoursesCategoriesPage implements OnInit { | ||||
|      * @return Promise resolved when done. | ||||
|      */ | ||||
|     protected async fetchCategories(): Promise<void> { | ||||
|         try{ | ||||
|         try { | ||||
|             const categories: CoreCategoryData[] = await CoreCourses.getCategories(this.categoryId, true); | ||||
| 
 | ||||
|             this.currentCategory = undefined; | ||||
|  | ||||
| @ -40,14 +40,26 @@ import { CoreNavigator } from '@services/navigator'; | ||||
| }) | ||||
| export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { | ||||
| 
 | ||||
|     grades: CoreGradesCourseManager; | ||||
|     grades!: CoreGradesCourseManager; | ||||
|     splitViewMode?: CoreSplitViewMode; | ||||
| 
 | ||||
|     @ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent; | ||||
| 
 | ||||
|     constructor(protected route: ActivatedRoute) { | ||||
|         const courseId = CoreNavigator.getRouteNumberParam('courseId', { route })!; | ||||
|         const userId = CoreNavigator.getRouteNumberParam('userId', { route }) ?? CoreSites.getCurrentSiteUserId(); | ||||
|         let courseId: number; | ||||
|         let userId: number; | ||||
| 
 | ||||
|         try { | ||||
|             courseId = CoreNavigator.getRequiredRouteNumberParam('courseId', { route }); | ||||
|             userId = CoreNavigator.getRouteNumberParam('userId', { route }) ?? CoreSites.getCurrentSiteUserId(); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const useSplitView = route.snapshot.data.useSplitView ?? true; | ||||
|         const outsideGradesTab = route.snapshot.data.outsideGradesTab ?? false; | ||||
| 
 | ||||
|  | ||||
| @ -31,16 +31,24 @@ import { CoreNavigator } from '@services/navigator'; | ||||
| }) | ||||
| export class CoreGradesGradePage implements OnInit { | ||||
| 
 | ||||
|     courseId: number; | ||||
|     userId: number; | ||||
|     gradeId: number; | ||||
|     courseId!: number; | ||||
|     userId!: number; | ||||
|     gradeId!: number; | ||||
|     grade?: CoreGradesFormattedRow | null; | ||||
|     gradeLoaded = false; | ||||
| 
 | ||||
|     constructor() { | ||||
|         this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         this.gradeId = CoreNavigator.getRouteNumberParam('gradeId')!; | ||||
|         this.userId = CoreNavigator.getRouteNumberParam('userId') ?? CoreSites.getCurrentSiteUserId(); | ||||
|         try { | ||||
|             this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|             this.gradeId = CoreNavigator.getRequiredRouteNumberParam('gradeId'); | ||||
|             this.userId = CoreNavigator.getRouteNumberParam('userId') ?? CoreSites.getCurrentSiteUserId(); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -33,7 +33,7 @@ import { CoreUtils } from '@services/utils/utils'; | ||||
| }) | ||||
| export class CoreUserParticipantsPage implements OnInit, AfterViewInit, OnDestroy { | ||||
| 
 | ||||
|     participants: CoreUserParticipantsManager; | ||||
|     participants!: CoreUserParticipantsManager; | ||||
|     searchQuery: string | null = null; | ||||
|     searchInProgress = false; | ||||
|     searchEnabled = false; | ||||
| @ -43,7 +43,17 @@ export class CoreUserParticipantsPage implements OnInit, AfterViewInit, OnDestro | ||||
|     @ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent; | ||||
| 
 | ||||
|     constructor() { | ||||
|         const courseId = CoreNavigator.getRouteNumberParam('courseId')!; | ||||
|         let courseId: number; | ||||
| 
 | ||||
|         try { | ||||
|             courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); | ||||
|         } catch (error) { | ||||
|             CoreDomUtils.showErrorModal(error); | ||||
| 
 | ||||
|             CoreNavigator.back(); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         this.participants = new CoreUserParticipantsManager(CoreUserParticipantsPage, courseId); | ||||
|     } | ||||
|  | ||||
| @ -30,6 +30,7 @@ import { makeSingleton, NavController, Router } from '@singletons'; | ||||
| import { CoreScreen } from './screen'; | ||||
| import { CoreApp } from './app'; | ||||
| import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; | ||||
| import { CoreError } from '@classes/errors/error'; | ||||
| 
 | ||||
| const DEFAULT_MAIN_MENU_TAB = CoreMainMenuHomeHandlerService.PAGE_NAME; | ||||
| 
 | ||||
| @ -269,7 +270,7 @@ export class CoreNavigatorService { | ||||
| 
 | ||||
|         const value = route.snapshot.queryParams[name] ?? route.snapshot.params[name]; | ||||
| 
 | ||||
|         if (typeof value != 'undefined') { | ||||
|         if (value !== undefined) { | ||||
|             return value; | ||||
|         } | ||||
| 
 | ||||
| @ -300,7 +301,7 @@ export class CoreNavigatorService { | ||||
|             value = routeOptions.params[name]; | ||||
|         } | ||||
| 
 | ||||
|         if (typeof value == 'undefined') { | ||||
|         if (value === undefined) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
| @ -345,7 +346,7 @@ export class CoreNavigatorService { | ||||
|     getRouteBooleanParam(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): boolean | undefined { | ||||
|         const value = this.getRouteParam<string>(name, routeOptions); | ||||
| 
 | ||||
|         if (typeof value == 'undefined') { | ||||
|         if (value === undefined) { | ||||
|             return value; | ||||
|         } | ||||
| 
 | ||||
| @ -360,6 +361,67 @@ export class CoreNavigatorService { | ||||
|         return Boolean(value); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get a parameter for the current route. | ||||
|      * Please notice that objects can only be retrieved once. You must call this function only once per page and parameter, | ||||
|      * unless there's a new navigation to the page. | ||||
|      * | ||||
|      * This function will fail if parameter is not found. | ||||
|      * | ||||
|      * @param name Name of the parameter. | ||||
|      * @param routeOptions Optional routeOptions to get the params or route value from. If missing, it will autodetect. | ||||
|      * @return Value of the parameter, undefined if not found. | ||||
|      */ | ||||
|     getRequiredRouteParam<T = unknown>(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): T { | ||||
|         const value = this.getRouteParam<T>(name, routeOptions); | ||||
| 
 | ||||
|         if (value === undefined) { | ||||
|             throw new CoreError(`Required param '${name}' not found.`); | ||||
|         } | ||||
| 
 | ||||
|         return value; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get a number route param. | ||||
|      * Angular router automatically converts numbers to string, this function automatically converts it back to number. | ||||
|      * | ||||
|      * This function will fail if parameter is not found. | ||||
|      * | ||||
|      * @param name Name of the parameter. | ||||
|      * @param routeOptions Optional routeOptions to get the params or route value from. If missing, it will autodetect. | ||||
|      * @return Value of the parameter, undefined if not found. | ||||
|      */ | ||||
|     getRequiredRouteNumberParam(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): number { | ||||
|         const value = this.getRouteNumberParam(name, routeOptions); | ||||
| 
 | ||||
|         if (value === undefined) { | ||||
|             throw new CoreError(`Required number param '${name}' not found.`); | ||||
|         } | ||||
| 
 | ||||
|         return value; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get a boolean route param. | ||||
|      * Angular router automatically converts booleans to string, this function automatically converts it back to boolean. | ||||
|      * | ||||
|      * This function will fail if parameter is not found. | ||||
|      * | ||||
|      * @param name Name of the parameter. | ||||
|      * @param routeOptions Optional routeOptions to get the params or route value from. If missing, it will autodetect. | ||||
|      * @return Value of the parameter, undefined if not found. | ||||
|      */ | ||||
|     getRequiredRouteBooleanParam(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): boolean { | ||||
|         const value = this.getRouteBooleanParam(name, routeOptions); | ||||
| 
 | ||||
|         if (value === undefined) { | ||||
|             throw new CoreError(`Required boolean param '${name}' not found.`); | ||||
|         } | ||||
| 
 | ||||
|         return value; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Navigate back. | ||||
|      * | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user