From 803ad32ec85eabb65943f901f6dc673ccc4e480b Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 11 Jan 2022 09:33:02 +0100 Subject: [PATCH] MOBILE-3934 grades: Refactor routes --- ...odule.ts => grades-courses-lazy.module.ts} | 9 +------ src/core/features/grades/grades.module.ts | 24 ++++++++++--------- .../grades/pages/course/course.page.ts | 6 ++++- .../features/grades/services/grades-helper.ts | 13 ++++------ .../grades/services/handlers/overview-link.ts | 6 ++--- .../features/grades/services/handlers/user.ts | 13 +++++----- 6 files changed, 32 insertions(+), 39 deletions(-) rename src/core/features/grades/{grades-lazy.module.ts => grades-courses-lazy.module.ts} (88%) diff --git a/src/core/features/grades/grades-lazy.module.ts b/src/core/features/grades/grades-courses-lazy.module.ts similarity index 88% rename from src/core/features/grades/grades-lazy.module.ts rename to src/core/features/grades/grades-courses-lazy.module.ts index d825a2621..94dee326b 100644 --- a/src/core/features/grades/grades-lazy.module.ts +++ b/src/core/features/grades/grades-courses-lazy.module.ts @@ -23,14 +23,10 @@ import { CoreGradesCoursePage } from './pages/course/course.page'; import { CoreGradesCoursePageModule } from './pages/course/course.module'; import { CoreGradesCoursesPage } from './pages/courses/courses.page'; import { CoreGradesGradePage } from './pages/grade/grade.page'; -import { CoreGradesUserHandlerService } from './services/handlers/user'; const mobileRoutes: Routes = [ { path: '', - data: { - mainMenuTabRoot: CoreGradesUserHandlerService.PAGE_NAME, - }, component: CoreGradesCoursesPage, }, { @@ -46,9 +42,6 @@ const mobileRoutes: Routes = [ const tabletRoutes: Routes = [ { path: '', - data: { - mainMenuTabRoot: CoreGradesUserHandlerService.PAGE_NAME, - }, component: CoreGradesCoursesPage, children: [ { @@ -85,4 +78,4 @@ const routes: Routes = [ CoreGradesGradePage, ], }) -export class CoreGradesLazyModule {} +export class CoreGradesCoursesLazyModule {} diff --git a/src/core/features/grades/grades.module.ts b/src/core/features/grades/grades.module.ts index d7ca58cf3..6669a9161 100644 --- a/src/core/features/grades/grades.module.ts +++ b/src/core/features/grades/grades.module.ts @@ -15,16 +15,17 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { COURSE_PAGE_NAME } from '@features/course/course.module'; import { CoreCourseIndexRoutingModule } from '@features/course/pages/index/index-routing.module'; import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate'; -import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CoreUserDelegate } from '@features/user/services/user-delegate'; +import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module'; import { CoreGradesProvider } from './services/grades'; import { CoreGradesHelperProvider } from './services/grades-helper'; import { CoreGradesCourseOptionHandler } from './services/handlers/course-option'; import { CoreGradesOverviewLinkHandler } from './services/handlers/overview-link'; -import { CoreGradesUserHandler, CoreGradesUserHandlerService } from './services/handlers/user'; +import { CoreGradesUserHandler } from './services/handlers/user'; import { CoreGradesUserLinkHandler } from './services/handlers/user-link'; export const CORE_GRADES_SERVICES: Type[] = [ @@ -32,28 +33,29 @@ export const CORE_GRADES_SERVICES: Type[] = [ CoreGradesHelperProvider, ]; -const routes: Routes = [ +export const GRADES_PAGE_NAME = 'grades'; + +const mainMenuChildrenRoutes: Routes = [ { - path: CoreGradesUserHandlerService.PAGE_NAME, - loadChildren: () => import('@features/grades/grades-lazy.module').then(m => m.CoreGradesLazyModule), + path: GRADES_PAGE_NAME, + loadChildren: () => import('./grades-courses-lazy.module').then(m => m.CoreGradesCoursesLazyModule), }, { - path: 'user-grades/:courseId', - loadChildren: () => import('@features/grades/grades-course-lazy.module').then(m => m.CoreGradesCourseLazyModule), + path: `${COURSE_PAGE_NAME}/:courseId/${PARTICIPANTS_PAGE_NAME}/:userId/${GRADES_PAGE_NAME}`, + loadChildren: () => import('./grades-course-lazy.module').then(m => m.CoreGradesCourseLazyModule), }, ]; const courseIndexRoutes: Routes = [ { - path: 'grades', - loadChildren: () => import('@features/grades/grades-course-lazy.module').then(m => m.CoreGradesCourseLazyModule), + path: GRADES_PAGE_NAME, + loadChildren: () => import('./grades-course-lazy.module').then(m => m.CoreGradesCourseLazyModule), }, ]; @NgModule({ imports: [ - CoreMainMenuTabRoutingModule.forChild(routes), - CoreMainMenuRoutingModule.forChild({ children: routes }), + CoreMainMenuTabRoutingModule.forChild(mainMenuChildrenRoutes), CoreCourseIndexRoutingModule.forChild({ children: courseIndexRoutes }), ], providers: [ diff --git a/src/core/features/grades/pages/course/course.page.ts b/src/core/features/grades/pages/course/course.page.ts index 224d9369b..51ef0fe4f 100644 --- a/src/core/features/grades/pages/course/course.page.ts +++ b/src/core/features/grades/pages/course/course.page.ts @@ -159,7 +159,11 @@ class CoreGradesCourseManager extends CorePageItemsListManager { if (this.outsideGradesTab) { - await CoreNavigator.navigateToSitePath(`/grades/${this.courseId}/${row.id}`); + await CoreNavigator.navigateToSitePath(`/grades/${this.courseId}/${row.id}`, { + params: { + userId: this.userId, + }, + }); return; } diff --git a/src/core/features/grades/services/grades-helper.ts b/src/core/features/grades/services/grades-helper.ts index b602a8df5..add464673 100644 --- a/src/core/features/grades/services/grades-helper.ts +++ b/src/core/features/grades/services/grades-helper.ts @@ -35,6 +35,7 @@ import { CoreNavigator } from '@services/navigator'; import { makeSingleton, Translate } from '@singletons'; import { CoreError } from '@classes/errors/error'; import { CoreCourseHelper } from '@features/course/services/course-helper'; +import { GRADES_PAGE_NAME } from '../grades.module'; /** * Service that provides some features regarding grades information. @@ -472,10 +473,7 @@ export class CoreGradesHelperProvider { const gradeId = item.id; await CoreUtils.ignoreErrors( - CoreNavigator.navigateToSitePath(`/grades/${courseId}/${gradeId}`, { - siteId, - params: { userId }, - }), + CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}/${gradeId}`, { siteId }), ); } catch (error) { try { @@ -483,10 +481,7 @@ export class CoreGradesHelperProvider { if (userId && userId != currentUserId) { // View another user grades. Open the grades page directly. await CoreUtils.ignoreErrors( - CoreNavigator.navigateToSitePath(`/grades/${courseId}`, { - siteId, - params: { userId }, - }), + CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}`, { siteId }), ); } @@ -502,7 +497,7 @@ export class CoreGradesHelperProvider { await CoreCourseHelper.getAndOpenCourse(courseId, { selectedTab: 'CoreGrades' }, siteId); } catch (error) { // Cannot get course for some reason, just open the grades page. - await CoreNavigator.navigateToSitePath(`/grades/${courseId}`, { siteId }); + await CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}`, { siteId }); } } finally { modal.dismiss(); diff --git a/src/core/features/grades/services/handlers/overview-link.ts b/src/core/features/grades/services/handlers/overview-link.ts index 307124802..241e2fc19 100644 --- a/src/core/features/grades/services/handlers/overview-link.ts +++ b/src/core/features/grades/services/handlers/overview-link.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; +import { GRADES_PAGE_NAME } from '@features/grades/grades.module'; import { CoreNavigator } from '@services/navigator'; import { makeSingleton } from '@singletons'; import { CoreGrades } from '../grades'; @@ -36,10 +37,7 @@ export class CoreGradesOverviewLinkHandlerService extends CoreContentLinksHandle getActions(): CoreContentLinksAction[] | Promise { return [{ action: siteId => { - CoreNavigator.navigateToSitePath('/grades', { - siteId, - preferCurrentTab: false, - }); + CoreNavigator.navigateToSitePath(GRADES_PAGE_NAME, { siteId }); }, }]; } diff --git a/src/core/features/grades/services/handlers/user.ts b/src/core/features/grades/services/handlers/user.ts index fab0752f6..6c4a655a0 100644 --- a/src/core/features/grades/services/handlers/user.ts +++ b/src/core/features/grades/services/handlers/user.ts @@ -13,6 +13,8 @@ // limitations under the License. import { Injectable } from '@angular/core'; +import { COURSE_PAGE_NAME } from '@features/course/course.module'; +import { GRADES_PAGE_NAME } from '@features/grades/grades.module'; import { CoreGrades } from '@features/grades/services/grades'; import { CoreUserProfile } from '@features/user/services/user'; @@ -21,6 +23,7 @@ import { CoreUserProfileHandler, CoreUserProfileHandlerData, } from '@features/user/services/user-delegate'; +import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -32,8 +35,6 @@ import { makeSingleton } from '@singletons'; @Injectable({ providedIn: 'root' }) export class CoreGradesUserHandlerService implements CoreUserProfileHandler { - static readonly PAGE_NAME = 'grades'; - name = 'CoreGrades:viewGrades'; priority = 400; type = CoreUserDelegateService.TYPE_NEW_PAGE; @@ -81,9 +82,9 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { action: (event, user, courseId): void => { event.preventDefault(); event.stopPropagation(); - CoreNavigator.navigateToSitePath(`/user-grades/${courseId}`, { - params: { userId: user.id }, - }); + CoreNavigator.navigateToSitePath( + [COURSE_PAGE_NAME, courseId, PARTICIPANTS_PAGE_NAME, user.id, GRADES_PAGE_NAME].join('/'), + ); }, }; } else { @@ -94,7 +95,7 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { action: (event): void => { event.preventDefault(); event.stopPropagation(); - CoreNavigator.navigateToSitePath(CoreGradesUserHandlerService.PAGE_NAME); + CoreNavigator.navigateToSitePath(GRADES_PAGE_NAME); }, }; }