Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 1 | import './nav.scss'; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 2 | import {IXosNavigationService, IXosNavigationRoute} from '../services/navigation'; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 3 | |
| 4 | class NavCtrl { |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 5 | static $inject = ['$scope', '$state', 'NavigationService']; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 6 | public routes: IXosNavigationRoute[]; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 7 | |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 8 | constructor( |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 9 | private $scope: ng.IScope, |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 10 | private $state: angular.ui.IStateService, |
| 11 | private navigationService: IXosNavigationService |
| 12 | ) { |
Matteo Scandolo | 3b3b3b4 | 2016-12-15 17:31:53 -0800 | [diff] [blame] | 13 | // NOTE we'll need to have: |
| 14 | // - Base routes (defined from configuration based on BRAND) |
| 15 | // - Autogenerated routes (nested somewhere) |
| 16 | // - Service Routes (dynamically added) |
Matteo Scandolo | ee655a1 | 2016-12-19 15:38:43 -0800 | [diff] [blame^] | 17 | this.routes = []; |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 18 | this.$scope.$watch(() => this.navigationService.query(), (routes) => { |
| 19 | this.routes = routes; |
| 20 | }); |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | isRouteActive(route: IXosNavigationRoute) { |
| 24 | return this.$state.current.url === route.url ? 'active' : ''; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 25 | } |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 26 | |
| 27 | activateRoute(route: IXosNavigationRoute) { |
| 28 | route.opened = !route.opened; |
| 29 | } |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | export const xosNav: angular.IComponentOptions = { |
| 33 | template: require('./nav.html'), |
| 34 | controllerAs: 'vm', |
| 35 | controller: NavCtrl |
| 36 | }; |