diff --git a/src/app/core/courses/courses.module.ts b/src/app/core/courses/courses.module.ts index 3665427fd..bbc05d612 100644 --- a/src/app/core/courses/courses.module.ts +++ b/src/app/core/courses/courses.module.ts @@ -13,27 +13,35 @@ // limitations under the License. import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; +import { Routes } from '@angular/router'; +import { CoreHomeRoutingModule } from '../mainmenu/pages/home/home-routing.module'; import { CoreHomeDelegate } from '../mainmenu/services/home.delegate'; -import { CoreCoursesDashboardHandler } from './handlers/dashboard'; +import { CoreCoursesDashboardHandler } from './services/handlers/dashboard'; import { CoreCoursesDashboardPage } from './pages/dashboard/dashboard.page'; const routes: Routes = [ { path: 'dashboard', - component: CoreCoursesDashboardPage, + loadChildren: () => + import('@core/courses/pages/dashboard/dashboard.page.module').then(m => m.CoreCoursesDashboardPageModule), }, ]; @NgModule({ - imports: [RouterModule.forChild(routes)], - declarations: [], + imports: [CoreHomeRoutingModule.forChild(routes)], + exports: [CoreHomeRoutingModule], + providers: [ + CoreCoursesDashboardHandler, + ], }) export class CoreCoursesModule { - constructor(homeDelegate: CoreHomeDelegate) { - homeDelegate.registerHandler(new CoreCoursesDashboardHandler()); + constructor( + homeDelegate: CoreHomeDelegate, + coursesDashboardHandler: CoreCoursesDashboardHandler, + ) { + homeDelegate.registerHandler(coursesDashboardHandler); } } diff --git a/src/app/core/courses/handlers/dashboard.ts b/src/app/core/courses/services/handlers/dashboard.ts similarity index 96% rename from src/app/core/courses/handlers/dashboard.ts rename to src/app/core/courses/services/handlers/dashboard.ts index 0640f7c66..5ef475a46 100644 --- a/src/app/core/courses/handlers/dashboard.ts +++ b/src/app/core/courses/services/handlers/dashboard.ts @@ -12,11 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { Injectable } from '@angular/core'; import { CoreHomeHandler, CoreHomeHandlerData } from '@core/mainmenu/services/home.delegate'; /** * Handler to add Home into main menu. */ +Injectable(); export class CoreCoursesDashboardHandler implements CoreHomeHandler { name = 'CoreCoursesDashboard'; diff --git a/src/app/core/mainmenu/mainmenu.module.ts b/src/app/core/mainmenu/mainmenu.module.ts index 332b231c7..3bcd75734 100644 --- a/src/app/core/mainmenu/mainmenu.module.ts +++ b/src/app/core/mainmenu/mainmenu.module.ts @@ -26,7 +26,7 @@ import { CoreMainMenuDelegate } from './services/mainmenu.delegate'; import { CoreMainMenuRoutingModule } from './mainmenu-routing.module'; import { CoreMainMenuPage } from './pages/menu/menu.page'; import { CoreMainMenuMorePage } from './pages/more/more.page'; -import { CoreHomeMainMenuHandler } from './handlers/mainmenu'; +import { CoreHomeMainMenuHandler } from './services/handlers/mainmenu'; @NgModule({ @@ -42,11 +42,17 @@ import { CoreHomeMainMenuHandler } from './handlers/mainmenu'; CoreMainMenuPage, CoreMainMenuMorePage, ], + providers: [ + CoreHomeMainMenuHandler, + ], }) export class CoreMainMenuModule { - constructor(mainMenuDelegate: CoreMainMenuDelegate) { - mainMenuDelegate.registerHandler(new CoreHomeMainMenuHandler()); + constructor( + mainMenuDelegate: CoreMainMenuDelegate, + homeMainMenuHandler: CoreHomeMainMenuHandler, + ) { + mainMenuDelegate.registerHandler(homeMainMenuHandler); } } diff --git a/src/app/core/mainmenu/pages/home/home.html b/src/app/core/mainmenu/pages/home/home.html index d73d9ecaf..71b4ffdad 100644 --- a/src/app/core/mainmenu/pages/home/home.html +++ b/src/app/core/mainmenu/pages/home/home.html @@ -16,12 +16,10 @@ - - + + - -
Home page
-
+
diff --git a/src/app/core/mainmenu/pages/home/home.page.module.ts b/src/app/core/mainmenu/pages/home/home.page.module.ts index 205739270..c0c90ab3f 100644 --- a/src/app/core/mainmenu/pages/home/home.page.module.ts +++ b/src/app/core/mainmenu/pages/home/home.page.module.ts @@ -14,7 +14,6 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { RouterModule, Routes } from '@angular/router'; import { IonicModule } from '@ionic/angular'; import { TranslateModule } from '@ngx-translate/core'; @@ -22,33 +21,19 @@ import { CoreComponentsModule } from '@components/components.module'; import { CoreDirectivesModule } from '@directives/directives.module'; import { CoreHomePage } from './home.page'; - -const routes: Routes = [ - { - path: '', - component: CoreHomePage, - children: [ - { - path: 'dashboard', // @todo: Add this route dynamically. - loadChildren: () => - import('@core/courses/pages/dashboard/dashboard.page.module').then(m => m.CoreCoursesDashboardPageModule), - }, - ], - }, -]; +import { CoreHomeRoutingModule } from './home-routing.module'; @NgModule({ imports: [ - RouterModule.forChild(routes), CommonModule, IonicModule, TranslateModule.forChild(), CoreComponentsModule, CoreDirectivesModule, + CoreHomeRoutingModule, ], declarations: [ CoreHomePage, ], - exports: [RouterModule], }) export class CoreHomePageModule {} diff --git a/src/app/core/mainmenu/pages/home/home.page.ts b/src/app/core/mainmenu/pages/home/home.page.ts index d0d23aa5f..4a9d1c418 100644 --- a/src/app/core/mainmenu/pages/home/home.page.ts +++ b/src/app/core/mainmenu/pages/home/home.page.ts @@ -55,6 +55,8 @@ export class CoreHomePage implements OnInit { initHandlers(handlers: CoreHomeHandlerToDisplay[]): 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; + // Check if the handler is already in the tabs list. If so, use it. const tab = this.tabs.find((tab) => tab.title == handler.title); @@ -63,9 +65,10 @@ export class CoreHomePage implements OnInit { // Sort them by priority so new handlers are in the right position. .sort((a, b) => (b.priority || 0) - (a.priority || 0)); - if (typeof this.selectedTab == 'undefined') { + if (typeof this.selectedTab == 'undefined' && newTabs.length > 0) { let maxPriority = 0; let maxIndex = 0; + newTabs.forEach((tab, index) => { if ((tab.selectPriority || 0) > maxPriority) { maxPriority = tab.selectPriority || 0; diff --git a/src/app/core/mainmenu/handlers/mainmenu.ts b/src/app/core/mainmenu/services/handlers/mainmenu.ts similarity index 95% rename from src/app/core/mainmenu/handlers/mainmenu.ts rename to src/app/core/mainmenu/services/handlers/mainmenu.ts index 4a6a6dd4c..36a106e6a 100644 --- a/src/app/core/mainmenu/handlers/mainmenu.ts +++ b/src/app/core/mainmenu/services/handlers/mainmenu.ts @@ -12,11 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../services/mainmenu.delegate'; +import { Injectable } from '@angular/core'; +import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../mainmenu.delegate'; /** * Handler to add Home into main menu. */ +Injectable(); export class CoreHomeMainMenuHandler implements CoreMainMenuHandler { name = 'CoreHome'; diff --git a/src/app/core/search/components/search-box/search-box.ts b/src/app/core/search/components/search-box/search-box.ts index 615d5b270..23ab9a6ee 100644 --- a/src/app/core/search/components/search-box/search-box.ts +++ b/src/app/core/search/components/search-box/search-box.ts @@ -17,8 +17,9 @@ import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; -import { CoreSearchHistory, CoreSearchHistoryItem } from '../../services/search-history'; +import { CoreSearchHistory } from '../../services/search-history'; import { Translate } from '@singletons/core.singletons'; +import { CoreSearchHistoryDBRecord } from '../../services/search.history.db'; /** * Component to display a "search box". @@ -59,7 +60,7 @@ export class CoreSearchBoxComponent implements OnInit { searched = ''; // Last search emitted. searchText = ''; - history: CoreSearchHistoryItem[] = []; + history: CoreSearchHistoryDBRecord[] = []; historyShown = false; constructor() {