diff --git a/src/addons/messages/pages/discussion/discussion.page.ts b/src/addons/messages/pages/discussion/discussion.page.ts index a66e6af9a..6717cb529 100644 --- a/src/addons/messages/pages/discussion/discussion.page.ts +++ b/src/addons/messages/pages/discussion/discussion.page.ts @@ -164,9 +164,9 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView this.route.queryParams.subscribe(async (params) => { this.loaded = false; - this.conversationId = CoreNavigator.getRouteNumberParam('conversationId', params) || undefined; - this.userId = CoreNavigator.getRouteNumberParam('userId', params) || undefined; - this.showKeyboard = CoreNavigator.getRouteBooleanParam('showKeyboard', params) || false; + this.conversationId = CoreNavigator.getRouteNumberParam('conversationId', { params }) || undefined; + this.userId = CoreNavigator.getRouteNumberParam('userId', { params }) || undefined; + this.showKeyboard = CoreNavigator.getRouteBooleanParam('showKeyboard', { params }) || false; await this.fetchData(); diff --git a/src/addons/messages/pages/discussions-35/discussions.page.ts b/src/addons/messages/pages/discussions-35/discussions.page.ts index 3f8e8370e..34a935772 100644 --- a/src/addons/messages/pages/discussions-35/discussions.page.ts +++ b/src/addons/messages/pages/discussions-35/discussions.page.ts @@ -138,8 +138,8 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy { */ ngOnInit(): void { this.route.queryParams.subscribe(async (params) => { - const discussionUserId = CoreNavigator.getRouteNumberParam('discussionUserId', params) || - CoreNavigator.getRouteNumberParam('userId', params) || undefined; + const discussionUserId = CoreNavigator.getRouteNumberParam('discussionUserId', { params }) || + CoreNavigator.getRouteNumberParam('userId', { params }) || undefined; if (this.loaded && this.discussionUserId == discussionUserId) { return; diff --git a/src/addons/messages/pages/group-conversations/group-conversations.page.ts b/src/addons/messages/pages/group-conversations/group-conversations.page.ts index 27f6b30f8..2757fc7a2 100644 --- a/src/addons/messages/pages/group-conversations/group-conversations.page.ts +++ b/src/addons/messages/pages/group-conversations/group-conversations.page.ts @@ -273,9 +273,9 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy { ngOnInit(): void { this.route.queryParams.subscribe(async (params) => { // Conversation to load. - this.conversationId = CoreNavigator.getRouteNumberParam('conversationId', params) || undefined; + this.conversationId = CoreNavigator.getRouteNumberParam('conversationId', { params }) || undefined; if (!this.conversationId) { - this.discussionUserId = CoreNavigator.getRouteNumberParam('discussionUserId', params) || undefined; + this.discussionUserId = CoreNavigator.getRouteNumberParam('discussionUserId', { params }) || undefined; } if (this.conversationId || this.discussionUserId) { diff --git a/src/addons/mod/assign/pages/submission-review/submission-review.ts b/src/addons/mod/assign/pages/submission-review/submission-review.ts index eae18746b..2c5e846d7 100644 --- a/src/addons/mod/assign/pages/submission-review/submission-review.ts +++ b/src/addons/mod/assign/pages/submission-review/submission-review.ts @@ -58,7 +58,7 @@ export class AddonModAssignSubmissionReviewPage implements OnInit, CanLeave { this.moduleId = CoreNavigator.getRouteNumberParam('cmId')!; this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.submitId = CoreNavigator.getRouteNumberParam('submitId') || 0; - this.blindId = CoreNavigator.getRouteNumberParam('blindId', params); + this.blindId = CoreNavigator.getRouteNumberParam('blindId', { params }); this.fetchSubmission().finally(() => { this.loaded = true; diff --git a/src/core/features/grades/pages/courses/courses.page.ts b/src/core/features/grades/pages/courses/courses.page.ts index 603253f58..df98d2033 100644 --- a/src/core/features/grades/pages/courses/courses.page.ts +++ b/src/core/features/grades/pages/courses/courses.page.ts @@ -16,11 +16,10 @@ import { AfterViewInit, Component, OnDestroy, ViewChild } from '@angular/core'; import { ActivatedRouteSnapshot } from '@angular/router'; import { CorePageItemsListManager } from '@classes/page-items-list-manager'; -import { CoreSplitViewComponent, CoreSplitViewMode } from '@components/split-view/split-view'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreGrades } from '@features/grades/services/grades'; import { CoreGradesGradeOverviewWithCourseData, CoreGradesHelper } from '@features/grades/services/grades-helper'; import { IonRefresher } from '@ionic/angular'; -import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; @@ -34,27 +33,13 @@ import { CoreUtils } from '@services/utils/utils'; export class CoreGradesCoursesPage implements OnDestroy, AfterViewInit { courses: CoreGradesCoursesManager = new CoreGradesCoursesManager(CoreGradesCoursesPage); - splitViewMode?: CoreSplitViewMode; @ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent; - constructor() { - const userId = CoreNavigator.getRouteNumberParam('userId'); - const courseId = CoreNavigator.getRouteNumberParam('courseId'); - - // If courseId and userId is set, show only the content page. - this.splitViewMode = courseId && userId ? undefined : CoreSplitViewMode.ContentOnly; - } - /** * @inheritdoc */ async ngAfterViewInit(): Promise { - if (this.splitViewMode) { - // Won't be shown, do nothing. - return; - } - await this.fetchInitialCourses(); this.courses.start(this.splitView); diff --git a/src/core/services/navigator.ts b/src/core/services/navigator.ts index ab711adaa..bd223c89d 100644 --- a/src/core/services/navigator.ts +++ b/src/core/services/navigator.ts @@ -52,10 +52,11 @@ export type CoreNavigationOptions = { }; /** - * Options for CoreNavigatorService#getCurrentRoute method. + * Route options to get route or params values. */ -type GetCurrentRouteOptions = Partial<{ - parentRoute: ActivatedRoute; +export type CoreNavigatorCurrentRouteOptions = Partial<{ + params: Params; // Params to get the value from. + route: ActivatedRoute; // Current Route. pageComponent: unknown; }>; @@ -246,8 +247,8 @@ export class CoreNavigatorService { /** * Iterately get the params checking parent routes. * - * @param route Current route. * @param name Name of the parameter. + * @param route Current route. * @return Value of the parameter, undefined if not found. */ protected getRouteSnapshotParam(name: string, route?: ActivatedRoute): T | undefined { @@ -270,18 +271,21 @@ export class CoreNavigatorService { * unless there's a new navigation to the page. * * @param name Name of the parameter. - * @param params Optional params to get the value from. If missing, it will autodetect. + * @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. */ - getRouteParam(name: string, params?: Params): T | undefined { + getRouteParam(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): T | undefined { let value: any; - if (!params) { - const route = this.getCurrentRoute(); + if (!routeOptions.params) { + let route = this.getCurrentRoute(); + if (!route?.snapshot && routeOptions.route) { + route = routeOptions.route; + } value = this.getRouteSnapshotParam(name, route); } else { - value = params[name]; + value = routeOptions.params[name]; } if (typeof value == 'undefined') { @@ -309,11 +313,11 @@ export class CoreNavigatorService { * Angular router automatically converts numbers to string, this function automatically converts it back to number. * * @param name Name of the parameter. - * @param params Optional params to get the value from. If missing, it will autodetect. + * @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. */ - getRouteNumberParam(name: string, params?: Params): number | undefined { - const value = this.getRouteParam(name, params); + getRouteNumberParam(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): number | undefined { + const value = this.getRouteParam(name, routeOptions); return value !== undefined ? Number(value) : value; } @@ -323,13 +327,25 @@ export class CoreNavigatorService { * Angular router automatically converts booleans to string, this function automatically converts it back to boolean. * * @param name Name of the parameter. - * @param params Optional params to get the value from. If missing, it will autodetect. + * @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. */ - getRouteBooleanParam(name: string, params?: Params): boolean | undefined { - const value = this.getRouteParam(name, params); + getRouteBooleanParam(name: string, routeOptions: CoreNavigatorCurrentRouteOptions = {}): boolean | undefined { + const value = this.getRouteParam(name, routeOptions); - return value !== undefined ? Boolean(value) : value; + if (typeof value == 'undefined') { + return value; + } + + if (CoreUtils.isTrueOrOne(value)) { + return true; + } + + if (CoreUtils.isFalseOrZero(value)) { + return false; + } + + return Boolean(value); } /** @@ -345,25 +361,25 @@ export class CoreNavigatorService { * Get current activated route. * * @param options - * - parent: Parent route, if this isn't provided the current active route will be used. + * - route: Parent route, if this isn't provided the current active route will be used. * - pageComponent: Page component of the route to find, if this isn't provided the deepest route in the hierarchy * will be returned. * @return Current activated route. */ getCurrentRoute(): ActivatedRoute; - getCurrentRoute(options: GetCurrentRouteOptions): ActivatedRoute | null; - getCurrentRoute({ parentRoute, pageComponent }: GetCurrentRouteOptions = {}): ActivatedRoute | null { - parentRoute = parentRoute ?? Router.routerState.root; + getCurrentRoute(options: CoreNavigatorCurrentRouteOptions): ActivatedRoute | null; + getCurrentRoute({ route, pageComponent }: CoreNavigatorCurrentRouteOptions = {}): ActivatedRoute | null { + route = route ?? Router.routerState.root; - if (pageComponent && parentRoute.component === pageComponent) { - return parentRoute; + if (pageComponent && route.component === pageComponent) { + return route; } - if (parentRoute.firstChild) { - return this.getCurrentRoute({ parentRoute: parentRoute.firstChild, pageComponent }); + if (route.firstChild) { + return this.getCurrentRoute({ route: route.firstChild, pageComponent }); } - return pageComponent ? null : parentRoute; + return pageComponent ? null : route; } /**