Merge pull request #2605 from crazyserver/MOBILE-3565

MOBILE-3565 courses: Add priority to dashboard
main
Dani Palou 2020-11-12 14:45:22 +01:00 committed by GitHub
commit f581dbcc7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 10 deletions

View File

@ -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);
}

View File

@ -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,
};
}

View File

@ -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<Routes[]>(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<CoreHomeRoutingModule> {
return {
ngModule: CoreHomeRoutingModule,
providers: [
{ provide: HOME_ROUTES, multi: true, useValue: routes },
],
};
}
}