MOBILE-3592 routes: Allow add siblings to any main menu tab

main
Dani Palou 2020-12-11 10:36:24 +01:00
parent 36d03d27c5
commit 186593b09f
8 changed files with 121 additions and 93 deletions

View File

@ -12,23 +12,33 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { NgModule } from '@angular/core'; import { Injector, NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, ROUTES, Routes } from '@angular/router';
const routes: Routes = [ import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
{
path: '', function buildRoutes(injector: Injector): Routes {
redirectTo: 'root', // Fake "hash". return [
pathMatch: 'full',
},
{ {
path: ':hash', path: ':hash',
loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule), loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule),
}, },
...buildTabMainRoutes(injector, {
redirectTo: 'root', // Fake "hash".
pathMatch: 'full',
}),
]; ];
}
@NgModule({ @NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule], exports: [RouterModule],
providers: [
{
provide: ROUTES,
multi: true,
deps: [Injector],
useFactory: buildRoutes,
},
],
}) })
export class AddonPrivateFilesLazyModule {} export class AddonPrivateFilesLazyModule {}

View File

@ -0,0 +1,47 @@
// (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 { Route, Routes } from '@angular/router';
import { ModuleRoutes, resolveModuleRoutes } from '@/app/app-routing.module';
export const MAIN_MENU_TAB_ROUTES = new InjectionToken('MAIN_MENU_TAB_ROUTES');
export function buildTabMainRoutes(injector: Injector, mainRoute: Route): Routes {
const routes = resolveModuleRoutes(injector, MAIN_MENU_TAB_ROUTES);
mainRoute.path = mainRoute.path || '';
mainRoute.children = mainRoute.children || [];
mainRoute.children.concat(routes.children);
return [
mainRoute,
...routes.siblings,
];
}
@NgModule()
export class CoreMainMenuTabRoutingModule {
static forChild(routes: Partial<ModuleRoutes>): ModuleWithProviders<CoreMainMenuTabRoutingModule> {
return {
ngModule: CoreMainMenuTabRoutingModule,
providers: [
{ provide: MAIN_MENU_TAB_ROUTES, multi: true, useValue: routes },
],
};
}
}

View File

@ -24,16 +24,17 @@ import { CoreDirectivesModule } from '@directives/directives.module';
import { CoreMainMenuHomePage } from './home'; import { CoreMainMenuHomePage } from './home';
import { MAIN_MENU_HOME_ROUTES } from './home-routing.module'; import { MAIN_MENU_HOME_ROUTES } from './home-routing.module';
import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
function buildRoutes(injector: Injector): Routes { function buildRoutes(injector: Injector): Routes {
const routes = resolveModuleRoutes(injector, MAIN_MENU_HOME_ROUTES); const routes = resolveModuleRoutes(injector, MAIN_MENU_HOME_ROUTES);
return [ return [
{ ...buildTabMainRoutes(injector, {
path: '', path: '',
component: CoreMainMenuHomePage, component: CoreMainMenuHomePage,
children: routes.children, children: routes.children,
}, }),
...routes.siblings, ...routes.siblings,
]; ];
} }

View File

@ -1,33 +0,0 @@
// (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, ModuleWithProviders, NgModule } from '@angular/core';
import { ModuleRoutes } from '@/app/app-routing.module';
export const MAIN_MENU_MORE_ROUTES = new InjectionToken('MAIN_MENU_MORE_ROUTES');
@NgModule()
export class CoreMainMenuMoreRoutingModule {
static forChild(routes: Partial<ModuleRoutes>): ModuleWithProviders<CoreMainMenuMoreRoutingModule> {
return {
ngModule: CoreMainMenuMoreRoutingModule,
providers: [
{ provide: MAIN_MENU_MORE_ROUTES, multi: true, useValue: routes },
],
};
}
}

View File

@ -14,29 +14,14 @@
import { Injector, NgModule } from '@angular/core'; import { Injector, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { RouterModule, ROUTES, Routes } from '@angular/router'; import { RouterModule, ROUTES } from '@angular/router';
import { IonicModule } from '@ionic/angular'; import { IonicModule } from '@ionic/angular';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { resolveModuleRoutes } from '@/app/app-routing.module';
import { CoreComponentsModule } from '@components/components.module'; import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module'; import { CoreDirectivesModule } from '@directives/directives.module';
import { CoreMainMenuMorePage } from './more'; import { CoreMainMenuMorePage } from './more';
import { MAIN_MENU_MORE_ROUTES } from './more-routing.module'; import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
function buildRoutes(injector: Injector): Routes {
const routes = resolveModuleRoutes(injector, MAIN_MENU_MORE_ROUTES);
return [
{
path: '',
component: CoreMainMenuMorePage,
children: routes.children,
},
...routes.siblings,
];
}
@NgModule({ @NgModule({
imports: [ imports: [
@ -47,7 +32,14 @@ function buildRoutes(injector: Injector): Routes {
CoreDirectivesModule, CoreDirectivesModule,
], ],
providers: [ providers: [
{ provide: ROUTES, multi: true, useFactory: buildRoutes, deps: [Injector] }, {
provide: ROUTES,
multi: true,
deps: [Injector],
useFactory: (injector: Injector) => buildTabMainRoutes(injector, {
component: CoreMainMenuMorePage,
}),
},
], ],
declarations: [ declarations: [
CoreMainMenuMorePage, CoreMainMenuMorePage,

View File

@ -16,7 +16,7 @@ import { APP_INITIALIZER, NgModule } from '@angular/core';
import { Routes } from '@angular/router'; import { Routes } from '@angular/router';
import { AppRoutingModule } from '@/app/app-routing.module'; import { AppRoutingModule } from '@/app/app-routing.module';
import { CoreMainMenuMoreRoutingModule } from '@features/mainmenu/pages/more/more-routing.module'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
import { CoreSettingsHelperProvider } from './services/settings-helper'; import { CoreSettingsHelperProvider } from './services/settings-helper';
@ -41,7 +41,7 @@ const mainMenuMoreRoutes: Routes = [
@NgModule({ @NgModule({
imports: [ imports: [
AppRoutingModule.forChild(appRoutes), AppRoutingModule.forChild(appRoutes),
CoreMainMenuMoreRoutingModule.forChild({ siblings: mainMenuMoreRoutes }), CoreMainMenuTabRoutingModule.forChild({ siblings: mainMenuMoreRoutes }),
], ],
providers: [ providers: [
{ {

View File

@ -12,10 +12,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { NgModule } from '@angular/core'; import { Injector, NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, ROUTES, Routes } from '@angular/router';
const routes: Routes = [ import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
function buildRoutes(injector: Injector): Routes {
return [
{ {
path: 'index', path: 'index',
loadChildren: () => import('@features/tag/pages/index/index.page.module').then(m => m.CoreTagIndexPageModule), loadChildren: () => import('@features/tag/pages/index/index.page.module').then(m => m.CoreTagIndexPageModule),
@ -26,17 +29,25 @@ const routes: Routes = [
}, },
{ {
path: 'index-area', path: 'index-area',
loadChildren: () => import('@features/tag/pages/index-area/index-area.page.module').then(m => m.CoreTagIndexAreaPageModule), loadChildren: () =>
import('@features/tag/pages/index-area/index-area.page.module').then(m => m.CoreTagIndexAreaPageModule),
}, },
{ ...buildTabMainRoutes(injector, {
path: '',
redirectTo: 'search', redirectTo: 'search',
pathMatch: 'full', pathMatch: 'full',
}, }),
]; ];
}
@NgModule({ @NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule], exports: [RouterModule],
providers: [
{
provide: ROUTES,
multi: true,
deps: [Injector],
useFactory: buildRoutes,
},
],
}) })
export class CoreTagLazyModule { } export class CoreTagLazyModule { }

View File

@ -15,7 +15,7 @@
import { APP_INITIALIZER, NgModule } from '@angular/core'; import { APP_INITIALIZER, NgModule } from '@angular/core';
import { Routes } from '@angular/router'; import { Routes } from '@angular/router';
import { CoreMainMenuMoreRoutingModule } from '@features/mainmenu/pages/more/more-routing.module'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
import { CORE_SITE_SCHEMAS } from '@services/sites'; import { CORE_SITE_SCHEMAS } from '@services/sites';
import { SITE_SCHEMA, OFFLINE_SITE_SCHEMA } from './services/database/user'; import { SITE_SCHEMA, OFFLINE_SITE_SCHEMA } from './services/database/user';
import { CoreUserComponentsModule } from './components/components.module'; import { CoreUserComponentsModule } from './components/components.module';
@ -37,7 +37,7 @@ const routes: Routes = [
@NgModule({ @NgModule({
imports: [ imports: [
CoreMainMenuMoreRoutingModule.forChild({ siblings: routes }), CoreMainMenuTabRoutingModule.forChild({ siblings: routes }),
CoreUserComponentsModule, CoreUserComponentsModule,
], ],
providers: [ providers: [