Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 1 | angular |
| 2 | .module('app', [ |
| 3 | 'ngRoute', |
| 4 | 'app.directives', |
| 5 | 'app.services', |
| 6 | 'app.controllers' |
| 7 | ]) |
| 8 | .config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){ |
| 9 | $locationProvider.hashPrefix(''); |
| 10 | $routeProvider |
| 11 | .when('/login', { |
| 12 | 'templateUrl': 'login.html', |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 13 | 'controller': 'loginController', |
| 14 | authenticated: false |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 15 | }) |
| 16 | .when('/power-operations', { |
| 17 | 'templateUrl': 'power-operations.html', |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 18 | 'controller': 'powerOperationsController', |
| 19 | authenticated: true |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 20 | }) |
| 21 | .when('/system-overview', { |
| 22 | 'templateUrl': 'system-overview.html', |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 23 | 'controller': 'systemOverviewController', |
| 24 | authenticated: true |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 25 | }) |
Iftekharul Islam | b37fdfb | 2017-07-12 15:36:20 -0500 | [diff] [blame] | 26 | .when('/unit-id', { |
| 27 | 'templateUrl': 'unit-id.html', |
| 28 | 'controller': 'unitIDController', |
| 29 | authenticated: true |
| 30 | }) |
| 31 | .when('/bmc-reboot', { |
| 32 | 'templateUrl': 'bmc-reboot.html', |
| 33 | 'controller': 'bmcRebootController', |
| 34 | authenticated: true |
| 35 | }) |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 36 | .otherwise({ |
| 37 | 'redirectTo': '/login' |
| 38 | }); |
| 39 | }]) |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 40 | .run(['$rootScope', '$location', 'dataService', 'userModel', |
| 41 | function($rootScope, $location, dataService, userModel){ |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 42 | $rootScope.dataService = dataService; |
| 43 | dataService.path = $location.path(); |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 44 | $rootScope.$on('$routeChangeStart', function(event, next, current){ |
| 45 | |
| 46 | if(next.$$route == null || next.$$route == undefined) return; |
| 47 | |
| 48 | if(next.$$route.authenticated){ |
| 49 | if(!userModel.isLoggedIn()){ |
| 50 | $location.path('/login'); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if(next.$$route.originalPath == '/' || |
| 55 | next.$$route.originalPath == '/login'){ |
| 56 | if(userModel.isLoggedIn()){ |
| 57 | if(current){ |
| 58 | $location.path(current.$$route.originalPath); |
| 59 | }else{ |
| 60 | $location.path('/system-overview'); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | }); |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 65 | $rootScope.$on('$locationChangeSuccess', function(event){ |
| 66 | var path = $location.path(); |
| 67 | dataService.path = path; |
| 68 | if(['/','/login','/logout'].indexOf(path) == -1){ |
| 69 | dataService.showNavigation = true; |
| 70 | }else{ |
| 71 | dataService.showNavigation = false; |
| 72 | } |
| 73 | }); |
| 74 | } |
| 75 | ]); |