From e8a4616cdf332b7b67c01f13de684b89a43ae6ba Mon Sep 17 00:00:00 2001 From: dxvladislavvolkov Date: Tue, 11 Sep 2018 15:32:20 +0300 Subject: [PATCH] Use routes for navigation (#5) * Use routes for navigation * Remove icon * generate navigation for treeview * Fix indents * Add HomeComponent to routes * Add export navigation * Add a new line --- src/app/app-navigation.ts | 18 ++++++++ src/app/app-routing.module.ts | 31 +++++++------- src/app/layout/layout.component.html | 12 +++--- .../navigation/navigation.service.spec.ts | 15 ------- .../services/navigation/navigation.service.ts | 41 ------------------- .../navigation-menu.component.html | 2 +- .../navigation-menu.component.ts | 14 +++---- 7 files changed, 45 insertions(+), 88 deletions(-) create mode 100644 src/app/app-navigation.ts delete mode 100644 src/app/services/navigation/navigation.service.spec.ts delete mode 100644 src/app/services/navigation/navigation.service.ts diff --git a/src/app/app-navigation.ts b/src/app/app-navigation.ts new file mode 100644 index 000000000..6c89cc46e --- /dev/null +++ b/src/app/app-navigation.ts @@ -0,0 +1,18 @@ +export const navigation = [ + { + text: 'Home', + path: '/home', + icon: 'home', + items: [{ + text: 'Profile', + path: '/profile' + }, { + text: 'Settings', + path: '/settings' + }] + }, { + text: 'About', + path: '/about', + icon: 'info' + } +]; diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 22d1d1f4a..ca718fad1 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -5,23 +5,20 @@ import { ProfileComponent } from './pages/profile/profile.component'; import { SettingsComponent } from './pages/settings/settings.component'; import { AboutComponent } from './pages/about/about.component' -const routes: Routes = [{ - path: '', - redirectTo: 'profile', - pathMatch: 'full' - }, { - path: 'profile', - component: ProfileComponent, - data: { title: 'Profile' } - }, { - path: 'settings', - component: SettingsComponent, - data: { title: 'Settings' } - }, { - path: 'about', - component: AboutComponent, - data: { title: 'About' } - } +export const routes: Routes = [{ + path: '', + redirectTo: 'profile', + pathMatch: 'full' + }, { + path: 'profile', + component: ProfileComponent + }, { + path: 'settings', + component: SettingsComponent + }, { + path: 'about', + component: AboutComponent + } ]; @NgModule({ diff --git a/src/app/layout/layout.component.html b/src/app/layout/layout.component.html index 2d2e7f0d8..bdf8ac9c0 100644 --- a/src/app/layout/layout.component.html +++ b/src/app/layout/layout.component.html @@ -1,6 +1,6 @@
- - - - +
diff --git a/src/app/services/navigation/navigation.service.spec.ts b/src/app/services/navigation/navigation.service.spec.ts deleted file mode 100644 index 3d2693e64..000000000 --- a/src/app/services/navigation/navigation.service.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { TestBed, inject } from '@angular/core/testing'; - -import { NavigationService } from './navigation.service'; - -describe('NavigationService', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [NavigationService] - }); - }); - - it('should be created', inject([NavigationService], (service: NavigationService) => { - expect(service).toBeTruthy(); - })); -}); diff --git a/src/app/services/navigation/navigation.service.ts b/src/app/services/navigation/navigation.service.ts deleted file mode 100644 index 830d189e2..000000000 --- a/src/app/services/navigation/navigation.service.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Injectable } from '@angular/core'; - -export class Navigation { - text: string; - expanded?: boolean; - icon?: string; - path?: string; - items?: any; -} - -let navigationData: Navigation[] = [ - { - "text": "Home", - "expanded": true, - "icon": "home", - "items": [ - { - "text": "Profile", - "path": "profile" - }, - { - "text": "Settings", - "path": "settings" - } - ] - }, - { - "text": "About", - "icon": "info", - "path": "about" - } -] - -@Injectable({ - providedIn: 'root' -}) -export class NavigationService { - getNavigationData() { - return navigationData; - } -} diff --git a/src/app/shared/components/navigation-menu/navigation-menu.component.html b/src/app/shared/components/navigation-menu/navigation-menu.component.html index a151d7f1d..727d47379 100644 --- a/src/app/shared/components/navigation-menu/navigation-menu.component.html +++ b/src/app/shared/components/navigation-menu/navigation-menu.component.html @@ -1,6 +1,6 @@ diff --git a/src/app/shared/components/navigation-menu/navigation-menu.component.ts b/src/app/shared/components/navigation-menu/navigation-menu.component.ts index 522020408..a97eb89e3 100644 --- a/src/app/shared/components/navigation-menu/navigation-menu.component.ts +++ b/src/app/shared/components/navigation-menu/navigation-menu.component.ts @@ -1,6 +1,6 @@ import { Component, NgModule, Output, EventEmitter } from '@angular/core'; import { DxTreeViewModule } from 'devextreme-angular/ui/tree-view'; -import { NavigationService, Navigation } from '../../../services/navigation/navigation.service'; +import { navigation } from '../../../app-navigation'; import { Router } from '@angular/router'; @Component({ @@ -11,17 +11,15 @@ import { Router } from '@angular/router'; display: block; height: 100%; } - `], - providers: [NavigationService] + `] }) export class NavigationMenuComponent { @Output() selectedItemChanged = new EventEmitter(); + menuItems: any; - menuItems: Navigation[]; - - constructor(private router: Router, navigationService: NavigationService) { - this.menuItems = navigationService.getNavigationData(); - } + constructor(private router: Router) { + this.menuItems = navigation; + } onItemSelectionChanged(event) { this.selectedItemChanged.emit(event.itemData.text);