MOBILE-3833 navigator: Add required route params functions

main
Pau Ferrer Ocaña 2021-09-09 16:38:38 +02:00
parent 0d3123d2af
commit 34f9c3ab57
46 changed files with 673 additions and 228 deletions

View File

@ -147,7 +147,16 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
* View loaded. * View loaded.
*/ */
ngOnInit(): void { 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.syncIcon = CoreConstants.ICON_LOADING;
this.fetchEvent(); this.fetchEvent();

View File

@ -60,12 +60,20 @@ export class AddonCompetencyCompetencyPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.competencyId = CoreNavigator.getRouteNumberParam('competencyId')!; try {
this.competencyId = CoreNavigator.getRequiredRouteNumberParam('competencyId');
this.planId = CoreNavigator.getRouteNumberParam('planId'); this.planId = CoreNavigator.getRouteNumberParam('planId');
if (!this.planId) { if (!this.planId) {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.userId = CoreNavigator.getRouteNumberParam('userId'); this.userId = CoreNavigator.getRouteNumberParam('userId');
} }
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
try { try {
await this.fetchCompetency(); await this.fetchCompetency();

View File

@ -40,9 +40,17 @@ export class AddonCompetencyCompetencySummaryPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.competencyId = CoreNavigator.getRouteNumberParam('competencyId')!; try {
this.competencyId = CoreNavigator.getRequiredRouteNumberParam('competencyId');
this.contextLevel = CoreNavigator.getRouteParam<ContextLevel>('contextLevel'); this.contextLevel = CoreNavigator.getRouteParam<ContextLevel>('contextLevel');
this.contextInstanceId = CoreNavigator.getRouteNumberParam('contextInstanceId'); this.contextInstanceId = CoreNavigator.getRouteNumberParam('contextInstanceId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
try { try {
await this.fetchCompetency(); await this.fetchCompetency();

View File

@ -42,8 +42,16 @@ export class AddonCompetencyCourseCompetenciesPage implements OnInit {
* View loaded. * View loaded.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.userId = CoreNavigator.getRouteNumberParam('userId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.userId = CoreNavigator.getRequiredRouteNumberParam('userId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.fetchCourseCompetencies().finally(() => { this.fetchCourseCompetencies().finally(() => {
this.competenciesLoaded = true; this.competenciesLoaded = true;

View File

@ -39,7 +39,15 @@ export class AddonCompetencyPlanPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
ngOnInit(): void { 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.fetchLearningPlan().finally(() => {
this.loaded = true; this.loaded = true;

View File

@ -44,11 +44,15 @@ export class AddonCourseCompletionReportPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
ngOnInit(): void { ngOnInit(): void {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId(); this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId();
} catch (error) {
CoreDomUtils.showErrorModal(error);
if (!this.userId) { CoreNavigator.back();
this.userId = CoreSites.getCurrentSiteUserId();
return;
} }
this.fetchCompletion().finally(() => { this.fetchCompletion().finally(() => {

View File

@ -78,9 +78,17 @@ export class AddonModAssignEditPage implements OnInit, OnDestroy, CanLeave {
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.moduleId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.moduleId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.isBlind = !!CoreNavigator.getRouteNumberParam('blindId'); this.isBlind = !!CoreNavigator.getRouteNumberParam('blindId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.fetchAssignment().finally(() => { this.fetchAssignment().finally(() => {
this.loaded = true; this.loaded = true;

View File

@ -120,10 +120,18 @@ export class AddonModAssignSubmissionListPage implements AfterViewInit, OnDestro
* Component being initialized. * Component being initialized.
*/ */
ngAfterViewInit(): void { ngAfterViewInit(): void {
this.moduleId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.moduleId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.groupId = CoreNavigator.getRouteNumberParam('groupId') || 0; this.groupId = CoreNavigator.getRouteNumberParam('groupId') || 0;
this.selectedStatus = CoreNavigator.getRouteParam('status'); this.selectedStatus = CoreNavigator.getRouteParam('status');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
if (this.selectedStatus) { if (this.selectedStatus) {
if (this.selectedStatus == AddonModAssignProvider.NEED_GRADING) { if (this.selectedStatus == AddonModAssignProvider.NEED_GRADING) {

View File

@ -55,10 +55,18 @@ export class AddonModAssignSubmissionReviewPage implements OnInit, CanLeave {
*/ */
ngOnInit(): void { ngOnInit(): void {
this.route.queryParams.subscribe((params) => { this.route.queryParams.subscribe((params) => {
this.moduleId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.moduleId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.submitId = CoreNavigator.getRouteNumberParam('submitId') || 0; this.submitId = CoreNavigator.getRouteNumberParam('submitId') || 0;
this.blindId = CoreNavigator.getRouteNumberParam('blindId', { params }); this.blindId = CoreNavigator.getRouteNumberParam('blindId', { params });
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.fetchSubmission().finally(() => { this.fetchSubmission().finally(() => {
this.loaded = true; this.loaded = true;

View File

@ -78,12 +78,12 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.chatId = CoreNavigator.getRouteNumberParam('chatId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.chatId = CoreNavigator.getRequiredRouteNumberParam('chatId');
this.title = CoreNavigator.getRouteParam('title') || ''; this.title = CoreNavigator.getRouteParam('title') || '';
try {
await this.loginUser(); await this.loginUser();
await this.fetchMessages(); await this.fetchMessages();

View File

@ -47,12 +47,20 @@ export class AddonModChatSessionMessagesPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
ngOnInit(): void { ngOnInit(): void {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.sessionStart = CoreNavigator.getRouteNumberParam('sessionStart')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.sessionEnd = CoreNavigator.getRouteNumberParam('sessionEnd')!; this.sessionStart = CoreNavigator.getRequiredRouteNumberParam('sessionStart');
this.chatId = CoreNavigator.getRouteNumberParam('chatId')!; this.sessionEnd = CoreNavigator.getRequiredRouteNumberParam('sessionEnd');
this.chatId = CoreNavigator.getRequiredRouteNumberParam('chatId');
this.groupId = CoreNavigator.getRouteNumberParam('groupId') || 0; this.groupId = CoreNavigator.getRouteNumberParam('groupId') || 0;
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.currentUserId = CoreSites.getCurrentSiteUserId(); this.currentUserId = CoreSites.getCurrentSiteUserId();

View File

@ -53,10 +53,18 @@ export class AddonModChatSessionsPage implements AfterViewInit, OnDestroy {
* @inheritdoc * @inheritdoc
*/ */
async ngAfterViewInit(): Promise<void> { async ngAfterViewInit(): Promise<void> {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.chatId = CoreNavigator.getRouteNumberParam('chatId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.chatId = CoreNavigator.getRequiredRouteNumberParam('chatId');
this.sessions.setChatId(this.chatId); this.sessions.setChatId(this.chatId);
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
await this.fetchSessions(); await this.fetchSessions();

View File

@ -53,7 +53,7 @@ export class AddonModDataFieldPluginComponent implements OnInit, OnChanges {
return; return;
} }
try{ try {
// Check if the plugin has defined its own component to render itself. // Check if the plugin has defined its own component to render itself.
this.fieldComponent = await AddonModDataFieldsDelegate.getComponentForField(this.field); this.fieldComponent = await AddonModDataFieldsDelegate.getComponentForField(this.field);

View File

@ -96,10 +96,18 @@ export class AddonModDataEditPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
ngOnInit(): void { ngOnInit(): void {
this.module = CoreNavigator.getRouteParam<CoreCourseModule>('module')!; try {
this.module = CoreNavigator.getRequiredRouteParam<CoreCourseModule>('module');
this.entryId = CoreNavigator.getRouteNumberParam('entryId') || undefined; this.entryId = CoreNavigator.getRouteNumberParam('entryId') || undefined;
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; 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. // 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; this.isEditing = typeof this.entryId != 'undefined' && this.entryId > 0;

View File

@ -132,11 +132,20 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.module = CoreNavigator.getRouteParam<CoreCourseModule>('module')!; try {
this.module = CoreNavigator.getRequiredRouteParam<CoreCourseModule>('module');
this.entryId = CoreNavigator.getRouteNumberParam('entryId') || undefined; this.entryId = CoreNavigator.getRouteNumberParam('entryId') || undefined;
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0;
this.offset = CoreNavigator.getRouteNumberParam('offset'); this.offset = CoreNavigator.getRouteNumberParam('offset');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.title = this.module.name; this.title = this.module.name;
this.commentsEnabled = !CoreComments.areCommentsDisabledInSite(); this.commentsEnabled = !CoreComments.areCommentsDisabledInSite();

View File

@ -49,9 +49,17 @@ export class AddonModFeedbackAttemptPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
ngOnInit(): void { ngOnInit(): void {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.attemptId = CoreNavigator.getRouteNumberParam('attemptId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.attemptId = CoreNavigator.getRequiredRouteNumberParam('attemptId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.fetchData(); this.fetchData();
} }

View File

@ -92,12 +92,20 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.currentPage = CoreNavigator.getRouteNumberParam('page'); this.currentPage = CoreNavigator.getRouteNumberParam('page');
this.title = CoreNavigator.getRouteParam('title'); this.title = CoreNavigator.getRouteParam('title');
this.preview = !!CoreNavigator.getRouteBooleanParam('preview'); this.preview = !!CoreNavigator.getRouteBooleanParam('preview');
this.fromIndex = !!CoreNavigator.getRouteBooleanParam('fromIndex'); this.fromIndex = !!CoreNavigator.getRouteBooleanParam('fromIndex');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
await this.fetchData(); await this.fetchData();

View File

@ -47,9 +47,17 @@ export class AddonModFeedbackNonRespondentsPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
ngOnInit(): void { ngOnInit(): void {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0;
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.fetchData(); this.fetchData();
} }

View File

@ -63,9 +63,17 @@ export class AddonModFeedbackRespondentsPage implements AfterViewInit {
* @inheritdoc * @inheritdoc
*/ */
async ngAfterViewInit(): Promise<void> { async ngAfterViewInit(): Promise<void> {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0; this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0;
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
await this.fetchData(); await this.fetchData();

View File

@ -65,7 +65,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
discussionId!: number; discussionId!: number;
forum: Partial<AddonModForumData> = {}; forum: Partial<AddonModForumData> = {};
accessInfo: AddonModForumAccessInformation = {}; accessInfo: AddonModForumAccessInformation = {};
discussion!: AddonModForumDiscussion; discussion?: AddonModForumDiscussion;
startingPost?: Post; startingPost?: Post;
posts!: Post[]; posts!: Post[];
discussionLoaded = false; discussionLoaded = false;
@ -100,8 +100,8 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
leavingPage = false; leavingPage = false;
protected forumId!: number; protected forumId!: number;
protected postId!: number; protected postId?: number;
protected parent!: number; protected parent?: number;
protected onlineObserver?: Subscription; protected onlineObserver?: Subscription;
protected syncObserver?: CoreEventObserver; protected syncObserver?: CoreEventObserver;
protected syncManualObserver?: CoreEventObserver; protected syncManualObserver?: CoreEventObserver;
@ -122,16 +122,25 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
} }
ngOnInit(): void { ngOnInit(): void {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.forumId = CoreNavigator.getRouteNumberParam('forumId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.discussion = CoreNavigator.getRouteParam<AddonModForumDiscussion>('discussion')!; this.forumId = CoreNavigator.getRequiredRouteNumberParam('forumId');
this.discussion = CoreNavigator.getRouteParam<AddonModForumDiscussion>('discussion');
this.discussionId = this.discussion this.discussionId = this.discussion
? this.discussion.discussion ? this.discussion.discussion
: CoreNavigator.getRouteNumberParam('discussionId')!; : CoreNavigator.getRequiredRouteNumberParam('discussionId');
this.trackPosts = CoreNavigator.getRouteBooleanParam('trackPosts')!; this.trackPosts = CoreNavigator.getRouteBooleanParam('trackPosts') || false;
this.postId = CoreNavigator.getRouteNumberParam('postId')!; this.postId = CoreNavigator.getRouteNumberParam('postId');
this.parent = CoreNavigator.getRouteNumberParam('parent')!; this.parent = CoreNavigator.getRouteNumberParam('parent');
} catch (error) {
CoreDomUtils.showErrorModal(error);
this.goBack();
return;
}
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreApp.isOnline();
this.onlineObserver = Network.onChange().subscribe(() => { this.onlineObserver = Network.onChange().subscribe(() => {
@ -148,11 +157,9 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
* View loaded. * View loaded.
*/ */
async ngAfterViewInit(): Promise<void> { async ngAfterViewInit(): Promise<void> {
if (this.parent) { this.sort = this.parent
this.sort = 'nested'; // Force nested order. ? 'nested' // Force nested order.
} else { : await this.getUserSort();
this.sort = await this.getUserSort();
}
await this.fetchPosts(true, false, true); 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); 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. // Refresh data if this discussion is synchronized automatically.
this.syncObserver = CoreEvents.on(AddonModForumSyncProvider.AUTO_SYNCED, data => { this.syncObserver = CoreEvents.on(AddonModForumSyncProvider.AUTO_SYNCED, data => {
if (data.forumId == this.forumId && this.discussionId == data.discussionId if (data.forumId == this.forumId && this.discussionId == data.discussionId
@ -204,7 +221,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
}, CoreSites.getCurrentSiteId()); }, CoreSites.getCurrentSiteId());
// Invalidate discussion list if it was not read. // Invalidate discussion list if it was not read.
if (this.discussion.numunread > 0) { if (discussion.numunread > 0) {
AddonModForum.invalidateDiscussionsList(this.forumId); 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) { if ((this.forumId && this.forumId === data.forumId) || data.cmId === this.cmId) {
AddonModForum.invalidateDiscussionsList(this.forumId).finally(() => { AddonModForum.invalidateDiscussionsList(this.forumId).finally(() => {
if (typeof data.locked != 'undefined') { if (typeof data.locked != 'undefined') {
this.discussion.locked = data.locked; discussion.locked = data.locked;
} }
if (typeof data.pinned != 'undefined') { if (typeof data.pinned != 'undefined') {
this.discussion.pinned = data.pinned; discussion.pinned = data.pinned;
} }
if (typeof data.starred != 'undefined') { if (typeof data.starred != 'undefined') {
this.discussion.starred = data.starred; discussion.starred = data.starred;
} }
if (typeof data.deleted != 'undefined' && data.deleted) { if (typeof data.deleted != 'undefined' && data.deleted) {
if (!data.post?.parentid) { if (!data.post?.parentid) {
if (this.splitView?.outletActivated) { this.goBack();
CoreNavigator.navigate('../');
} else {
CoreNavigator.back();
}
} else { } else {
this.discussionLoaded = false; this.discussionLoaded = false;
this.refreshPosts(); this.refreshPosts();
@ -272,6 +285,17 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
return true; 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. * 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; this.syncIcon = CoreConstants.ICON_SYNC;
if (forceMarkAsRead || (hasUnreadPosts && this.trackPosts)) { 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(() => { AddonModForum.logDiscussionView(this.discussionId, this.forumId || -1, this.forum.name).catch(() => {
// Ignore errors. // Ignore errors.
}).finally(() => { }).finally(() => {
@ -543,14 +567,8 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
return; return;
} }
try { this.discussion = await AddonModForumHelper.getDiscussionById(forumId, cmId, discussionId);
const discussion = await AddonModForumHelper.getDiscussionById(forumId, cmId, discussionId);
this.discussion = discussion;
this.discussionId = this.discussion.discussion; this.discussionId = this.discussion.discussion;
} catch (error) {
// Ignore errors.
}
} }
/** /**
@ -630,7 +648,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
* @param showErrors Whether to show errors in a modal. * @param showErrors Whether to show errors in a modal.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
refreshPosts(sync?: boolean, showErrors?: boolean): Promise<void> { async refreshPosts(sync?: boolean, showErrors?: boolean): Promise<void> {
this.content.scrollToTop(); this.content.scrollToTop();
this.refreshIcon = CoreConstants.ICON_LOADING; this.refreshIcon = CoreConstants.ICON_LOADING;
this.syncIcon = CoreConstants.ICON_LOADING; this.syncIcon = CoreConstants.ICON_LOADING;
@ -642,9 +660,9 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
AddonModForum.invalidateCanAddDiscussion(this.forumId), AddonModForum.invalidateCanAddDiscussion(this.forumId),
]; ];
return CoreUtils.allPromises(promises).catch(() => { await CoreUtils.ignoreErrors(CoreUtils.allPromises(promises));
// Ignore errors.
}).then(() => this.fetchPosts(sync, showErrors)); 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. * @param locked True to lock the discussion, false to unlock.
*/ */
async setLockState(locked: boolean): Promise<void> { async setLockState(locked: boolean): Promise<void> {
if (!this.discussion) {
return;
}
const modal = await CoreDomUtils.showModalLoading('core.sending', true); const modal = await CoreDomUtils.showModalLoading('core.sending', true);
try { try {
@ -696,6 +718,10 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
* @param pinned True to pin the discussion, false to unpin it. * @param pinned True to pin the discussion, false to unpin it.
*/ */
async setPinState(pinned: boolean): Promise<void> { async setPinState(pinned: boolean): Promise<void> {
if (!this.discussion) {
return;
}
const modal = await CoreDomUtils.showModalLoading('core.sending', true); const modal = await CoreDomUtils.showModalLoading('core.sending', true);
try { try {
@ -725,6 +751,10 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
* @param starred True to star the discussion, false to unstar it. * @param starred True to star the discussion, false to unstar it.
*/ */
async toggleFavouriteState(starred: boolean): Promise<void> { async toggleFavouriteState(starred: boolean): Promise<void> {
if (!this.discussion) {
return;
}
const modal = await CoreDomUtils.showModalLoading('core.sending', true); const modal = await CoreDomUtils.showModalLoading('core.sending', true);
try { try {

View File

@ -103,10 +103,18 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.forumId = CoreNavigator.getRouteNumberParam('forumId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.timeCreated = CoreNavigator.getRouteNumberParam('timeCreated')!; this.forumId = CoreNavigator.getRequiredRouteNumberParam('forumId');
this.timeCreated = CoreNavigator.getRequiredRouteNumberParam('timeCreated');
} catch (error) {
CoreDomUtils.showErrorModal(error);
this.goBack();
return;
}
this.fetchDiscussionData().finally(() => { this.fetchDiscussionData().finally(() => {
this.groupsLoaded = true; this.groupsLoaded = true;
@ -595,6 +603,17 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea
delete this.syncObserver; delete this.syncObserver;
} }
/**
* Helper function to go back.
*/
protected goBack(): void {
if (this.splitView?.outletActivated) {
CoreNavigator.navigate('../../');
} else {
CoreNavigator.back();
}
}
/** /**
* Page destroyed. * Page destroyed.
*/ */

View File

@ -73,7 +73,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
}; };
protected timecreated!: number; protected timecreated!: number;
protected concept?: string; protected concept = '';
protected syncId?: string; protected syncId?: string;
protected syncObserver?: CoreEventObserver; protected syncObserver?: CoreEventObserver;
protected isDestroyed = false; protected isDestroyed = false;
@ -86,11 +86,19 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.timecreated = CoreNavigator.getRouteNumberParam('timecreated')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.concept = CoreNavigator.getRouteParam<string>('concept')!; this.timecreated = CoreNavigator.getRequiredRouteNumberParam('timecreated');
this.concept = CoreNavigator.getRouteParam<string>('concept') || '';
this.editorExtraParams.timecreated = this.timecreated; this.editorExtraParams.timecreated = this.timecreated;
} catch (error) {
CoreDomUtils.showErrorModal(error);
this.goBack();
return;
}
this.fetchData(); this.fetchData();
} }
@ -116,7 +124,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
} catch (error) { } catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingglossary', true); 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. * @return Promise resolved when done.
*/ */
protected async loadOfflineData(): Promise<void> { 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.concept = entry.concept || '';
this.entry.definition = entry.definition || ''; 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();
}
}
} }

View File

@ -57,10 +57,18 @@ export class AddonModGlossaryEntryPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.entryId = CoreNavigator.getRouteNumberParam('entryId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.entryId = CoreNavigator.getRequiredRouteNumberParam('entryId');
this.tagsEnabled = CoreTag.areTagsAvailableInSite(); this.tagsEnabled = CoreTag.areTagsAvailableInSite();
this.commentsEnabled = !CoreComments.areCommentsDisabledInSite(); this.commentsEnabled = !CoreComments.areCommentsDisabledInSite();
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
try { try {
await this.fetchEntry(); await this.fetchEntry();

View File

@ -50,9 +50,17 @@ export class AddonModH5PActivityAttemptResultsPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.attemptId = CoreNavigator.getRouteNumberParam('attemptId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.attemptId = CoreNavigator.getRequiredRouteNumberParam('attemptId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
try { try {
await this.fetchData(); await this.fetchData();

View File

@ -51,9 +51,18 @@ export class AddonModH5PActivityUserAttemptsPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId(); this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId();
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.isCurrentUser = this.userId == CoreSites.getCurrentSiteUserId(); this.isCurrentUser = this.userId == CoreSites.getCurrentSiteUserId();
try { try {

View File

@ -49,8 +49,16 @@ export class AddonModH5PActivityUsersAttemptsPage implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
try { try {
await this.fetchData(); await this.fetchData();

View File

@ -119,12 +119,20 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
* Component being initialized. * Component being initialized.
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.password = CoreNavigator.getRouteParam('password'); this.password = CoreNavigator.getRouteParam('password');
this.review = !!CoreNavigator.getRouteBooleanParam('review'); this.review = !!CoreNavigator.getRouteBooleanParam('review');
this.currentPage = CoreNavigator.getRouteNumberParam('pageId'); this.currentPage = CoreNavigator.getRouteNumberParam('pageId');
this.retakeToReview = CoreNavigator.getRouteNumberParam('retake'); this.retakeToReview = CoreNavigator.getRouteNumberParam('retake');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
try { try {
// Fetch the Lesson data. // Fetch the Lesson data.

View File

@ -64,10 +64,18 @@ export class AddonModLessonUserRetakePage implements OnInit {
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId(); this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId();
this.retakeNumber = CoreNavigator.getRouteNumberParam('retake'); this.retakeNumber = CoreNavigator.getRouteNumberParam('retake');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
// Fetch the data. // Fetch the data.
this.fetchData().finally(() => { this.fetchData().finally(() => {

View File

@ -52,9 +52,17 @@ export class AddonModQuizAttemptPage implements OnInit {
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.attemptId = CoreNavigator.getRouteNumberParam('attemptId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.attemptId = CoreNavigator.getRequiredRouteNumberParam('attemptId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.fetchQuizData().finally(() => { this.fetchQuizData().finally(() => {
this.loaded = true; this.loaded = true;

View File

@ -106,9 +106,17 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave {
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.moduleUrl = CoreNavigator.getRouteParam('moduleUrl'); this.moduleUrl = CoreNavigator.getRouteParam('moduleUrl');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
// Create the auto save instance. // Create the auto save instance.
this.autoSave = new AddonModQuizAutoSave( this.autoSave = new AddonModQuizAutoSave(

View File

@ -83,11 +83,19 @@ export class AddonModQuizReviewPage implements OnInit {
* Component being initialized. * Component being initialized.
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.attemptId = CoreNavigator.getRouteNumberParam('attemptId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.attemptId = CoreNavigator.getRequiredRouteNumberParam('attemptId');
this.currentPage = CoreNavigator.getRouteNumberParam('page') || -1; this.currentPage = CoreNavigator.getRouteNumberParam('page') || -1;
this.showAll = this.currentPage == -1; this.showAll = this.currentPage == -1;
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
try { try {
await this.fetchData(); await this.fetchData();

View File

@ -88,14 +88,22 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.mode = CoreNavigator.getRouteParam('mode') || AddonModScormProvider.MODENORMAL; this.mode = CoreNavigator.getRouteParam('mode') || AddonModScormProvider.MODENORMAL;
this.moduleUrl = CoreNavigator.getRouteParam('moduleUrl') || ''; this.moduleUrl = CoreNavigator.getRouteParam('moduleUrl') || '';
this.newAttempt = !!CoreNavigator.getRouteBooleanParam('newAttempt'); this.newAttempt = !!CoreNavigator.getRouteBooleanParam('newAttempt');
this.organizationId = CoreNavigator.getRouteParam('organizationId'); this.organizationId = CoreNavigator.getRouteParam('organizationId');
this.initialScoId = CoreNavigator.getRouteNumberParam('scoId'); this.initialScoId = CoreNavigator.getRouteNumberParam('scoId');
this.siteId = CoreSites.getCurrentSiteId(); this.siteId = CoreSites.getCurrentSiteId();
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
try { try {
// Fetch the SCORM data. // Fetch the SCORM data.

View File

@ -117,10 +117,18 @@ export class AddonModWorkshopAssessmentPage implements OnInit, OnDestroy, CanLea
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.assessment = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionAssessmentWithFormData>('assessment')!; try {
this.submission = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionData>('submission')!; this.assessment = CoreNavigator.getRequiredRouteParam<AddonModWorkshopSubmissionAssessmentWithFormData>('assessment');
this.profile = CoreNavigator.getRouteParam<CoreUserProfile>('profile')!; this.submission = CoreNavigator.getRequiredRouteParam<AddonModWorkshopSubmissionData>('submission');
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; 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.assessmentId = this.assessment.id;
this.workshopId = this.submission.workshopid; this.workshopId = this.submission.workshopid;

View File

@ -99,10 +99,18 @@ export class AddonModWorkshopEditSubmissionPage implements OnInit, OnDestroy, Ca
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.module = CoreNavigator.getRouteParam<CoreCourseModule>('module')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.module = CoreNavigator.getRequiredRouteParam<CoreCourseModule>('module');
this.access = CoreNavigator.getRouteParam<AddonModWorkshopGetWorkshopAccessInformationWSResponse>('access')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.access = CoreNavigator.getRequiredRouteParam<AddonModWorkshopGetWorkshopAccessInformationWSResponse>('access');
this.submissionId = CoreNavigator.getRouteNumberParam('submissionId') || 0; this.submissionId = CoreNavigator.getRouteNumberParam('submissionId') || 0;
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
if (this.submissionId > 0) { if (this.submissionId > 0) {
this.editorExtraParams.id = this.submissionId; this.editorExtraParams.id = this.submissionId;

View File

@ -130,15 +130,22 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy, CanLea
* Component being initialized. * Component being initialized.
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
try {
this.submissionId = CoreNavigator.getRouteNumberParam('submissionId')!; this.submissionId = CoreNavigator.getRequiredRouteNumberParam('submissionId');
this.module = CoreNavigator.getRouteParam<CoreCourseModule>('module')!; this.module = CoreNavigator.getRequiredRouteParam<CoreCourseModule>('module');
this.workshop = CoreNavigator.getRouteParam<AddonModWorkshopData>('workshop')!; this.workshop = CoreNavigator.getRequiredRouteParam<AddonModWorkshopData>('workshop');
this.access = CoreNavigator.getRouteParam<AddonModWorkshopGetWorkshopAccessInformationWSResponse>('access')!; this.access = CoreNavigator.getRequiredRouteParam<AddonModWorkshopGetWorkshopAccessInformationWSResponse>('access');
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.profile = CoreNavigator.getRouteParam<CoreUserProfile>('profile'); this.profile = CoreNavigator.getRouteParam<CoreUserProfile>('profile');
this.submissionInfo = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionDataWithOfflineData>('submission')!; this.submissionInfo = CoreNavigator.getRequiredRouteParam<AddonModWorkshopSubmissionDataWithOfflineData>('submission');
this.assessment = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionAssessmentWithFormData>('assessment'); this.assessment = CoreNavigator.getRouteParam<AddonModWorkshopSubmissionAssessmentWithFormData>('assessment');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.title = this.module.name; this.title = this.module.name;
this.workshopId = this.module.instance || this.workshop.id; this.workshopId = this.module.instance || this.workshop.id;

View File

@ -40,7 +40,7 @@ export class AddonNotesListPage implements OnInit, OnDestroy {
@ViewChild(IonContent) content?: IonContent; @ViewChild(IonContent) content?: IonContent;
courseId: number; courseId!: number;
userId?: number; userId?: number;
type: AddonNotesPublishState = 'course'; type: AddonNotesPublishState = 'course';
refreshIcon = CoreConstants.ICON_LOADING; refreshIcon = CoreConstants.ICON_LOADING;
@ -51,13 +51,21 @@ export class AddonNotesListPage implements OnInit, OnDestroy {
user?: CoreUserProfile; user?: CoreUserProfile;
showDelete = false; showDelete = false;
canDeleteNotes = false; canDeleteNotes = false;
currentUserId: number; currentUserId!: number;
protected syncObserver: CoreEventObserver; protected syncObserver!: CoreEventObserver;
constructor() { constructor() {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.userId = CoreNavigator.getRouteNumberParam('userId'); this.userId = CoreNavigator.getRouteNumberParam('userId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
// Refresh data if notes are synchronized automatically. // Refresh data if notes are synchronized automatically.
this.syncObserver = CoreEvents.on(AddonNotesSyncProvider.AUTO_SYNCED, (data) => { this.syncObserver = CoreEvents.on(AddonNotesSyncProvider.AUTO_SYNCED, (data) => {

View File

@ -69,6 +69,7 @@ export class AddonPrivateFilesIndexPage implements OnInit, OnDestroy {
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
try {
this.root = CoreNavigator.getRouteParam('root'); this.root = CoreNavigator.getRouteParam('root');
const contextId = CoreNavigator.getRouteNumberParam('contextid'); const contextId = CoreNavigator.getRouteNumberParam('contextid');
@ -76,13 +77,20 @@ export class AddonPrivateFilesIndexPage implements OnInit, OnDestroy {
// Loading a certain folder. // Loading a certain folder.
this.path = { this.path = {
contextid: contextId, contextid: contextId,
component: CoreNavigator.getRouteParam<string>('component')!, component: CoreNavigator.getRequiredRouteParam<string>('component'),
filearea: CoreNavigator.getRouteParam<string>('filearea')!, filearea: CoreNavigator.getRequiredRouteParam<string>('filearea'),
itemid: CoreNavigator.getRouteNumberParam('itemid')!, itemid: CoreNavigator.getRequiredRouteNumberParam('itemid'),
filepath: CoreNavigator.getRouteParam<string>('filepath')!, filepath: CoreNavigator.getRequiredRouteParam<string>('filepath'),
filename: CoreNavigator.getRouteParam<string>('filename')!, filename: CoreNavigator.getRequiredRouteParam<string>('filename'),
}; };
} }
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.title = this.path?.filename || Translate.instant('addon.privatefiles.files'); this.title = this.path?.filename || Translate.instant('addon.privatefiles.files');

View File

@ -42,7 +42,15 @@ export class AddonStorageManagerCourseStoragePage implements OnInit {
* View loaded. * View loaded.
*/ */
async ngOnInit(): Promise<void> { 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); this.sections = await CoreCourse.getSections(this.course.id, false, true);
CoreCourseHelper.addHandlerDataForModules(this.sections, this.course.id); CoreCourseHelper.addHandlerDataForModules(this.sections, this.course.id);

View File

@ -66,14 +66,8 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy {
this.disableScrollOnParent(); this.disableScrollOnParent();
this.subscriptions = [ this.subscriptions = [
this.contentOutlet.activateEvents.subscribe(() => { this.contentOutlet.activateEvents.subscribe(() => this.updateOutletRoute()),
this.updateClasses(); this.contentOutlet.deactivateEvents.subscribe(() => this.updateOutletRoute()),
this.outletRouteSubject.next(this.contentOutlet.activatedRoute.snapshot);
}),
this.contentOutlet.deactivateEvents.subscribe(() => {
this.updateClasses();
this.outletRouteSubject.next(null);
}),
CoreScreen.layoutObservable.subscribe(() => this.updateClasses()), CoreScreen.layoutObservable.subscribe(() => this.updateClasses()),
]; ];
@ -89,6 +83,17 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy {
this.enableScrollOnParent(); 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. * Update host classes.
*/ */

View File

@ -110,19 +110,28 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
* View loaded. * View loaded.
*/ */
async ngOnInit(): Promise<void> { 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. // Is implicit the user can delete if he can add.
this.addDeleteCommentsAvailable = await CoreComments.isAddCommentsAvailable(); this.addDeleteCommentsAvailable = await CoreComments.isAddCommentsAvailable();
this.currentUserId = CoreSites.getCurrentSiteUserId(); this.currentUserId = CoreSites.getCurrentSiteUserId();
this.commentsLoaded = false; 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); await this.fetchComments(true);
} }

View File

@ -14,10 +14,10 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreCourseAnyModuleData } from '../services/course'; import { CoreCourseAnyModuleData } from '../services/course';
import { CoreCourseModuleMainResourceComponent } from './main-resource-component'; import { CoreCourseModuleMainResourceComponent } from './main-resource-component';
/**
/** /**
* Template class to easily create CoreCourseModuleMainComponent of resources (or activities without syncing). * 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. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.module = CoreNavigator.getRouteParam<CoreCourseAnyModuleData>('module')!; try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.module = CoreNavigator.getRequiredRouteParam<CoreCourseAnyModuleData>('module');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
this.title = this.module?.name; this.title = this.module?.name;
} }

View File

@ -59,7 +59,7 @@ export class CoreCoursesCategoriesPage implements OnInit {
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async fetchCategories(): Promise<void> { protected async fetchCategories(): Promise<void> {
try{ try {
const categories: CoreCategoryData[] = await CoreCourses.getCategories(this.categoryId, true); const categories: CoreCategoryData[] = await CoreCourses.getCategories(this.categoryId, true);
this.currentCategory = undefined; this.currentCategory = undefined;

View File

@ -40,14 +40,26 @@ import { CoreNavigator } from '@services/navigator';
}) })
export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { export class CoreGradesCoursePage implements AfterViewInit, OnDestroy {
grades: CoreGradesCourseManager; grades!: CoreGradesCourseManager;
splitViewMode?: CoreSplitViewMode; splitViewMode?: CoreSplitViewMode;
@ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent; @ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent;
constructor(protected route: ActivatedRoute) { constructor(protected route: ActivatedRoute) {
const courseId = CoreNavigator.getRouteNumberParam('courseId', { route })!; let courseId: number;
const userId = CoreNavigator.getRouteNumberParam('userId', { route }) ?? CoreSites.getCurrentSiteUserId(); 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 useSplitView = route.snapshot.data.useSplitView ?? true;
const outsideGradesTab = route.snapshot.data.outsideGradesTab ?? false; const outsideGradesTab = route.snapshot.data.outsideGradesTab ?? false;

View File

@ -31,16 +31,24 @@ import { CoreNavigator } from '@services/navigator';
}) })
export class CoreGradesGradePage implements OnInit { export class CoreGradesGradePage implements OnInit {
courseId: number; courseId!: number;
userId: number; userId!: number;
gradeId: number; gradeId!: number;
grade?: CoreGradesFormattedRow | null; grade?: CoreGradesFormattedRow | null;
gradeLoaded = false; gradeLoaded = false;
constructor() { constructor() {
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; try {
this.gradeId = CoreNavigator.getRouteNumberParam('gradeId')!; this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
this.gradeId = CoreNavigator.getRequiredRouteNumberParam('gradeId');
this.userId = CoreNavigator.getRouteNumberParam('userId') ?? CoreSites.getCurrentSiteUserId(); this.userId = CoreNavigator.getRouteNumberParam('userId') ?? CoreSites.getCurrentSiteUserId();
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
} }
/** /**

View File

@ -33,7 +33,7 @@ import { CoreUtils } from '@services/utils/utils';
}) })
export class CoreUserParticipantsPage implements OnInit, AfterViewInit, OnDestroy { export class CoreUserParticipantsPage implements OnInit, AfterViewInit, OnDestroy {
participants: CoreUserParticipantsManager; participants!: CoreUserParticipantsManager;
searchQuery: string | null = null; searchQuery: string | null = null;
searchInProgress = false; searchInProgress = false;
searchEnabled = false; searchEnabled = false;
@ -43,7 +43,17 @@ export class CoreUserParticipantsPage implements OnInit, AfterViewInit, OnDestro
@ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent; @ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent;
constructor() { 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); this.participants = new CoreUserParticipantsManager(CoreUserParticipantsPage, courseId);
} }

View File

@ -30,6 +30,7 @@ import { makeSingleton, NavController, Router } from '@singletons';
import { CoreScreen } from './screen'; import { CoreScreen } from './screen';
import { CoreApp } from './app'; import { CoreApp } from './app';
import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins';
import { CoreError } from '@classes/errors/error';
const DEFAULT_MAIN_MENU_TAB = CoreMainMenuHomeHandlerService.PAGE_NAME; 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]; const value = route.snapshot.queryParams[name] ?? route.snapshot.params[name];
if (typeof value != 'undefined') { if (value !== undefined) {
return value; return value;
} }
@ -300,7 +301,7 @@ export class CoreNavigatorService {
value = routeOptions.params[name]; value = routeOptions.params[name];
} }
if (typeof value == 'undefined') { if (value === undefined) {
return; return;
} }
@ -345,7 +346,7 @@ export class CoreNavigatorService {
getRouteBooleanParam(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): boolean | undefined { getRouteBooleanParam(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): boolean | undefined {
const value = this.getRouteParam<string>(name, routeOptions); const value = this.getRouteParam<string>(name, routeOptions);
if (typeof value == 'undefined') { if (value === undefined) {
return value; return value;
} }
@ -360,6 +361,67 @@ export class CoreNavigatorService {
return Boolean(value); 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. * Navigate back.
* *