diff --git a/src/app/app.menu.ts b/src/app/app.menu.ts new file mode 100644 index 00000000..f9fab54a --- /dev/null +++ b/src/app/app.menu.ts @@ -0,0 +1,121 @@ +export const menuItems = [ + { + title: 'Dashboard', + component: 'Dashboard', + icon: 'ion-android-home', + selected: false, + expanded: false, + order: 0 + }, + { + title: 'UI Features', + component: 'Ui', + icon: 'ion-android-laptop', + selected: false, + expanded: false, + order: 200, + subMenu: [ + { + title: 'Typography', + component: 'Typography', + }, + { + title: 'Buttons', + component: 'Buttons', + }, + { + title: 'Icons', + component: 'Icons', + }, + { + title: 'Grid', + component: 'Grid', + }, + ] + }, + { + title: 'Maps', + component: 'Maps', + icon: 'ion-ios-location-outline', + selected: false, + expanded: false, + order: 300, + subMenu: [ + { + title: 'Google Maps', + component: 'GoogleMaps', + }, + { + title: 'Leaflet Maps', + component: 'LeafletMaps', + }, + { + title: 'Bubble Maps', + component: 'BubbleMaps', + }, + { + title: 'Line Maps', + component: 'LineMaps', + } + ] + }, + { + title: 'Charts', + component: 'Charts', + icon: 'ion-stats-bars', + selected: false, + expanded: false, + order: 400, + subMenu: [ + // { + // title: 'Chart Js', + // component: 'ChartJs', + // }, + { + title: 'ChartistJs', + component: 'ChartistJs', + }, + ] + }, + { + title: 'Form Elements', + component: 'Forms', + icon: 'ion-compose', + selected: false, + expanded: false, + order: 500, + subMenu: [ + { + title: 'Form Inputs', + component: 'Inputs', + }, + { + title: 'Form Layouts', + component: 'Layouts', + }, + ] + }, + { + title: 'Menu Level 1', + icon: 'ion-ios-more', + selected: false, + expanded: false, + subMenu: [ + { + title: 'Menu Level 1.1', + disabled: true, + selected: false, + expanded: false + }, + { + title: 'Menu Level 1.2', + subMenu: [{ + title: 'Menu Level 1.2.1', + disabled: true, + selected: false, + expanded: false + }] + } + ] + } +]; diff --git a/src/app/theme/components/sidebar/sidebar.component.ts b/src/app/theme/components/sidebar/sidebar.component.ts index c6f287d5..66bb1c92 100644 --- a/src/app/theme/components/sidebar/sidebar.component.ts +++ b/src/app/theme/components/sidebar/sidebar.component.ts @@ -5,9 +5,6 @@ import {AppState} from '../../../app.state'; import {layoutSizes} from '../../../theme'; import {SidebarService} from './sidebar.service'; -// TODO: separate menu and sidebar -// TODO: move some functionality to decorators - @Component({ selector: 'sidebar', encapsulation: ViewEncapsulation.None, @@ -36,15 +33,10 @@ export class Sidebar { private _sidebarService:SidebarService, private _state:AppState) { - } - - ngOnInit() { this.menuItems = this._sidebarService.getMenuItems(); - this.selectMenuItem(); - this._router.root.subscribe(() => this.selectMenuItem()); + this._router.root.subscribe((path) => this._selectMenuItem(path)); } - // TODO: is it really the best event for this kind of things? ngAfterViewInit() { this.updateSidebarHeight(); } @@ -102,28 +94,9 @@ export class Sidebar { return false; } - // TODO: there is a bug in the router thus all child routers are considered as active - private selectMenuItem() { - let currentMenu; + private _selectMenuItem(currentPath = null) { - let isCurrent = (instructions) => (instructions.filter(i => typeof i !== 'undefined').length > 0 ? this._router.isRouteActive(this._router.generate(instructions)) : false); - let assignCurrent = (menu) => (menu.selected ? currentMenu = menu : null); - - this.menuItems.forEach(function (menu: any) { - - menu.selected = isCurrent([menu.name]); - menu.expanded = menu.expanded || menu.selected; - assignCurrent(menu); - - if (menu.subMenu) { - menu.subMenu.forEach(function (subMenu) { - subMenu.selected = isCurrent([menu.name, subMenu.name]) && !subMenu.disabled; - assignCurrent(menu); - }); - } - }); - - // notifies all subscribers + let currentMenu = this._sidebarService.selectMenuItem(this._router, this.menuItems, currentPath); this._state.notifyDataChanged('menu.activeLink', currentMenu); } } diff --git a/src/app/theme/components/sidebar/sidebar.html b/src/app/theme/components/sidebar/sidebar.html index a07d0217..a706297b 100644 --- a/src/app/theme/components/sidebar/sidebar.html +++ b/src/app/theme/components/sidebar/sidebar.html @@ -1,9 +1,9 @@ -