blob: edaeb244b6a8b3ff7ed53004c4cc314c816e3224 [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 Scandolo266907e2016-12-20 13:41:42 -08003import {StyleConfig} from '../../config/style.config';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08004
5class NavCtrl {
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -08006 static $inject = ['$scope', '$state', 'NavigationService'];
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08007 public routes: IXosNavigationRoute[];
Matteo Scandolo266907e2016-12-20 13:41:42 -08008 public navSelected: string;
9 public appName: string;
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080010
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080011 constructor(
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080012 private $scope: ng.IScope,
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080013 private $state: angular.ui.IStateService,
14 private navigationService: IXosNavigationService
15 ) {
Matteo Scandolo3b3b3b42016-12-15 17:31:53 -080016 // NOTE we'll need to have:
17 // - Base routes (defined from configuration based on BRAND)
18 // - Autogenerated routes (nested somewhere)
19 // - Service Routes (dynamically added)
Matteo Scandoloee655a12016-12-19 15:38:43 -080020 this.routes = [];
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080021 this.$scope.$watch(() => this.navigationService.query(), (routes) => {
22 this.routes = routes;
23 });
Matteo Scandolo266907e2016-12-20 13:41:42 -080024 this.appName = StyleConfig.projectName;
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080025 }
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080026
27 activateRoute(route: IXosNavigationRoute) {
Matteo Scandolo266907e2016-12-20 13:41:42 -080028 this.navSelected = route.state;
29 }
30
31 includes(state: string): boolean {
32 return this.$state.includes(state);
33 }
34
35 isSelected(navId: string, navSelected: string) {
36
37 // TODO activate only one state
38
39 const activeRoute = this.$state.current.name;
40 const separateRoutes = activeRoute.split('.');
41
42 if (!navSelected) {
43 navSelected = separateRoutes[1];
44 }
45
46 if (navId === navSelected) {
47 return false;
48 }
49 else if (this.$state.current.name.indexOf(navId) === -1 && navId === navSelected ) {
50 return false;
51 }
52 else {
53 return true;
54 }
55
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080056 }
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080057}
58
59export const xosNav: angular.IComponentOptions = {
60 template: require('./nav.html'),
61 controllerAs: 'vm',
62 controller: NavCtrl
63};