MOBILE-3565 mainmenu: Add Home routing
parent
58d901f207
commit
f437e92b31
|
@ -13,7 +13,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { NgModule } from '@angular/core';
|
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 { CoreHomeDelegate } from '../mainmenu/services/home.delegate';
|
||||||
import { CoreCoursesDashboardHandler } from './services/handlers/dashboard';
|
import { CoreCoursesDashboardHandler } from './services/handlers/dashboard';
|
||||||
import { CoreCoursesDashboardPage } from './pages/dashboard/dashboard.page';
|
import { CoreCoursesDashboardPage } from './pages/dashboard/dashboard.page';
|
||||||
|
@ -22,12 +23,14 @@ import { CoreCoursesDashboardPage } from './pages/dashboard/dashboard.page';
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: 'dashboard',
|
path: 'dashboard',
|
||||||
component: CoreCoursesDashboardPage,
|
loadChildren: () =>
|
||||||
|
import('@core/courses/pages/dashboard/dashboard.page.module').then(m => m.CoreCoursesDashboardPageModule),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [RouterModule.forChild(routes)],
|
imports: [CoreHomeRoutingModule.forChild(routes)],
|
||||||
|
exports: [CoreHomeRoutingModule],
|
||||||
providers: [
|
providers: [
|
||||||
CoreCoursesDashboardHandler,
|
CoreCoursesDashboardHandler,
|
||||||
],
|
],
|
||||||
|
|
|
@ -16,12 +16,10 @@
|
||||||
</ion-header>
|
</ion-header>
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<!-- @todo -->
|
<!-- @todo -->
|
||||||
<core-loading [hideUntil]="loaded" *ngIf="tabs.length > 0">
|
<core-loading [hideUntil]="loaded">
|
||||||
<core-tabs [selectedIndex]="selectedTab" [hideUntil]="loaded" [tabs]="tabs"></core-tabs>
|
<core-tabs *ngIf="tabs.length > 0" [selectedIndex]="selectedTab" [hideUntil]="loaded" [tabs]="tabs"></core-tabs>
|
||||||
<ng-container *ngIf="tabs.length == 0">
|
<ng-container *ngIf="tabs.length == 0">
|
||||||
<core-empty-box icon="fa-home" [message]="'core.courses.nocourses' | translate">
|
<core-empty-box icon="fas-home" [message]="'core.courses.nocourses' | translate"></core-empty-box>
|
||||||
<div>Home page</div>
|
|
||||||
</core-empty-box>
|
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
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';
|
||||||
|
|
||||||
|
@ -22,33 +21,19 @@ import { CoreComponentsModule } from '@components/components.module';
|
||||||
import { CoreDirectivesModule } from '@directives/directives.module';
|
import { CoreDirectivesModule } from '@directives/directives.module';
|
||||||
|
|
||||||
import { CoreHomePage } from './home.page';
|
import { CoreHomePage } from './home.page';
|
||||||
|
import { CoreHomeRoutingModule } from './home-routing.module';
|
||||||
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),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
RouterModule.forChild(routes),
|
|
||||||
CommonModule,
|
CommonModule,
|
||||||
IonicModule,
|
IonicModule,
|
||||||
TranslateModule.forChild(),
|
TranslateModule.forChild(),
|
||||||
CoreComponentsModule,
|
CoreComponentsModule,
|
||||||
CoreDirectivesModule,
|
CoreDirectivesModule,
|
||||||
|
CoreHomeRoutingModule,
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
CoreHomePage,
|
CoreHomePage,
|
||||||
],
|
],
|
||||||
exports: [RouterModule],
|
|
||||||
})
|
})
|
||||||
export class CoreHomePageModule {}
|
export class CoreHomePageModule {}
|
||||||
|
|
|
@ -55,6 +55,8 @@ export class CoreHomePage implements OnInit {
|
||||||
initHandlers(handlers: CoreHomeHandlerToDisplay[]): void {
|
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.
|
// 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) => {
|
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.
|
// Check if the handler is already in the tabs list. If so, use it.
|
||||||
const tab = this.tabs.find((tab) => tab.title == handler.title);
|
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 them by priority so new handlers are in the right position.
|
||||||
.sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
.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 maxPriority = 0;
|
||||||
let maxIndex = 0;
|
let maxIndex = 0;
|
||||||
|
|
||||||
newTabs.forEach((tab, index) => {
|
newTabs.forEach((tab, index) => {
|
||||||
if ((tab.selectPriority || 0) > maxPriority) {
|
if ((tab.selectPriority || 0) > maxPriority) {
|
||||||
maxPriority = tab.selectPriority || 0;
|
maxPriority = tab.selectPriority || 0;
|
||||||
|
|
Loading…
Reference in New Issue