Skip to content

Commit

Permalink
Add navigation service and fix page components (DevExpress#4)
Browse files Browse the repository at this point in the history
* Add navigation service and fix page components

* Add type of navigation
  • Loading branch information
dxvladislavvolkov committed Aug 31, 2018
1 parent ba56bf8 commit 7a78420
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 49 deletions.
15 changes: 6 additions & 9 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { ProfileComponent, ProfileModule } from './pages/profile/profile.component';
import { SettingsComponent, SettingsModule } from './pages/settings/settings.component';
import { AboutComponent, AboutModule } from './pages/about/about.component';
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: '',
Expand All @@ -26,12 +26,9 @@ const routes: Routes = [{

@NgModule({
imports: [
RouterModule,
RouterModule.forRoot(routes),
SettingsModule,
ProfileModule,
AboutModule
RouterModule.forRoot(routes)
],
exports: [ RouterModule ]
exports: [ RouterModule ],
declarations: [AboutComponent, SettingsComponent, ProfileComponent]
})
export class PagesRoutingModule {}
8 changes: 1 addition & 7 deletions src/app/pages/about/about.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, NgModule } from '@angular/core';
import { Component } from '@angular/core';

@Component({
templateUrl: 'about.template.html'
Expand All @@ -7,9 +7,3 @@ import { Component, NgModule } from '@angular/core';
export class AboutComponent {
constructor() {}
}

@NgModule({
imports: [],
declarations: [AboutComponent]
})
export class AboutModule { }
8 changes: 1 addition & 7 deletions src/app/pages/profile/profile.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, NgModule } from '@angular/core';
import { Component } from '@angular/core';

@Component({
templateUrl: 'profile.template.html'
Expand All @@ -7,9 +7,3 @@ import { Component, NgModule } from '@angular/core';
export class ProfileComponent {
constructor() {}
}

@NgModule({
imports: [],
declarations: [ProfileComponent]
})
export class ProfileModule { }
8 changes: 1 addition & 7 deletions src/app/pages/settings/settings.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, NgModule } from '@angular/core';
import { Component } from '@angular/core';

@Component({
templateUrl: 'settings.template.html'
Expand All @@ -7,9 +7,3 @@ import { Component, NgModule } from '@angular/core';
export class SettingsComponent {
constructor() {}
}

@NgModule({
imports: [],
declarations: [SettingsComponent]
})
export class SettingsModule { }
15 changes: 15 additions & 0 deletions src/app/services/navigation/navigation.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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();
}));
});
41 changes: 41 additions & 0 deletions src/app/services/navigation/navigation.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +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 { Router } from '@angular/router';

@Component({
Expand All @@ -10,30 +11,17 @@ import { Router } from '@angular/router';
display: block;
height: 100%;
}
`]
`],
providers: [NavigationService]
})
export class NavigationMenuComponent {
@Output() selectedItemChanged = new EventEmitter<string>();

menuItems = [{
text: 'Home',
expanded: true,
icon: 'home',
items: [{
text: 'Profile',
path: 'profile'
}, {
text: 'Settings',
path: 'settings'
}]
}, {
text: 'About',
icon: 'info',
path: 'about'
}
];
menuItems: Navigation[];

constructor(private router: Router) { }
constructor(private router: Router, navigationService: NavigationService) {
this.menuItems = navigationService.getNavigationData();
}

onItemSelectionChanged(event) {
this.selectedItemChanged.emit(event.itemData.text);
Expand Down

0 comments on commit 7a78420

Please sign in to comment.