MOBILE-3565 mainmenu: Add Home routing
parent
58d901f207
commit
f437e92b31
|
@ -13,7 +13,8 @@
|
|||
// 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 './services/handlers/dashboard';
|
||||
import { CoreCoursesDashboardPage } from './pages/dashboard/dashboard.page';
|
||||
|
@ -22,12 +23,14 @@ 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)],
|
||||
imports: [CoreHomeRoutingModule.forChild(routes)],
|
||||
exports: [CoreHomeRoutingModule],
|
||||
providers: [
|
||||
CoreCoursesDashboardHandler,
|
||||
],
|
||||
|
|
|
@ -16,12 +16,10 @@
|
|||
</ion-header>
|
||||
<ion-content>
|
||||
<!-- @todo -->
|
||||
<core-loading [hideUntil]="loaded" *ngIf="tabs.length > 0">
|
||||
<core-tabs [selectedIndex]="selectedTab" [hideUntil]="loaded" [tabs]="tabs"></core-tabs>
|
||||
<core-loading [hideUntil]="loaded">
|
||||
<core-tabs *ngIf="tabs.length > 0" [selectedIndex]="selectedTab" [hideUntil]="loaded" [tabs]="tabs"></core-tabs>
|
||||
<ng-container *ngIf="tabs.length == 0">
|
||||
<core-empty-box icon="fa-home" [message]="'core.courses.nocourses' | translate">
|
||||
<div>Home page</div>
|
||||
</core-empty-box>
|
||||
<core-empty-box icon="fas-home" [message]="'core.courses.nocourses' | translate"></core-empty-box>
|
||||
</ng-container>
|
||||
</core-loading>
|
||||
</ion-content>
|
||||
|
|
|
@ -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 {}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue