blob: 43f62b3a29a254010506d767a0a14e058a22bbc1 [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) {
40
41 // TODO activate only one state
42
43 const activeRoute = this.$state.current.name;
44 const separateRoutes = activeRoute.split('.');
45
46 if (!navSelected) {
47 navSelected = separateRoutes[1];
48 }
49
50 if (navId === navSelected) {
51 return false;
52 }
53 else if (this.$state.current.name.indexOf(navId) === -1 && navId === navSelected ) {
54 return false;
55 }
56 else {
57 return true;
58 }
Matteo Scandoloa8a6fbb2016-12-21 16:59:08 -080059 }
Matteo Scandolo266907e2016-12-20 13:41:42 -080060
Matteo Scandoloa8a6fbb2016-12-21 16:59:08 -080061 logout() {
62 this.authService.logout();
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080063 }
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080064}
65
66export const xosNav: angular.IComponentOptions = {
67 template: require('./nav.html'),
68 controllerAs: 'vm',
69 controller: NavCtrl
70};