From cf6da0481b57cf15b9dd421875aec18ad7936a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 12 Nov 2020 14:01:45 +0100 Subject: [PATCH] MOBILE-3565 courses: Add priority to dashboard --- src/app/core/courses/courses.module.ts | 8 +-- .../{dashboard.ts => dashboard.home.ts} | 11 ++-- .../pages/home/home-routing.module.ts | 56 +++++++++++++++++++ 3 files changed, 65 insertions(+), 10 deletions(-) rename src/app/core/courses/services/handlers/{dashboard.ts => dashboard.home.ts} (83%) create mode 100644 src/app/core/mainmenu/pages/home/home-routing.module.ts diff --git a/src/app/core/courses/courses.module.ts b/src/app/core/courses/courses.module.ts index bbc05d612..c38b25679 100644 --- a/src/app/core/courses/courses.module.ts +++ b/src/app/core/courses/courses.module.ts @@ -16,9 +16,7 @@ import { NgModule } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreHomeRoutingModule } from '../mainmenu/pages/home/home-routing.module'; import { CoreHomeDelegate } from '../mainmenu/services/home.delegate'; -import { CoreCoursesDashboardHandler } from './services/handlers/dashboard'; -import { CoreCoursesDashboardPage } from './pages/dashboard/dashboard.page'; - +import { CoreDashboardHomeHandler } from './services/handlers/dashboard.home'; const routes: Routes = [ { @@ -32,14 +30,14 @@ const routes: Routes = [ imports: [CoreHomeRoutingModule.forChild(routes)], exports: [CoreHomeRoutingModule], providers: [ - CoreCoursesDashboardHandler, + CoreDashboardHomeHandler, ], }) export class CoreCoursesModule { constructor( homeDelegate: CoreHomeDelegate, - coursesDashboardHandler: CoreCoursesDashboardHandler, + coursesDashboardHandler: CoreDashboardHomeHandler, ) { homeDelegate.registerHandler(coursesDashboardHandler); } diff --git a/src/app/core/courses/services/handlers/dashboard.ts b/src/app/core/courses/services/handlers/dashboard.home.ts similarity index 83% rename from src/app/core/courses/services/handlers/dashboard.ts rename to src/app/core/courses/services/handlers/dashboard.home.ts index 5ef475a46..cfdbb8ab3 100644 --- a/src/app/core/courses/services/handlers/dashboard.ts +++ b/src/app/core/courses/services/handlers/dashboard.home.ts @@ -13,13 +13,13 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreHomeHandler, CoreHomeHandlerData } from '@core/mainmenu/services/home.delegate'; +import { CoreHomeHandler, CoreHomeHandlerToDisplay } from '@core/mainmenu/services/home.delegate'; /** * Handler to add Home into main menu. */ Injectable(); -export class CoreCoursesDashboardHandler implements CoreHomeHandler { +export class CoreDashboardHomeHandler implements CoreHomeHandler { name = 'CoreCoursesDashboard'; priority = 1100; @@ -50,12 +50,13 @@ export class CoreCoursesDashboardHandler implements CoreHomeHandler { * * @return Data needed to render the handler. */ - getDisplayData(): CoreHomeHandlerData { + getDisplayData(): CoreHomeHandlerToDisplay { return { title: 'core.courses.mymoodle', - page: 'home/dashboard', + page: 'dashboard', class: 'core-courses-dashboard-handler', - icon: 'fa-tachometer-alt', + icon: 'fas-tachometer-alt', + selectPriority: 1000, }; } diff --git a/src/app/core/mainmenu/pages/home/home-routing.module.ts b/src/app/core/mainmenu/pages/home/home-routing.module.ts new file mode 100644 index 000000000..092239b13 --- /dev/null +++ b/src/app/core/mainmenu/pages/home/home-routing.module.ts @@ -0,0 +1,56 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { InjectionToken, Injector, ModuleWithProviders, NgModule } from '@angular/core'; +import { RouterModule, ROUTES, Routes } from '@angular/router'; + +import { CoreArray } from '@/app/singletons/array'; + +import { CoreHomePage } from './home.page'; + +function buildHomeRoutes(injector: Injector): Routes { + const routes = CoreArray.flatten(injector.get(HOME_ROUTES, [])); + + return [ + { + path: '', + component: CoreHomePage, + children: [ + ...routes, + // @todo handle 404. + ], + }, + ]; +} + +export const HOME_ROUTES = new InjectionToken('HOME_ROUTES'); + +@NgModule({ + providers: [ + { provide: ROUTES, multi: true, useFactory: buildHomeRoutes, deps: [Injector] }, + ], + exports: [RouterModule], +}) +export class CoreHomeRoutingModule { + + static forChild(routes: Routes): ModuleWithProviders { + return { + ngModule: CoreHomeRoutingModule, + providers: [ + { provide: HOME_ROUTES, multi: true, useValue: routes }, + ], + }; + } + +}