blob: 31831e1af5fc40348baef58db9f3d14d58dfd1aa [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 Scandoloa8a6fbb2016-12-21 16:59:08 -08004import {IXosAuthService} from '../../datasources/rest/auth.rest';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08005
6class NavCtrl {
Matteo Scandoloa8a6fbb2016-12-21 16:59:08 -08007 static $inject = ['$scope', '$state', 'NavigationService', 'AuthService'];
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08008 public routes: IXosNavigationRoute[];
Matteo Scandolo266907e2016-12-20 13:41:42 -08009 public navSelected: string;
10 public appName: string;
Matteo Scandoloa8a6fbb2016-12-21 16:59:08 -080011 public payoff: string;
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080012
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080013 constructor(
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080014 private $scope: ng.IScope,
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080015 private $state: angular.ui.IStateService,
Matteo Scandoloa8a6fbb2016-12-21 16:59:08 -080016 private navigationService: IXosNavigationService,
17 private authService: IXosAuthService
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080018 ) {
Matteo Scandolo3b3b3b42016-12-15 17:31:53 -080019 // NOTE we'll need to have:
20 // - Base routes (defined from configuration based on BRAND)
21 // - Autogenerated routes (nested somewhere)
22 // - Service Routes (dynamically added)
Matteo Scandoloee655a12016-12-19 15:38:43 -080023 this.routes = [];
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080024 this.$scope.$watch(() => this.navigationService.query(), (routes) => {
25 this.routes = routes;
26 });
Matteo Scandolo266907e2016-12-20 13:41:42 -080027 this.appName = StyleConfig.projectName;
Matteo Scandoloa8a6fbb2016-12-21 16:59:08 -080028 this.payoff = StyleConfig.payoff;
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080029 }
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080030
31 activateRoute(route: IXosNavigationRoute) {
Matteo Scandolo266907e2016-12-20 13:41:42 -080032 this.navSelected = route.state;
33 }
34
35 includes(state: string): boolean {
36 return this.$state.includes(state);
37 }
38
39 isSelected(navId: string, navSelected: string) {
Matteo Scandolo266907e2016-12-20 13:41:42 -080040 const activeRoute = this.$state.current.name;
41 const separateRoutes = activeRoute.split('.');
42
43 if (!navSelected) {
44 navSelected = separateRoutes[1];
45 }
46
47 if (navId === navSelected) {
48 return false;
49 }
50 else if (this.$state.current.name.indexOf(navId) === -1 && navId === navSelected ) {
51 return false;
52 }
53 else {
54 return true;
55 }
Matteo Scandoloa8a6fbb2016-12-21 16:59:08 -080056 }
Matteo Scandolo266907e2016-12-20 13:41:42 -080057
Matteo Scandoloa8a6fbb2016-12-21 16:59:08 -080058 logout() {
59 this.authService.logout();
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080060 }
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080061}
62
63export const xosNav: angular.IComponentOptions = {
64 template: require('./nav.html'),
65 controllerAs: 'vm',
66 controller: NavCtrl
67};