refactor(app): refactor forRoot & menu import

This commit is contained in:
Dmitry Nehaychik 2017-07-20 15:14:38 +03:00
parent d6cef06dcd
commit be69ccc058
6 changed files with 170 additions and 111 deletions

View file

@ -1,7 +1,12 @@
import { NgModule, Optional, SkipSelf } from '@angular/core'; import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { throwIfAlreadyLoaded } from './module-import-guard'; import { throwIfAlreadyLoaded } from './module-import-guard';
import { DataModule } from './data/data.module';
const NGA_CORE_PROVIDERS = [
...DataModule.forRoot().providers,
];
@NgModule({ @NgModule({
imports: [ imports: [
@ -13,4 +18,13 @@ export class CoreModule {
constructor(@Optional() @SkipSelf() parentModule: CoreModule) { constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
throwIfAlreadyLoaded(parentModule, 'CoreModule'); throwIfAlreadyLoaded(parentModule, 'CoreModule');
} }
static forRoot(): ModuleWithProviders {
return <ModuleWithProviders>{
ngModule: CoreModule,
providers: [
...NGA_CORE_PROVIDERS,
],
};
}
} }

View file

@ -1,8 +1,9 @@
import { NgModule } from '@angular/core'; import { ModuleWithProviders, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { import {
NgaThemeModule,
NgaCardModule, NgaCardModule,
NgaLayoutModule, NgaLayoutModule,
NgaTabsetModule, NgaTabsetModule,
@ -45,6 +46,7 @@ const NGA_MODULES = [
NgaUserModule, NgaUserModule,
NgaActionsModule, NgaActionsModule,
NgaSearchModule, NgaSearchModule,
NgaSidebarModule,
]; ];
const COMPONENTS = [ const COMPONENTS = [
@ -61,11 +63,17 @@ const PIPES = [
RoundPipe, RoundPipe,
]; ];
const NGA_THEME_PROVIDERS = [
...NgaThemeModule.forRoot({ name: 'cosmic' }).providers,
...NgaSidebarModule.forRoot().providers,
...NgaSidebarModule.forRoot().providers,
...NgaMenuModule.forRoot().providers,
];
@NgModule({ @NgModule({
imports: [ imports: [
...BASE_MODULES, ...BASE_MODULES,
...NGA_MODULES, ...NGA_MODULES,
NgaSidebarModule.forRoot(),
], ],
exports: [ exports: [
...BASE_MODULES, ...BASE_MODULES,
@ -79,4 +87,13 @@ const PIPES = [
], ],
}) })
export class ThemeModule { export class ThemeModule {
static forRoot(): ModuleWithProviders {
return <ModuleWithProviders>{
ngModule: ThemeModule,
providers: [
...NGA_THEME_PROVIDERS,
],
};
}
} }

View file

@ -13,6 +13,7 @@ import { CoreModule } from './@core/core.module';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { ThemeModule } from './@theme/theme.module';
@NgModule({ @NgModule({
declarations: [AppComponent], declarations: [AppComponent],
@ -22,6 +23,8 @@ import { AppRoutingModule } from './app-routing.module';
HttpModule, HttpModule,
AppRoutingModule, AppRoutingModule,
CoreModule, CoreModule,
ThemeModule.forRoot(),
CoreModule.forRoot(),
], ],
bootstrap: [AppComponent], bootstrap: [AppComponent],
providers: [ providers: [

View file

@ -2,43 +2,53 @@ import { NgaMenuItem } from '@akveo/nga-theme';
import { List } from 'immutable'; import { List } from 'immutable';
// TODO: refactor array styles export const MENU_ITEMS: List<NgaMenuItem> = List([
export const menuItems: List<NgaMenuItem> = List([{ {
title: 'Dashboard', title: 'Dashboard',
icon: 'ion ion-ios-home-outline', icon: 'ion ion-ios-home-outline',
link: '/pages/dashboard', link: '/pages/dashboard',
home: true, home: true,
}, { },
{
title: 'FEATURES', title: 'FEATURES',
group: true, group: true,
}, { },
{
title: 'UI Features', title: 'UI Features',
icon: 'ion ion-ios-keypad-outline', icon: 'ion ion-ios-keypad-outline',
link: '/pages/ui-features', link: '/pages/ui-features',
children: List<NgaMenuItem>([{ children: List<NgaMenuItem>([
{
title: 'Buttons', title: 'Buttons',
link: '/pages/ui-features/buttons', link: '/pages/ui-features/buttons',
}, { },
{
title: 'Grid', title: 'Grid',
link: '/pages/ui-features/grid', link: '/pages/ui-features/grid',
}, { },
{
title: 'Icons', title: 'Icons',
link: '/pages/ui-features/icons', link: '/pages/ui-features/icons',
}, { },
{
title: 'Modals', title: 'Modals',
link: '/pages/ui-features/modals', link: '/pages/ui-features/modals',
}, { },
{
title: 'Typography', title: 'Typography',
link: '/pages/ui-features/typography', link: '/pages/ui-features/typography',
}, { },
{
title: 'Animated Searches', title: 'Animated Searches',
link: '/pages/ui-features/search-fields', link: '/pages/ui-features/search-fields',
}, },
{ {
title: 'Tabs', title: 'Tabs',
link: '/pages/ui-features/tabs', link: '/pages/ui-features/tabs',
}]), },
}, { ]),
},
{
title: 'Components', title: 'Components',
icon: 'ion ion-ios-gear-outline', icon: 'ion ion-ios-gear-outline',
children: List<NgaMenuItem>([ children: List<NgaMenuItem>([
@ -50,54 +60,76 @@ export const menuItems: List<NgaMenuItem> = List([{
link: '/pages/components/toaster', link: '/pages/components/toaster',
}, },
]), ]),
}, { },
{
title: 'Maps', title: 'Maps',
icon: 'ion ion-ios-location-outline', icon: 'ion ion-ios-location-outline',
children: List<NgaMenuItem>([{ children: List<NgaMenuItem>([
{
title: 'Gmaps', title: 'Gmaps',
link: '/pages/maps/gmaps', link: '/pages/maps/gmaps',
}, { },
{
title: 'Leaflet', title: 'Leaflet',
link: '/pages/maps/leaflet', link: '/pages/maps/leaflet',
}]), },
}, { ]),
},
{
title: 'Charts', title: 'Charts',
icon: 'ion ion-arrow-graph-up-right', icon: 'ion ion-arrow-graph-up-right',
children: List<NgaMenuItem>([{ children: List<NgaMenuItem>([
{
title: 'Echarts', title: 'Echarts',
link: '/pages/charts/echarts', link: '/pages/charts/echarts',
}, { },
{
title: 'D3', title: 'D3',
link: '/pages/charts/d3', link: '/pages/charts/d3',
}, { },
{
title: 'Charts.js', title: 'Charts.js',
link: '/pages/charts/chartjs', link: '/pages/charts/chartjs',
}]), },
}, { ]),
},
{
title: 'Editors', title: 'Editors',
icon: 'ion ion-edit', icon: 'ion ion-edit',
children: List<NgaMenuItem>([{ children: List<NgaMenuItem>([
{
title: 'TinyMCE', title: 'TinyMCE',
link: '/pages/editors/tinymce', link: '/pages/editors/tinymce',
}, { },
{
title: 'CKEditor', title: 'CKEditor',
link: '/pages/editors/ckeditor', link: '/pages/editors/ckeditor',
}]), },
}, { ]),
},
{
title: 'Forms', title: 'Forms',
icon: 'ion-compose', icon: 'ion-compose',
children: List<NgaMenuItem>([{ children: List<NgaMenuItem>([
{
title: 'Form Inputs', title: 'Form Inputs',
link: '/pages/forms/inputs', link: '/pages/forms/inputs',
}, { },
{
title: 'Form Layouts', title: 'Form Layouts',
link: '/pages/forms/layouts', link: '/pages/forms/layouts',
}]), },
}, { ]),
},
{
title: 'Tables', title: 'Tables',
icon: 'ion-ios-grid-view', icon: 'ion-ios-grid-view',
children: List<NgaMenuItem>([{ children: List<NgaMenuItem>([
{
title: 'Smart Table', title: 'Smart Table',
link: '/pages/tables/smart-table', link: '/pages/tables/smart-table',
}]), },
}]); ]),
},
]);

View file

@ -1,15 +1,18 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import 'style-loader!../@theme/styles/styles.scss'; import 'style-loader!../@theme/styles/styles.scss';
import { MENU_ITEMS } from './pages-menu';
@Component({ @Component({
selector: 'ngx-pages', selector: 'ngx-pages',
template: ` template: `
<ngx-one-column-layout> <ngx-one-column-layout>
<nga-menu></nga-menu> <nga-menu [items]="menu"></nga-menu>
<router-outlet></router-outlet> <router-outlet></router-outlet>
</ngx-one-column-layout> </ngx-one-column-layout>
`, `,
}) })
export class PagesComponent { export class PagesComponent {
menu = MENU_ITEMS;
} }

View file

@ -1,14 +1,9 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { NgaMenuModule, NgaSidebarModule, NgaThemeModule } from '@akveo/nga-theme';
import { menuItems } from './pages-menu';
import { PagesComponent } from './pages.component'; import { PagesComponent } from './pages.component';
import { DashboardModule } from './dashboard/dashboard.module'; import { DashboardModule } from './dashboard/dashboard.module';
import { PagesRoutingModule } from './pages-routing.module'; import { PagesRoutingModule } from './pages-routing.module';
import { ThemeModule } from '../@theme/theme.module'; import { ThemeModule } from '../@theme/theme.module';
import { DataModule } from '../@core/data/data.module';
const PAGES_COMPONENTS = [ const PAGES_COMPONENTS = [
PagesComponent, PagesComponent,
@ -16,13 +11,8 @@ const PAGES_COMPONENTS = [
@NgModule({ @NgModule({
imports: [ imports: [
// TODO: why here? review the modules structure
NgaThemeModule.forRoot({ name: 'cosmic' }),
NgaSidebarModule.forRoot(),
NgaMenuModule.forRoot({ items: menuItems }),
PagesRoutingModule, PagesRoutingModule,
ThemeModule, ThemeModule,
DataModule.forRoot(),
DashboardModule, DashboardModule,
], ],
declarations: [ declarations: [