MOBILE-3934 grades: Refactor routes
This commit is contained in:
		
							parent
							
								
									7265611dda
								
							
						
					
					
						commit
						803ad32ec8
					
				| @ -23,14 +23,10 @@ import { CoreGradesCoursePage } from './pages/course/course.page'; | |||||||
| import { CoreGradesCoursePageModule } from './pages/course/course.module'; | import { CoreGradesCoursePageModule } from './pages/course/course.module'; | ||||||
| import { CoreGradesCoursesPage } from './pages/courses/courses.page'; | import { CoreGradesCoursesPage } from './pages/courses/courses.page'; | ||||||
| import { CoreGradesGradePage } from './pages/grade/grade.page'; | import { CoreGradesGradePage } from './pages/grade/grade.page'; | ||||||
| import { CoreGradesUserHandlerService } from './services/handlers/user'; |  | ||||||
| 
 | 
 | ||||||
| const mobileRoutes: Routes = [ | const mobileRoutes: Routes = [ | ||||||
|     { |     { | ||||||
|         path: '', |         path: '', | ||||||
|         data: { |  | ||||||
|             mainMenuTabRoot: CoreGradesUserHandlerService.PAGE_NAME, |  | ||||||
|         }, |  | ||||||
|         component: CoreGradesCoursesPage, |         component: CoreGradesCoursesPage, | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
| @ -46,9 +42,6 @@ const mobileRoutes: Routes = [ | |||||||
| const tabletRoutes: Routes = [ | const tabletRoutes: Routes = [ | ||||||
|     { |     { | ||||||
|         path: '', |         path: '', | ||||||
|         data: { |  | ||||||
|             mainMenuTabRoot: CoreGradesUserHandlerService.PAGE_NAME, |  | ||||||
|         }, |  | ||||||
|         component: CoreGradesCoursesPage, |         component: CoreGradesCoursesPage, | ||||||
|         children: [ |         children: [ | ||||||
|             { |             { | ||||||
| @ -85,4 +78,4 @@ const routes: Routes = [ | |||||||
|         CoreGradesGradePage, |         CoreGradesGradePage, | ||||||
|     ], |     ], | ||||||
| }) | }) | ||||||
| export class CoreGradesLazyModule {} | export class CoreGradesCoursesLazyModule {} | ||||||
| @ -15,16 +15,17 @@ | |||||||
| import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; | import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; | ||||||
| import { Routes } from '@angular/router'; | import { Routes } from '@angular/router'; | ||||||
| import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; | 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 { CoreCourseIndexRoutingModule } from '@features/course/pages/index/index-routing.module'; | ||||||
| import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate'; | 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 { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; | ||||||
| import { CoreUserDelegate } from '@features/user/services/user-delegate'; | import { CoreUserDelegate } from '@features/user/services/user-delegate'; | ||||||
|  | import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module'; | ||||||
| import { CoreGradesProvider } from './services/grades'; | import { CoreGradesProvider } from './services/grades'; | ||||||
| import { CoreGradesHelperProvider } from './services/grades-helper'; | import { CoreGradesHelperProvider } from './services/grades-helper'; | ||||||
| import { CoreGradesCourseOptionHandler } from './services/handlers/course-option'; | import { CoreGradesCourseOptionHandler } from './services/handlers/course-option'; | ||||||
| import { CoreGradesOverviewLinkHandler } from './services/handlers/overview-link'; | 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'; | import { CoreGradesUserLinkHandler } from './services/handlers/user-link'; | ||||||
| 
 | 
 | ||||||
| export const CORE_GRADES_SERVICES: Type<unknown>[] = [ | export const CORE_GRADES_SERVICES: Type<unknown>[] = [ | ||||||
| @ -32,28 +33,29 @@ export const CORE_GRADES_SERVICES: Type<unknown>[] = [ | |||||||
|     CoreGradesHelperProvider, |     CoreGradesHelperProvider, | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| const routes: Routes = [ | export const GRADES_PAGE_NAME = 'grades'; | ||||||
|  | 
 | ||||||
|  | const mainMenuChildrenRoutes: Routes = [ | ||||||
|     { |     { | ||||||
|         path: CoreGradesUserHandlerService.PAGE_NAME, |         path: GRADES_PAGE_NAME, | ||||||
|         loadChildren: () => import('@features/grades/grades-lazy.module').then(m => m.CoreGradesLazyModule), |         loadChildren: () => import('./grades-courses-lazy.module').then(m => m.CoreGradesCoursesLazyModule), | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|         path: 'user-grades/:courseId', |         path: `${COURSE_PAGE_NAME}/:courseId/${PARTICIPANTS_PAGE_NAME}/:userId/${GRADES_PAGE_NAME}`, | ||||||
|         loadChildren: () => import('@features/grades/grades-course-lazy.module').then(m => m.CoreGradesCourseLazyModule), |         loadChildren: () => import('./grades-course-lazy.module').then(m => m.CoreGradesCourseLazyModule), | ||||||
|     }, |     }, | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| const courseIndexRoutes: Routes = [ | const courseIndexRoutes: Routes = [ | ||||||
|     { |     { | ||||||
|         path: 'grades', |         path: GRADES_PAGE_NAME, | ||||||
|         loadChildren: () => import('@features/grades/grades-course-lazy.module').then(m => m.CoreGradesCourseLazyModule), |         loadChildren: () => import('./grades-course-lazy.module').then(m => m.CoreGradesCourseLazyModule), | ||||||
|     }, |     }, | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| @NgModule({ | @NgModule({ | ||||||
|     imports: [ |     imports: [ | ||||||
|         CoreMainMenuTabRoutingModule.forChild(routes), |         CoreMainMenuTabRoutingModule.forChild(mainMenuChildrenRoutes), | ||||||
|         CoreMainMenuRoutingModule.forChild({ children: routes }), |  | ||||||
|         CoreCourseIndexRoutingModule.forChild({ children: courseIndexRoutes }), |         CoreCourseIndexRoutingModule.forChild({ children: courseIndexRoutes }), | ||||||
|     ], |     ], | ||||||
|     providers: [ |     providers: [ | ||||||
|  | |||||||
| @ -159,7 +159,11 @@ class CoreGradesCourseManager extends CorePageItemsListManager<CoreGradesFormatt | |||||||
|      */ |      */ | ||||||
|     async select(row: CoreGradesFormattedTableRowFilled): Promise<void> { |     async select(row: CoreGradesFormattedTableRowFilled): Promise<void> { | ||||||
|         if (this.outsideGradesTab) { |         if (this.outsideGradesTab) { | ||||||
|             await CoreNavigator.navigateToSitePath(`/grades/${this.courseId}/${row.id}`); |             await CoreNavigator.navigateToSitePath(`/grades/${this.courseId}/${row.id}`, { | ||||||
|  |                 params: { | ||||||
|  |                     userId: this.userId, | ||||||
|  |                 }, | ||||||
|  |             }); | ||||||
| 
 | 
 | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -35,6 +35,7 @@ import { CoreNavigator } from '@services/navigator'; | |||||||
| import { makeSingleton, Translate } from '@singletons'; | import { makeSingleton, Translate } from '@singletons'; | ||||||
| import { CoreError } from '@classes/errors/error'; | import { CoreError } from '@classes/errors/error'; | ||||||
| import { CoreCourseHelper } from '@features/course/services/course-helper'; | import { CoreCourseHelper } from '@features/course/services/course-helper'; | ||||||
|  | import { GRADES_PAGE_NAME } from '../grades.module'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Service that provides some features regarding grades information. |  * Service that provides some features regarding grades information. | ||||||
| @ -472,10 +473,7 @@ export class CoreGradesHelperProvider { | |||||||
|             const gradeId = item.id; |             const gradeId = item.id; | ||||||
| 
 | 
 | ||||||
|             await CoreUtils.ignoreErrors( |             await CoreUtils.ignoreErrors( | ||||||
|                 CoreNavigator.navigateToSitePath(`/grades/${courseId}/${gradeId}`, { |                 CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}/${gradeId}`, { siteId }), | ||||||
|                     siteId, |  | ||||||
|                     params: { userId }, |  | ||||||
|                 }), |  | ||||||
|             ); |             ); | ||||||
|         } catch (error) { |         } catch (error) { | ||||||
|             try { |             try { | ||||||
| @ -483,10 +481,7 @@ export class CoreGradesHelperProvider { | |||||||
|                 if (userId && userId != currentUserId) { |                 if (userId && userId != currentUserId) { | ||||||
|                     // View another user grades. Open the grades page directly.
 |                     // View another user grades. Open the grades page directly.
 | ||||||
|                     await CoreUtils.ignoreErrors( |                     await CoreUtils.ignoreErrors( | ||||||
|                         CoreNavigator.navigateToSitePath(`/grades/${courseId}`, { |                         CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}`, { siteId }), | ||||||
|                             siteId, |  | ||||||
|                             params: { userId }, |  | ||||||
|                         }), |  | ||||||
|                     ); |                     ); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
| @ -502,7 +497,7 @@ export class CoreGradesHelperProvider { | |||||||
|                 await CoreCourseHelper.getAndOpenCourse(courseId, { selectedTab: 'CoreGrades' }, siteId); |                 await CoreCourseHelper.getAndOpenCourse(courseId, { selectedTab: 'CoreGrades' }, siteId); | ||||||
|             } catch (error) { |             } catch (error) { | ||||||
|                 // Cannot get course for some reason, just open the grades page.
 |                 // 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 { |         } finally { | ||||||
|             modal.dismiss(); |             modal.dismiss(); | ||||||
|  | |||||||
| @ -15,6 +15,7 @@ | |||||||
| import { Injectable } from '@angular/core'; | import { Injectable } from '@angular/core'; | ||||||
| import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; | import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; | ||||||
| import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; | import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; | ||||||
|  | import { GRADES_PAGE_NAME } from '@features/grades/grades.module'; | ||||||
| import { CoreNavigator } from '@services/navigator'; | import { CoreNavigator } from '@services/navigator'; | ||||||
| import { makeSingleton } from '@singletons'; | import { makeSingleton } from '@singletons'; | ||||||
| import { CoreGrades } from '../grades'; | import { CoreGrades } from '../grades'; | ||||||
| @ -36,10 +37,7 @@ export class CoreGradesOverviewLinkHandlerService extends CoreContentLinksHandle | |||||||
|     getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { |     getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { | ||||||
|         return [{ |         return [{ | ||||||
|             action: siteId => { |             action: siteId => { | ||||||
|                 CoreNavigator.navigateToSitePath('/grades', { |                 CoreNavigator.navigateToSitePath(GRADES_PAGE_NAME, { siteId }); | ||||||
|                     siteId, |  | ||||||
|                     preferCurrentTab: false, |  | ||||||
|                 }); |  | ||||||
|             }, |             }, | ||||||
|         }]; |         }]; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -13,6 +13,8 @@ | |||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
| import { Injectable } from '@angular/core'; | 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 { CoreGrades } from '@features/grades/services/grades'; | ||||||
| import { CoreUserProfile } from '@features/user/services/user'; | import { CoreUserProfile } from '@features/user/services/user'; | ||||||
| @ -21,6 +23,7 @@ import { | |||||||
|     CoreUserProfileHandler, |     CoreUserProfileHandler, | ||||||
|     CoreUserProfileHandlerData, |     CoreUserProfileHandlerData, | ||||||
| } from '@features/user/services/user-delegate'; | } from '@features/user/services/user-delegate'; | ||||||
|  | import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module'; | ||||||
| import { CoreNavigator } from '@services/navigator'; | import { CoreNavigator } from '@services/navigator'; | ||||||
| import { CoreSites } from '@services/sites'; | import { CoreSites } from '@services/sites'; | ||||||
| import { CoreUtils } from '@services/utils/utils'; | import { CoreUtils } from '@services/utils/utils'; | ||||||
| @ -32,8 +35,6 @@ import { makeSingleton } from '@singletons'; | |||||||
| @Injectable({ providedIn: 'root' }) | @Injectable({ providedIn: 'root' }) | ||||||
| export class CoreGradesUserHandlerService implements CoreUserProfileHandler { | export class CoreGradesUserHandlerService implements CoreUserProfileHandler { | ||||||
| 
 | 
 | ||||||
|     static readonly PAGE_NAME = 'grades'; |  | ||||||
| 
 |  | ||||||
|     name = 'CoreGrades:viewGrades'; |     name = 'CoreGrades:viewGrades'; | ||||||
|     priority = 400; |     priority = 400; | ||||||
|     type = CoreUserDelegateService.TYPE_NEW_PAGE; |     type = CoreUserDelegateService.TYPE_NEW_PAGE; | ||||||
| @ -81,9 +82,9 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { | |||||||
|                 action: (event, user, courseId): void => { |                 action: (event, user, courseId): void => { | ||||||
|                     event.preventDefault(); |                     event.preventDefault(); | ||||||
|                     event.stopPropagation(); |                     event.stopPropagation(); | ||||||
|                     CoreNavigator.navigateToSitePath(`/user-grades/${courseId}`, { |                     CoreNavigator.navigateToSitePath( | ||||||
|                         params: { userId: user.id }, |                         [COURSE_PAGE_NAME, courseId, PARTICIPANTS_PAGE_NAME, user.id, GRADES_PAGE_NAME].join('/'), | ||||||
|                     }); |                     ); | ||||||
|                 }, |                 }, | ||||||
|             }; |             }; | ||||||
|         } else { |         } else { | ||||||
| @ -94,7 +95,7 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { | |||||||
|                 action: (event): void => { |                 action: (event): void => { | ||||||
|                     event.preventDefault(); |                     event.preventDefault(); | ||||||
|                     event.stopPropagation(); |                     event.stopPropagation(); | ||||||
|                     CoreNavigator.navigateToSitePath(CoreGradesUserHandlerService.PAGE_NAME); |                     CoreNavigator.navigateToSitePath(GRADES_PAGE_NAME); | ||||||
|                 }, |                 }, | ||||||
|             }; |             }; | ||||||
|         } |         } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user