blob: cd249b9eb0194eaf98514a172067c6d5f85df038 [file] [log] [blame]
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08001import './nav.scss';
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08002import {IXosNavigationService, IXosNavigationRoute} from '../services/navigation';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08003
4class NavCtrl {
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -08005 static $inject = ['$scope', '$state', 'NavigationService'];
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08006 public routes: IXosNavigationRoute[];
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08007
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08008 constructor(
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -08009 private $scope: ng.IScope,
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080010 private $state: angular.ui.IStateService,
11 private navigationService: IXosNavigationService
12 ) {
Matteo Scandolo3b3b3b42016-12-15 17:31:53 -080013 // 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 Scandoloe0d71ea2016-12-19 11:56:12 -080017
18 this.$scope.$watch(() => this.navigationService.query(), (routes) => {
19 this.routes = routes;
20 });
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080021 }
22
23 isRouteActive(route: IXosNavigationRoute) {
24 return this.$state.current.url === route.url ? 'active' : '';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080025 }
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080026
27 activateRoute(route: IXosNavigationRoute) {
28 route.opened = !route.opened;
29 }
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080030}
31
32export const xosNav: angular.IComponentOptions = {
33 template: require('./nav.html'),
34 controllerAs: 'vm',
35 controller: NavCtrl
36};