diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 000000000..1ae558f27 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,19 @@ +name: Testing + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '12.x' + - run: npm ci + - run: npm run lint + - run: npm run test:ci + - run: npm run build:prod diff --git a/src/addons/addons.module.ts b/src/addons/addons.module.ts index c73da06f0..f278d5c27 100644 --- a/src/addons/addons.module.ts +++ b/src/addons/addons.module.ts @@ -14,11 +14,11 @@ import { NgModule } from '@angular/core'; -import { AddonPrivateFilesInitModule } from './privatefiles/privatefiles-init.module'; +import { AddonPrivateFilesModule } from './privatefiles/privatefiles.module'; @NgModule({ imports: [ - AddonPrivateFilesInitModule, + AddonPrivateFilesModule, ], }) export class AddonsModule {} diff --git a/src/addons/privatefiles/privatefiles-init.module.ts b/src/addons/privatefiles/privatefiles-init.module.ts deleted file mode 100644 index e5ca7c84d..000000000 --- a/src/addons/privatefiles/privatefiles-init.module.ts +++ /dev/null @@ -1,45 +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 { NgModule } from '@angular/core'; -import { Routes } from '@angular/router'; - -import { CoreMainMenuDelegate } from '@features/mainmenu/services/mainmenu-delegate'; -import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module'; -import { AddonPrivateFilesMainMenuHandler } from './services/handlers/mainmenu'; - -const routes: Routes = [ - { - path: 'addon-privatefiles', - loadChildren: () => import('@/addons/privatefiles/privatefiles.module').then(m => m.AddonPrivateFilesModule), - }, -]; - -@NgModule({ - imports: [CoreMainMenuRoutingModule.forChild(routes)], - exports: [CoreMainMenuRoutingModule], - providers: [ - AddonPrivateFilesMainMenuHandler, - ], -}) -export class AddonPrivateFilesInitModule { - - constructor( - mainMenuDelegate: CoreMainMenuDelegate, - mainMenuHandler: AddonPrivateFilesMainMenuHandler, - ) { - mainMenuDelegate.registerHandler(mainMenuHandler); - } - -} diff --git a/src/addons/privatefiles/privatefiles-routing.module.ts b/src/addons/privatefiles/privatefiles-lazy.module.ts similarity index 91% rename from src/addons/privatefiles/privatefiles-routing.module.ts rename to src/addons/privatefiles/privatefiles-lazy.module.ts index a10fe99e7..307142373 100644 --- a/src/addons/privatefiles/privatefiles-routing.module.ts +++ b/src/addons/privatefiles/privatefiles-lazy.module.ts @@ -23,7 +23,7 @@ const routes: Routes = [ }, { path: ':hash', - loadChildren: () => import('./pages/index/index.module').then( m => m.AddonPrivateFilesIndexPageModule), + loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule), }, ]; @@ -31,4 +31,4 @@ const routes: Routes = [ imports: [RouterModule.forChild(routes)], exports: [RouterModule], }) -export class AddonPrivateFilesRoutingModule {} +export class AddonPrivateFilesLazyModule {} diff --git a/src/addons/privatefiles/privatefiles.module.ts b/src/addons/privatefiles/privatefiles.module.ts index 3ddb6e41c..59af1bcbf 100644 --- a/src/addons/privatefiles/privatefiles.module.ts +++ b/src/addons/privatefiles/privatefiles.module.ts @@ -13,13 +13,33 @@ // limitations under the License. import { NgModule } from '@angular/core'; +import { Routes } from '@angular/router'; -import { AddonPrivateFilesRoutingModule } from './privatefiles-routing.module'; +import { CoreMainMenuDelegate } from '@features/mainmenu/services/mainmenu-delegate'; +import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module'; +import { AddonPrivateFilesMainMenuHandler } from './services/handlers/mainmenu'; + +const routes: Routes = [ + { + path: AddonPrivateFilesMainMenuHandler.PAGE_NAME, + loadChildren: () => import('@/addons/privatefiles/privatefiles-lazy.module').then(m => m.AddonPrivateFilesLazyModule), + }, +]; @NgModule({ - imports: [ - AddonPrivateFilesRoutingModule, + imports: [CoreMainMenuRoutingModule.forChild({ children: routes })], + exports: [CoreMainMenuRoutingModule], + providers: [ + AddonPrivateFilesMainMenuHandler, ], - declarations: [], }) -export class AddonPrivateFilesModule {} +export class AddonPrivateFilesModule { + + constructor( + mainMenuDelegate: CoreMainMenuDelegate, + mainMenuHandler: AddonPrivateFilesMainMenuHandler, + ) { + mainMenuDelegate.registerHandler(mainMenuHandler); + } + +} diff --git a/src/addons/privatefiles/services/handlers/mainmenu.ts b/src/addons/privatefiles/services/handlers/mainmenu.ts index 77dfad91c..6e2e8ae2f 100644 --- a/src/addons/privatefiles/services/handlers/mainmenu.ts +++ b/src/addons/privatefiles/services/handlers/mainmenu.ts @@ -23,6 +23,8 @@ import { AddonPrivateFiles } from '@/addons/privatefiles/services/privatefiles'; @Injectable() export class AddonPrivateFilesMainMenuHandler implements CoreMainMenuHandler { + static readonly PAGE_NAME = 'private'; + name = 'AddonPrivateFiles'; priority = 400; @@ -44,7 +46,7 @@ export class AddonPrivateFilesMainMenuHandler implements CoreMainMenuHandler { return { icon: 'fas-folder', title: 'addon.privatefiles.files', - page: 'addon-privatefiles', + page: AddonPrivateFilesMainMenuHandler.PAGE_NAME, subPage: 'root', class: 'addon-privatefiles-handler', }; diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 1e3f8e5c1..58f5f1650 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -12,35 +12,49 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { NgModule } from '@angular/core'; -import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; +import { InjectionToken, Injector, ModuleWithProviders, NgModule } from '@angular/core'; +import { PreloadAllModules, RouterModule, ROUTES, Routes } from '@angular/router'; -import { AuthGuard } from '@guards/auth'; +import { CoreArray } from '@singletons/array'; -const routes: Routes = [ - { - path: 'login', - loadChildren: () => import('@features/login/login.module').then( m => m.CoreLoginModule), - }, - { - path: 'settings', - loadChildren: () => import('@features/settings/settings.module').then( m => m.CoreSettingsModule), - }, - { - path: '', - loadChildren: () => import('@features/mainmenu/mainmenu.module').then( m => m.CoreMainMenuModule), - canActivate: [AuthGuard], - canLoad: [AuthGuard], - }, -]; +function buildAppRoutes(injector: Injector): Routes { + return CoreArray.flatten(injector.get(APP_ROUTES, [])); +} + +export type ModuleRoutes = { children: Routes; siblings: Routes }; + +export function resolveModuleRoutes(injector: Injector, token: InjectionToken[]>): ModuleRoutes { + const routes = injector.get(token, []); + + return { + children: CoreArray.flatten(routes.map(r => r.children || [])), + siblings: CoreArray.flatten(routes.map(r => r.siblings || [])), + }; +} + +export const APP_ROUTES = new InjectionToken('APP_ROUTES'); @NgModule({ imports: [ - RouterModule.forRoot(routes, { + RouterModule.forRoot([], { preloadingStrategy: PreloadAllModules, relativeLinkResolution: 'corrected', }), ], + providers: [ + { provide: ROUTES, multi: true, useFactory: buildAppRoutes, deps: [Injector] }, + ], exports: [RouterModule], }) -export class AppRoutingModule { } +export class AppRoutingModule { + + static forChild(routes: Routes): ModuleWithProviders { + return { + ngModule: AppRoutingModule, + providers: [ + { provide: APP_ROUTES, multi: true, useValue: routes }, + ], + }; + } + +} diff --git a/src/core/features/course/course.module.ts b/src/core/features/course/course.module.ts index 16c7dcd35..d63ef7568 100644 --- a/src/core/features/course/course.module.ts +++ b/src/core/features/course/course.module.ts @@ -16,19 +16,13 @@ import { NgModule } from '@angular/core'; import { CORE_SITE_SCHEMAS } from '@services/sites'; -import { - SITE_SCHEMA as COURSE_SITE_SCHEMA, - OFFLINE_SITE_SCHEMA as COURSE_OFFLINE_SITE_SCHEMA, -} from './services/db/course'; +import { SITE_SCHEMA, OFFLINE_SITE_SCHEMA } from './services/db/course'; @NgModule({ providers: [ { provide: CORE_SITE_SCHEMAS, - useValue: [ - COURSE_SITE_SCHEMA, - COURSE_OFFLINE_SITE_SCHEMA, - ], + useValue: [SITE_SCHEMA, OFFLINE_SITE_SCHEMA], multi: true, }, ], diff --git a/src/core/features/courses/courses-lazy.module.ts b/src/core/features/courses/courses-lazy.module.ts new file mode 100644 index 000000000..09095bed1 --- /dev/null +++ b/src/core/features/courses/courses-lazy.module.ts @@ -0,0 +1,64 @@ +// (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 { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; + +const routes: Routes = [ + { + path: '', + redirectTo: 'my', + pathMatch: 'full', + }, + { + path: 'categories', + redirectTo: 'categories/root', // Fake "id". + pathMatch: 'full', + }, + { + path: 'categories/:id', + loadChildren: () => + import('./pages/categories/categories.module') + .then(m => m.CoreCoursesCategoriesPageModule), + }, + { + path: 'all', + loadChildren: () => + import('./pages/available-courses/available-courses.module') + .then(m => m.CoreCoursesAvailableCoursesPageModule), + }, + { + path: 'search', + loadChildren: () => + import('./pages/search/search.module') + .then(m => m.CoreCoursesSearchPageModule), + }, + { + path: 'my', + loadChildren: () => + import('./pages/my-courses/my-courses.module') + .then(m => m.CoreCoursesMyCoursesPageModule), + }, + { + path: 'preview', + loadChildren: () => + import('./pages/course-preview/course-preview.module') + .then(m => m.CoreCoursesCoursePreviewPageModule), + }, +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], +}) +export class CoreCoursesLazyModule {} diff --git a/src/core/features/courses/courses.module.ts b/src/core/features/courses/courses.module.ts index cb439bc61..a51f0b3b7 100644 --- a/src/core/features/courses/courses.module.ts +++ b/src/core/features/courses/courses.module.ts @@ -13,82 +13,43 @@ // limitations under the License. import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; -import { CoreHomeRoutingModule } from '@features/mainmenu/pages/home/home-routing.module'; -import { CoreHomeDelegate } from '@features/mainmenu/services/home-delegate'; +import { Routes } from '@angular/router'; + +import { CoreMainMenuHomeRoutingModule } from '@features/mainmenu/pages/home/home-routing.module'; +import { CoreMainMenuHomeDelegate } from '@features/mainmenu/services/home-delegate'; + import { CoreDashboardHomeHandler } from './services/handlers/dashboard-home'; import { CoreCoursesMyCoursesHomeHandler } from './services/handlers/my-courses.home'; -const homeRoutes: Routes = [ +const mainMenuHomeChildrenRoutes: Routes = [ { - path: 'dashboard', - loadChildren: () => - import('@features/courses/pages/dashboard/dashboard.module').then(m => m.CoreCoursesDashboardPageModule), + path: '', + pathMatch: 'full', + redirectTo: CoreDashboardHomeHandler.PAGE_NAME, }, { - path: 'courses/my', - loadChildren: () => - import('@features/courses/pages/my-courses/my-courses.module') - .then(m => m.CoreCoursesMyCoursesPageModule), + path: CoreDashboardHomeHandler.PAGE_NAME, + loadChildren: () => import('./pages/dashboard/dashboard.module').then(m => m.CoreCoursesDashboardPageModule), + }, + { + path: CoreCoursesMyCoursesHomeHandler.PAGE_NAME, + loadChildren: () => import('./pages/my-courses/my-courses.module').then(m => m.CoreCoursesMyCoursesPageModule), }, ]; -const routes: Routes = [ +const mainMenuHomeSiblingRoutes: Routes = [ { path: 'courses', - children: [ - { - path: '', - redirectTo: 'my', - pathMatch: 'full', - }, - { - path: 'categories', - redirectTo: 'categories/root', // Fake "id". - pathMatch: 'full', - }, - { - path: 'categories/:id', - loadChildren: () => - import('@features/courses/pages/categories/categories.module') - .then(m => m.CoreCoursesCategoriesPageModule), - }, - { - path: 'all', - loadChildren: () => - import('@features/courses/pages/available-courses/available-courses.module') - .then(m => m.CoreCoursesAvailableCoursesPageModule), - }, - { - path: 'search', - loadChildren: () => - import('@features/courses/pages/search/search.module') - .then(m => m.CoreCoursesSearchPageModule), - }, - { - path: 'my', - loadChildren: () => - import('@features/courses/pages/my-courses/my-courses.module') - .then(m => m.CoreCoursesMyCoursesPageModule), - }, - { - path: 'preview', - loadChildren: () => - import('@features/courses/pages/course-preview/course-preview.module') - .then(m => m.CoreCoursesCoursePreviewPageModule), - }, - ], + loadChildren: () => import('./courses-lazy.module').then(m => m.CoreCoursesLazyModule), }, ]; @NgModule({ imports: [ - CoreHomeRoutingModule.forChild(homeRoutes), - RouterModule.forChild(routes), - ], - exports: [ - CoreHomeRoutingModule, - RouterModule, + CoreMainMenuHomeRoutingModule.forChild({ + children: mainMenuHomeChildrenRoutes, + siblings: mainMenuHomeSiblingRoutes, + }), ], providers: [ CoreDashboardHomeHandler, @@ -98,7 +59,7 @@ const routes: Routes = [ export class CoreCoursesModule { constructor( - homeDelegate: CoreHomeDelegate, + homeDelegate: CoreMainMenuHomeDelegate, coursesDashboardHandler: CoreDashboardHomeHandler, coursesMyCoursesHandler: CoreCoursesMyCoursesHomeHandler, ) { diff --git a/src/core/features/courses/pages/dashboard/dashboard.ts b/src/core/features/courses/pages/dashboard/dashboard.ts index 16382a526..8e9d0ce84 100644 --- a/src/core/features/courses/pages/dashboard/dashboard.ts +++ b/src/core/features/courses/pages/dashboard/dashboard.ts @@ -90,7 +90,7 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy { * Go to search courses. */ openSearch(): void { - this.navCtrl.navigateForward(['/courses/search']); + this.navCtrl.navigateForward(['/main/home/courses/search']); } /** diff --git a/src/core/features/courses/pages/my-courses/my-courses.ts b/src/core/features/courses/pages/my-courses/my-courses.ts index dc4211730..0799240c8 100644 --- a/src/core/features/courses/pages/my-courses/my-courses.ts +++ b/src/core/features/courses/pages/my-courses/my-courses.ts @@ -200,7 +200,7 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy { * Go to search courses. */ openSearch(): void { - this.navCtrl.navigateForward(['/courses/search']); + this.navCtrl.navigateForward(['/main/home/courses/search']); } /** diff --git a/src/core/features/courses/services/handlers/dashboard-home.ts b/src/core/features/courses/services/handlers/dashboard-home.ts index 73aad4613..f98e53457 100644 --- a/src/core/features/courses/services/handlers/dashboard-home.ts +++ b/src/core/features/courses/services/handlers/dashboard-home.ts @@ -13,13 +13,15 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreHomeHandler, CoreHomeHandlerToDisplay } from '@features/mainmenu/services/home-delegate'; +import { CoreMainMenuHomeHandler, CoreMainMenuHomeHandlerToDisplay } from '@features/mainmenu/services/home-delegate'; /** * Handler to add dashboard into home page. */ Injectable(); -export class CoreDashboardHomeHandler implements CoreHomeHandler { +export class CoreDashboardHomeHandler implements CoreMainMenuHomeHandler { + + static readonly PAGE_NAME = 'dashboard'; name = 'CoreCoursesDashboard'; priority = 1100; @@ -50,10 +52,10 @@ export class CoreDashboardHomeHandler implements CoreHomeHandler { * * @return Data needed to render the handler. */ - getDisplayData(): CoreHomeHandlerToDisplay { + getDisplayData(): CoreMainMenuHomeHandlerToDisplay { return { title: 'core.courses.mymoodle', - page: 'dashboard', + page: CoreDashboardHomeHandler.PAGE_NAME, class: 'core-courses-dashboard-handler', icon: 'fas-tachometer-alt', selectPriority: 1000, diff --git a/src/core/features/courses/services/handlers/my-courses.home.ts b/src/core/features/courses/services/handlers/my-courses.home.ts index 3ca7dfe5b..440bff94d 100644 --- a/src/core/features/courses/services/handlers/my-courses.home.ts +++ b/src/core/features/courses/services/handlers/my-courses.home.ts @@ -13,13 +13,15 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreHomeHandler, CoreHomeHandlerToDisplay } from '@features/mainmenu/services/home-delegate'; +import { CoreMainMenuHomeHandler, CoreMainMenuHomeHandlerToDisplay } from '@features/mainmenu/services/home-delegate'; /** * Handler to add my courses into home page. */ Injectable(); -export class CoreCoursesMyCoursesHomeHandler implements CoreHomeHandler { +export class CoreCoursesMyCoursesHomeHandler implements CoreMainMenuHomeHandler { + + static readonly PAGE_NAME = 'courses'; name = 'CoreCoursesMyCourses'; priority = 900; @@ -50,10 +52,10 @@ export class CoreCoursesMyCoursesHomeHandler implements CoreHomeHandler { * * @return Data needed to render the handler. */ - getDisplayData(): CoreHomeHandlerToDisplay { + getDisplayData(): CoreMainMenuHomeHandlerToDisplay { return { title: 'core.courses.mycourses', - page: 'courses/my', + page: CoreCoursesMyCoursesHomeHandler.PAGE_NAME, class: 'core-courses-my-courses-handler', icon: 'fas-graduation-cap', selectPriority: 900, diff --git a/src/core/features/features.module.ts b/src/core/features/features.module.ts index 29874d84d..c56c3a632 100644 --- a/src/core/features/features.module.ts +++ b/src/core/features/features.module.ts @@ -17,20 +17,22 @@ import { NgModule } from '@angular/core'; import { CoreCourseModule } from './course/course.module'; import { CoreCoursesModule } from './courses/courses.module'; import { CoreEmulatorModule } from './emulator/emulator.module'; -import { CoreFileUploaderInitModule } from './fileuploader/fileuploader-init.module'; +import { CoreFileUploaderModule } from './fileuploader/fileuploader.module'; import { CoreLoginModule } from './login/login.module'; -import { CoreSettingsInitModule } from './settings/settings-init.module'; -import { CoreSiteHomeInitModule } from './sitehome/sitehome-init.module'; +import { CoreMainMenuModule } from './mainmenu/mainmenu.module'; +import { CoreSettingsModule } from './settings/settings.module'; +import { CoreSiteHomeModule } from './sitehome/sitehome.module'; @NgModule({ imports: [ - CoreEmulatorModule, - CoreLoginModule, CoreCourseModule, CoreCoursesModule, - CoreSettingsInitModule, - CoreFileUploaderInitModule, - CoreSiteHomeInitModule, + CoreEmulatorModule, + CoreFileUploaderModule, + CoreLoginModule, + CoreMainMenuModule, + CoreSettingsModule, + CoreSiteHomeModule, ], }) export class CoreFeaturesModule {} diff --git a/src/core/features/fileuploader/fileuploader-init.module.ts b/src/core/features/fileuploader/fileuploader.module.ts similarity index 97% rename from src/core/features/fileuploader/fileuploader-init.module.ts rename to src/core/features/fileuploader/fileuploader.module.ts index 2486cb005..819b0a747 100644 --- a/src/core/features/fileuploader/fileuploader-init.module.ts +++ b/src/core/features/fileuploader/fileuploader.module.ts @@ -33,7 +33,7 @@ import { CoreFileUploaderVideoHandler } from './services/handlers/video'; CoreFileUploaderVideoHandler, ], }) -export class CoreFileUploaderInitModule { +export class CoreFileUploaderModule { constructor( delegate: CoreFileUploaderDelegate, diff --git a/src/core/features/login/login-routing.module.ts b/src/core/features/login/login-lazy.module.ts similarity index 73% rename from src/core/features/login/login-routing.module.ts rename to src/core/features/login/login-lazy.module.ts index 94a29f292..dfe077134 100644 --- a/src/core/features/login/login-routing.module.ts +++ b/src/core/features/login/login-lazy.module.ts @@ -14,6 +14,14 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { CommonModule } from '@angular/common'; +import { IonicModule } from '@ionic/angular'; +import { TranslateModule } from '@ngx-translate/core'; + +import { CoreComponentsModule } from '@components/components.module'; +import { CoreDirectivesModule } from '@directives/directives.module'; +import { CoreLoginSiteHelpComponent } from './components/site-help/site-help'; +import { CoreLoginSiteOnboardingComponent } from './components/site-onboarding/site-onboarding'; const routes: Routes = [ { @@ -62,7 +70,17 @@ const routes: Routes = [ ]; @NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule], + imports: [ + CommonModule, + IonicModule, + TranslateModule.forChild(), + CoreComponentsModule, + CoreDirectivesModule, + RouterModule.forChild(routes), + ], + declarations: [ + CoreLoginSiteHelpComponent, + CoreLoginSiteOnboardingComponent, + ], }) -export class CoreLoginRoutingModule {} +export class CoreLoginLazyModule {} diff --git a/src/core/features/login/login.module.ts b/src/core/features/login/login.module.ts index 24294daaa..f17cb2bbe 100644 --- a/src/core/features/login/login.module.ts +++ b/src/core/features/login/login.module.ts @@ -13,32 +13,18 @@ // limitations under the License. import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { IonicModule } from '@ionic/angular'; -import { TranslateModule } from '@ngx-translate/core'; +import { Routes } from '@angular/router'; -import { CoreComponentsModule } from '@components/components.module'; -import { CoreDirectivesModule } from '@directives/directives.module'; -import { CoreLoginRoutingModule } from './login-routing.module'; -import { CoreLoginSiteHelpComponent } from './components/site-help/site-help'; -import { CoreLoginSiteOnboardingComponent } from './components/site-onboarding/site-onboarding'; +import { AppRoutingModule } from '@/app/app-routing.module'; + +const appRoutes: Routes = [ + { + path: 'login', + loadChildren: () => import('./login-lazy.module').then(m => m.CoreLoginLazyModule), + }, +]; @NgModule({ - imports: [ - CoreLoginRoutingModule, - CommonModule, - IonicModule, - TranslateModule.forChild(), - CoreComponentsModule, - CoreDirectivesModule, - ], - declarations: [ - CoreLoginSiteHelpComponent, - CoreLoginSiteOnboardingComponent, - ], - exports: [ - CoreLoginSiteHelpComponent, - CoreLoginSiteOnboardingComponent, - ], + imports: [AppRoutingModule.forChild(appRoutes)], }) export class CoreLoginModule {} diff --git a/src/core/features/mainmenu/mainmenu-lazy.module.ts b/src/core/features/mainmenu/mainmenu-lazy.module.ts new file mode 100644 index 000000000..7fb36e1c0 --- /dev/null +++ b/src/core/features/mainmenu/mainmenu-lazy.module.ts @@ -0,0 +1,75 @@ +// (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 { CommonModule } from '@angular/common'; +import { Injector, NgModule } from '@angular/core'; +import { ROUTES, Routes } from '@angular/router'; +import { CoreComponentsModule } from '@components/components.module'; +import { CoreDirectivesModule } from '@directives/directives.module'; +import { IonicModule } from '@ionic/angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CorePipesModule } from '@pipes/pipes.module'; + +import { resolveModuleRoutes } from '@/app/app-routing.module'; + +import { MAIN_MENU_ROUTES } from './mainmenu-routing.module'; +import { CoreMainMenuPage } from './pages/menu/menu'; +import { CoreMainMenuHomeHandler } from './services/handlers/mainmenu'; + +function buildRoutes(injector: Injector): Routes { + const routes = resolveModuleRoutes(injector, MAIN_MENU_ROUTES); + + return [ + { + path: '', + component: CoreMainMenuPage, + children: [ + { + path: '', + pathMatch: 'full', + redirectTo: CoreMainMenuHomeHandler.PAGE_NAME, + }, + { + path: CoreMainMenuHomeHandler.PAGE_NAME, + loadChildren: () => import('./pages/home/home.module').then(m => m.CoreMainMenuHomePageModule), + }, + { + path: 'more', + loadChildren: () => import('./pages/more/more.module').then(m => m.CoreMainMenuMorePageModule), + }, + ...routes.children, + ], + }, + ...routes.siblings, + ]; +} + +@NgModule({ + imports: [ + CommonModule, + IonicModule, + TranslateModule, + CoreComponentsModule, + CoreDirectivesModule, + CorePipesModule, + ], + declarations: [ + CoreMainMenuPage, + ], + providers: [ + CoreMainMenuHomeHandler, + { provide: ROUTES, multi: true, useFactory: buildRoutes, deps: [Injector] }, + ], +}) +export class CoreMainMenuLazyModule {} diff --git a/src/core/features/mainmenu/mainmenu-routing.module.ts b/src/core/features/mainmenu/mainmenu-routing.module.ts index 173268d8d..c30b45479 100644 --- a/src/core/features/mainmenu/mainmenu-routing.module.ts +++ b/src/core/features/mainmenu/mainmenu-routing.module.ts @@ -12,54 +12,16 @@ // 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 { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core'; -import { CoreArray } from '@singletons/array'; - -import { CoreMainMenuPage } from './pages/menu/menu'; -import { CoreMainMenuMorePage } from './pages/more/more'; - -function buildMainMenuRoutes(injector: Injector): Routes { - const routes = CoreArray.flatten(injector.get(MAIN_MENU_ROUTES, [])); - - return [ - { - path: '', - component: CoreMainMenuPage, - children: [ - { - path: 'home', // @todo: Add this route dynamically. - loadChildren: () => import('./pages/home/home.module').then(m => m.CoreHomePageModule), - }, - { - path: 'more', - children: [ - { - path: '', - component: CoreMainMenuMorePage, - }, - ...routes, - ], - }, - ...routes, - // @todo handle 404. - ], - }, - ]; -} +import { ModuleRoutes } from '@/app/app-routing.module'; export const MAIN_MENU_ROUTES = new InjectionToken('MAIN_MENU_ROUTES'); -@NgModule({ - providers: [ - { provide: ROUTES, multi: true, useFactory: buildMainMenuRoutes, deps: [Injector] }, - ], - exports: [RouterModule], -}) +@NgModule() export class CoreMainMenuRoutingModule { - static forChild(routes: Routes): ModuleWithProviders { + static forChild(routes: Partial): ModuleWithProviders { return { ngModule: CoreMainMenuRoutingModule, providers: [ diff --git a/src/core/features/mainmenu/mainmenu.module.ts b/src/core/features/mainmenu/mainmenu.module.ts index e01609f8b..384ecdd2a 100644 --- a/src/core/features/mainmenu/mainmenu.module.ts +++ b/src/core/features/mainmenu/mainmenu.module.ts @@ -13,44 +13,36 @@ // limitations under the License. import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; +import { Routes } from '@angular/router'; +import { AuthGuard } from '@guards/auth'; -import { IonicModule } from '@ionic/angular'; -import { TranslateModule } from '@ngx-translate/core'; - -import { CoreComponentsModule } from '@components/components.module'; -import { CoreDirectivesModule } from '@directives/directives.module'; +import { AppRoutingModule } from '@/app/app-routing.module'; import { CoreMainMenuDelegate } from './services/mainmenu-delegate'; +import { CoreMainMenuHomeHandler } from './services/handlers/mainmenu'; -import { CoreMainMenuRoutingModule } from './mainmenu-routing.module'; -import { CoreMainMenuPage } from './pages/menu/menu'; -import { CoreMainMenuMorePage } from './pages/more/more'; -import { CoreHomeMainMenuHandler } from './services/handlers/mainmenu'; - +const appRoutes: Routes = [ + { + path: '', + pathMatch: 'full', + redirectTo: 'main', + }, + { + path: 'main', + loadChildren: () => import('./mainmenu-lazy.module').then(m => m.CoreMainMenuLazyModule), + canActivate: [AuthGuard], + canLoad: [AuthGuard], + }, +]; @NgModule({ - imports: [ - CommonModule, - IonicModule, - CoreMainMenuRoutingModule, - TranslateModule.forChild(), - CoreComponentsModule, - CoreDirectivesModule, - ], - declarations: [ - CoreMainMenuPage, - CoreMainMenuMorePage, - ], - providers: [ - CoreHomeMainMenuHandler, - ], + imports: [AppRoutingModule.forChild(appRoutes)], }) export class CoreMainMenuModule { constructor( mainMenuDelegate: CoreMainMenuDelegate, - homeMainMenuHandler: CoreHomeMainMenuHandler, + homeMainMenuHandler: CoreMainMenuHomeHandler, ) { mainMenuDelegate.registerHandler(homeMainMenuHandler); } diff --git a/src/core/features/mainmenu/pages/home/home-routing.module.ts b/src/core/features/mainmenu/pages/home/home-routing.module.ts index 8689eea49..73b3c4dc1 100644 --- a/src/core/features/mainmenu/pages/home/home-routing.module.ts +++ b/src/core/features/mainmenu/pages/home/home-routing.module.ts @@ -12,43 +12,20 @@ // 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 { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core'; -import { CoreArray } from '@singletons/array'; +import { ModuleRoutes } from '@/app/app-routing.module'; -import { CoreHomePage } from './home'; +export const MAIN_MENU_HOME_ROUTES = new InjectionToken('MAIN_MENU_HOME_ROUTES'); -function buildHomeRoutes(injector: Injector): Routes { - const routes = CoreArray.flatten(injector.get(HOME_ROUTES, [])); +@NgModule() +export class CoreMainMenuHomeRoutingModule { - 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 { + static forChild(routes: Partial): ModuleWithProviders { return { - ngModule: CoreHomeRoutingModule, + ngModule: CoreMainMenuHomeRoutingModule, providers: [ - { provide: HOME_ROUTES, multi: true, useValue: routes }, + { provide: MAIN_MENU_HOME_ROUTES, multi: true, useValue: routes }, ], }; } diff --git a/src/core/features/mainmenu/pages/home/home.module.ts b/src/core/features/mainmenu/pages/home/home.module.ts index 1a84963d5..674de5397 100644 --- a/src/core/features/mainmenu/pages/home/home.module.ts +++ b/src/core/features/mainmenu/pages/home/home.module.ts @@ -12,16 +12,31 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { NgModule } from '@angular/core'; +import { Injector, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; +import { RouterModule, ROUTES, Routes } from '@angular/router'; import { IonicModule } from '@ionic/angular'; import { TranslateModule } from '@ngx-translate/core'; +import { resolveModuleRoutes } from '@/app/app-routing.module'; import { CoreComponentsModule } from '@components/components.module'; import { CoreDirectivesModule } from '@directives/directives.module'; -import { CoreHomePage } from './home'; -import { CoreHomeRoutingModule } from './home-routing.module'; +import { CoreMainMenuHomePage } from './home'; +import { MAIN_MENU_HOME_ROUTES } from './home-routing.module'; + +function buildRoutes(injector: Injector): Routes { + const routes = resolveModuleRoutes(injector, MAIN_MENU_HOME_ROUTES); + + return [ + { + path: '', + component: CoreMainMenuHomePage, + children: routes.children, + }, + ...routes.siblings, + ]; +} @NgModule({ imports: [ @@ -30,10 +45,15 @@ import { CoreHomeRoutingModule } from './home-routing.module'; TranslateModule.forChild(), CoreComponentsModule, CoreDirectivesModule, - CoreHomeRoutingModule, + ], + providers: [ + { provide: ROUTES, multi: true, useFactory: buildRoutes, deps: [Injector] }, ], declarations: [ - CoreHomePage, + CoreMainMenuHomePage, + ], + exports: [ + RouterModule, ], }) -export class CoreHomePageModule {} +export class CoreMainMenuHomePageModule {} diff --git a/src/core/features/mainmenu/pages/home/home.ts b/src/core/features/mainmenu/pages/home/home.ts index b7f9e7611..7d505d6dc 100644 --- a/src/core/features/mainmenu/pages/home/home.ts +++ b/src/core/features/mainmenu/pages/home/home.ts @@ -18,39 +18,36 @@ import { Subscription } from 'rxjs'; import { CoreSites } from '@services/sites'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreTabsComponent } from '@components/tabs/tabs'; -import { CoreHomeDelegate, CoreHomeHandlerToDisplay } from '../../services/home-delegate'; +import { CoreMainMenuHomeDelegate, CoreMainMenuHomeHandlerToDisplay } from '../../services/home-delegate'; /** * Page that displays the Home. */ @Component({ - selector: 'page-core-home', + selector: 'page-core-mainmenu-home', templateUrl: 'home.html', styleUrls: ['home.scss'], }) -export class CoreHomePage implements OnInit { +export class CoreMainMenuHomePage implements OnInit { @ViewChild(CoreTabsComponent) tabsComponent?: CoreTabsComponent; - siteName!: string; - tabs: CoreHomeHandlerToDisplay[] = []; + tabs: CoreMainMenuHomeHandlerToDisplay[] = []; loaded = false; selectedTab?: number; protected subscription?: Subscription; protected updateSiteObserver?: CoreEventObserver; - constructor( - protected homeDelegate: CoreHomeDelegate, - ) { - this.loadSiteName(); - } + constructor(protected homeDelegate: CoreMainMenuHomeDelegate) {} /** * Initialize the component. */ ngOnInit(): void { + this.loadSiteName(); + this.subscription = this.homeDelegate.getHandlersObservable().subscribe((handlers) => { handlers && this.initHandlers(handlers); }); @@ -64,10 +61,10 @@ export class CoreHomePage implements OnInit { /** * Init handlers on change (size or handlers). */ - initHandlers(handlers: CoreHomeHandlerToDisplay[]): void { + initHandlers(handlers: CoreMainMenuHomeHandlerToDisplay[]): void { // Re-build the list of tabs. If a handler is already in the list, use existing object to prevent re-creating the tab. - const newTabs: CoreHomeHandlerToDisplay[] = handlers.map((handler) => { - handler.page = '/home/' + handler.page; + const newTabs: CoreMainMenuHomeHandlerToDisplay[] = handlers.map((handler) => { + handler.page = '/main/home/' + handler.page; // Check if the handler is already in the tabs list. If so, use it. const tab = this.tabs.find((tab) => tab.title == handler.title); diff --git a/src/core/features/mainmenu/pages/more/more-routing.module.ts b/src/core/features/mainmenu/pages/more/more-routing.module.ts new file mode 100644 index 000000000..11ed18c24 --- /dev/null +++ b/src/core/features/mainmenu/pages/more/more-routing.module.ts @@ -0,0 +1,33 @@ +// (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): ModuleWithProviders { + return { + ngModule: CoreMainMenuMoreRoutingModule, + providers: [ + { provide: MAIN_MENU_MORE_ROUTES, multi: true, useValue: routes }, + ], + }; + } + +} diff --git a/src/core/features/mainmenu/pages/more/more.module.ts b/src/core/features/mainmenu/pages/more/more.module.ts new file mode 100644 index 000000000..b3e48f897 --- /dev/null +++ b/src/core/features/mainmenu/pages/more/more.module.ts @@ -0,0 +1,59 @@ +// (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 { Injector, NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { RouterModule, ROUTES, Routes } from '@angular/router'; +import { IonicModule } from '@ionic/angular'; +import { TranslateModule } from '@ngx-translate/core'; + +import { resolveModuleRoutes } from '@/app/app-routing.module'; +import { CoreComponentsModule } from '@components/components.module'; +import { CoreDirectivesModule } from '@directives/directives.module'; + +import { CoreMainMenuMorePage } from './more'; +import { MAIN_MENU_MORE_ROUTES } from './more-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({ + imports: [ + CommonModule, + IonicModule, + TranslateModule.forChild(), + CoreComponentsModule, + CoreDirectivesModule, + ], + providers: [ + { provide: ROUTES, multi: true, useFactory: buildRoutes, deps: [Injector] }, + ], + declarations: [ + CoreMainMenuMorePage, + ], + exports: [ + RouterModule, + ], +}) +export class CoreMainMenuMorePageModule {} diff --git a/src/core/features/mainmenu/services/handlers/mainmenu.ts b/src/core/features/mainmenu/services/handlers/mainmenu.ts index 7fe947fff..06c4a8046 100644 --- a/src/core/features/mainmenu/services/handlers/mainmenu.ts +++ b/src/core/features/mainmenu/services/handlers/mainmenu.ts @@ -18,10 +18,12 @@ import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../mainmenu-delega /** * Handler to add Home into main menu. */ -Injectable(); -export class CoreHomeMainMenuHandler implements CoreMainMenuHandler { +@Injectable({ providedIn: 'root' }) +export class CoreMainMenuHomeHandler implements CoreMainMenuHandler { - name = 'CoreHome'; + static readonly PAGE_NAME = 'home'; + + name = 'CoreMainMenuHome'; priority = 1100; /** @@ -54,7 +56,7 @@ export class CoreHomeMainMenuHandler implements CoreMainMenuHandler { return { icon: 'fa-home', title: 'core.mainmenu.home', - page: 'home', + page: CoreMainMenuHomeHandler.PAGE_NAME, // @todo: subPage? The page can change due to core-tabs. class: 'core-home-handler', }; diff --git a/src/core/features/mainmenu/services/home-delegate.ts b/src/core/features/mainmenu/services/home-delegate.ts index 170a36311..67eca45e5 100644 --- a/src/core/features/mainmenu/services/home-delegate.ts +++ b/src/core/features/mainmenu/services/home-delegate.ts @@ -21,12 +21,12 @@ import { CoreSortedDelegate } from '@classes/delegate-sorted'; /** * Interface that all home handlers must implement. */ -export type CoreHomeHandler = CoreDelegateDisplayHandler; +export type CoreMainMenuHomeHandler = CoreDelegateDisplayHandler; /** * Data needed to render a main menu handler. It's returned by the handler. */ -export interface CoreHomeHandlerData { +export interface CoreMainMenuHomeHandlerData { /** * Name of the page to load for the handler. */ @@ -71,7 +71,7 @@ export interface CoreHomeHandlerData { /** * Data returned by the delegate for each handler. */ -export interface CoreHomeHandlerToDisplay extends CoreDelegateToDisplay, CoreHomeHandlerData { +export interface CoreMainMenuHomeHandlerToDisplay extends CoreDelegateToDisplay, CoreMainMenuHomeHandlerData { /** * Priority to select handler. */ @@ -85,12 +85,12 @@ export interface CoreHomeHandlerToDisplay extends CoreDelegateToDisplay, CoreHom @Injectable({ providedIn: 'root', }) -export class CoreHomeDelegate extends CoreSortedDelegate { +export class CoreMainMenuHomeDelegate extends CoreSortedDelegate { - protected featurePrefix = 'CoreHomeDelegate_'; + protected featurePrefix = 'CoreMainMenuHomeDelegate_'; constructor() { - super('CoreHomeDelegate'); + super('CoreMainMenuHomeDelegate'); } } diff --git a/src/core/features/settings/settings-init.module.ts b/src/core/features/settings/settings-init.module.ts deleted file mode 100644 index c8d1b44e9..000000000 --- a/src/core/features/settings/settings-init.module.ts +++ /dev/null @@ -1,48 +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 { NgModule } from '@angular/core'; -import { Routes } from '@angular/router'; - -import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module'; - -const routes: Routes = [ - { - path: 'settings', - loadChildren: () => import('@features/settings/settings.module').then(m => m.CoreSettingsModule), - }, - { - path: 'preferences', - loadChildren: () => import('@features/settings/pages/site/site.module').then(m => m.CoreSitePreferencesPageModule), - }, -]; - -@NgModule({ - imports: [ - CoreMainMenuRoutingModule.forChild(routes), - ], - exports: [ - CoreMainMenuRoutingModule, - ], - providers: [ - ], -}) -export class CoreSettingsInitModule { - - constructor() { - // @todo - // settingsHelper.initDomSettings(); - } - -} diff --git a/src/core/features/settings/settings-routing.module.ts b/src/core/features/settings/settings-lazy.module.ts similarity index 80% rename from src/core/features/settings/settings-routing.module.ts rename to src/core/features/settings/settings-lazy.module.ts index 02bafefab..5177d0c9f 100644 --- a/src/core/features/settings/settings-routing.module.ts +++ b/src/core/features/settings/settings-lazy.module.ts @@ -26,14 +26,12 @@ const routes: Routes = [ }, { path: 'spaceusage', - loadChildren: () => - import('@features/settings/pages/space-usage/space-usage.module') - .then(m => m.CoreSettingsSpaceUsagePageModule), + loadChildren: () => import('./pages/space-usage/space-usage.module').then(m => m.CoreSettingsSpaceUsagePageModule), }, { path: 'sync', loadChildren: () => - import('@features/settings/pages/synchronization/synchronization.module') + import('./pages/synchronization/synchronization.module') .then(m => m.CoreSettingsSynchronizationPageModule), }, { @@ -44,6 +42,5 @@ const routes: Routes = [ @NgModule({ imports: [RouterModule.forChild(routes)], - exports: [RouterModule], }) -export class CoreSettingsRoutingModule {} +export class CoreSettingsLazyModule {} diff --git a/src/core/features/settings/settings.module.ts b/src/core/features/settings/settings.module.ts index b9ed32dce..22dbbac9e 100644 --- a/src/core/features/settings/settings.module.ts +++ b/src/core/features/settings/settings.module.ts @@ -12,13 +12,44 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { NgModule } from '@angular/core'; +import { APP_INITIALIZER, NgModule } from '@angular/core'; +import { Routes } from '@angular/router'; -import { CoreSettingsRoutingModule } from './settings-routing.module'; +import { AppRoutingModule } from '@/app/app-routing.module'; +import { CoreMainMenuMoreRoutingModule } from '@features/mainmenu/pages/more/more-routing.module'; + +import { CoreSettingsHelperProvider } from './services/settings-helper'; + +const appRoutes: Routes = [ + { + path: 'settings', + loadChildren: () => import('./settings-lazy.module').then(m => m.CoreSettingsLazyModule), + }, +]; + +const mainMenuMoreRoutes: Routes = [ + { + path: 'settings', + loadChildren: () => import('./settings-lazy.module').then(m => m.CoreSettingsLazyModule), + }, + { + path: 'preferences', + loadChildren: () => import('./pages/site/site.module').then(m => m.CoreSitePreferencesPageModule), + }, +]; @NgModule({ imports: [ - CoreSettingsRoutingModule, + AppRoutingModule.forChild(appRoutes), + CoreMainMenuMoreRoutingModule.forChild({ siblings: mainMenuMoreRoutes }), + ], + providers: [ + { + provide: APP_INITIALIZER, + multi: true, + deps: [CoreSettingsHelperProvider], + useFactory: (helper: CoreSettingsHelperProvider) => () => helper.initDomSettings(), + }, ], }) export class CoreSettingsModule {} diff --git a/src/core/features/sitehome/pages/index/index.ts b/src/core/features/sitehome/pages/index/index.ts index 997df1753..f9ce81694 100644 --- a/src/core/features/sitehome/pages/index/index.ts +++ b/src/core/features/sitehome/pages/index/index.ts @@ -201,7 +201,7 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { * Go to search courses. */ openSearch(): void { - this.navCtrl.navigateForward(['/courses/search']); + this.navCtrl.navigateForward(['/main/home/courses/search']); } /** diff --git a/src/core/features/sitehome/services/handlers/sitehome-home.ts b/src/core/features/sitehome/services/handlers/sitehome-home.ts index cda4f0df5..491f1c498 100644 --- a/src/core/features/sitehome/services/handlers/sitehome-home.ts +++ b/src/core/features/sitehome/services/handlers/sitehome-home.ts @@ -14,14 +14,16 @@ import { Injectable } from '@angular/core'; import { CoreSites } from '@services/sites'; -import { CoreHomeHandler, CoreHomeHandlerToDisplay } from '@features/mainmenu/services/home-delegate'; +import { CoreMainMenuHomeHandler, CoreMainMenuHomeHandlerToDisplay } from '@features/mainmenu/services/home-delegate'; import { CoreSiteHome } from '../sitehome'; /** * Handler to add site home into home page. */ Injectable(); -export class CoreSiteHomeHomeHandler implements CoreHomeHandler { +export class CoreSiteHomeHomeHandler implements CoreMainMenuHomeHandler { + + static readonly PAGE_NAME = 'site'; name = 'CoreSiteHomeDashboard'; priority = 1200; @@ -50,13 +52,13 @@ export class CoreSiteHomeHomeHandler implements CoreHomeHandler { * * @return Data needed to render the handler. */ - getDisplayData(): CoreHomeHandlerToDisplay { + getDisplayData(): CoreMainMenuHomeHandlerToDisplay { const site = CoreSites.instance.getCurrentSite(); const displaySiteHome = site?.getInfo() && site?.getInfo()?.userhomepage === 0; return { title: 'core.sitehome.sitehome', - page: 'sitehome', + page: CoreSiteHomeHomeHandler.PAGE_NAME, class: 'core-sitehome-dashboard-handler', icon: 'fas-home', selectPriority: displaySiteHome ? 1100 : 900, diff --git a/src/core/features/sitehome/sitehome-init.module.ts b/src/core/features/sitehome/sitehome.module.ts similarity index 70% rename from src/core/features/sitehome/sitehome-init.module.ts rename to src/core/features/sitehome/sitehome.module.ts index e66eee94d..dd611c476 100644 --- a/src/core/features/sitehome/sitehome-init.module.ts +++ b/src/core/features/sitehome/sitehome.module.ts @@ -18,36 +18,34 @@ import { Routes } from '@angular/router'; import { CoreSiteHomeIndexLinkHandler } from './services/handlers/index-link'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; import { CoreSiteHomeHomeHandler } from './services/handlers/sitehome-home'; -import { CoreHomeDelegate } from '@features/mainmenu/services/home-delegate'; -import { CoreHomeRoutingModule } from '@features/mainmenu/pages/home/home-routing.module'; +import { CoreMainMenuHomeDelegate } from '@features/mainmenu/services/home-delegate'; +import { CoreMainMenuHomeRoutingModule } from '@features/mainmenu/pages/home/home-routing.module'; -const routes: Routes = [ +const mainMenuHomeRoutes: Routes = [ { - path: 'sitehome', - loadChildren: () => - import('@features/sitehome/pages/index/index.module').then(m => m.CoreSiteHomeIndexPageModule), + path: CoreSiteHomeHomeHandler.PAGE_NAME, + loadChildren: () => import('./pages/index/index.module').then(m => m.CoreSiteHomeIndexPageModule), }, ]; @NgModule({ - imports: [CoreHomeRoutingModule.forChild(routes)], - exports: [CoreHomeRoutingModule], + imports: [CoreMainMenuHomeRoutingModule.forChild({ children: mainMenuHomeRoutes })], + exports: [CoreMainMenuHomeRoutingModule], providers: [ CoreSiteHomeIndexLinkHandler, CoreSiteHomeHomeHandler, ], }) -export class CoreSiteHomeInitModule { +export class CoreSiteHomeModule { constructor( contentLinksDelegate: CoreContentLinksDelegate, - homeDelegate: CoreHomeDelegate, + homeDelegate: CoreMainMenuHomeDelegate, siteHomeIndexLinkHandler: CoreSiteHomeIndexLinkHandler, siteHomeDashboardHandler: CoreSiteHomeHomeHandler, ) { contentLinksDelegate.registerHandler(siteHomeIndexLinkHandler); homeDelegate.registerHandler(siteHomeDashboardHandler); - } }