blob: 7ba15cd8e0b5e04a57ff3f173deb3eed5e1c53d5 [file] [log] [blame]
Iftekharul Islamf157d372017-03-08 11:11:27 -06001angular
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 Islam115984a2017-03-09 09:47:35 -060013 'controller': 'loginController',
14 authenticated: false
Iftekharul Islamf157d372017-03-08 11:11:27 -060015 })
16 .when('/power-operations', {
17 'templateUrl': 'power-operations.html',
Iftekharul Islam115984a2017-03-09 09:47:35 -060018 'controller': 'powerOperationsController',
19 authenticated: true
Iftekharul Islamf157d372017-03-08 11:11:27 -060020 })
21 .when('/system-overview', {
22 'templateUrl': 'system-overview.html',
Iftekharul Islam115984a2017-03-09 09:47:35 -060023 'controller': 'systemOverviewController',
24 authenticated: true
Iftekharul Islamf157d372017-03-08 11:11:27 -060025 })
Iftekharul Islamb37fdfb2017-07-12 15:36:20 -050026 .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 Islamf157d372017-03-08 11:11:27 -060036 .otherwise({
37 'redirectTo': '/login'
38 });
39 }])
Iftekharul Islam38f681f2017-03-21 13:22:59 -050040 .config(['$httpProvider', function($httpProvider){
41 //console.log($httpProvider.interceptors);
42 $httpProvider.interceptors.push('apiInterceptor');
43 }])
Iftekharul Islam115984a2017-03-09 09:47:35 -060044 .run(['$rootScope', '$location', 'dataService', 'userModel',
45 function($rootScope, $location, dataService, userModel){
Iftekharul Islamf157d372017-03-08 11:11:27 -060046 $rootScope.dataService = dataService;
47 dataService.path = $location.path();
Iftekharul Islam115984a2017-03-09 09:47:35 -060048 $rootScope.$on('$routeChangeStart', function(event, next, current){
49
50 if(next.$$route == null || next.$$route == undefined) return;
51
52 if(next.$$route.authenticated){
53 if(!userModel.isLoggedIn()){
54 $location.path('/login');
55 }
56 }
57
58 if(next.$$route.originalPath == '/' ||
59 next.$$route.originalPath == '/login'){
60 if(userModel.isLoggedIn()){
61 if(current){
62 $location.path(current.$$route.originalPath);
63 }else{
64 $location.path('/system-overview');
65 }
66 }
67 }
68 });
Iftekharul Islamf157d372017-03-08 11:11:27 -060069 $rootScope.$on('$locationChangeSuccess', function(event){
70 var path = $location.path();
71 dataService.path = path;
72 if(['/','/login','/logout'].indexOf(path) == -1){
73 dataService.showNavigation = true;
74 }else{
75 dataService.showNavigation = false;
76 }
77 });
Iftekharul Islam38f681f2017-03-21 13:22:59 -050078
79 $rootScope.$on('timedout-user', function(){
80 sessionStorage.removeItem('LOGIN_ID');
81 $location.path('/login');
82 });
Iftekharul Islamf157d372017-03-08 11:11:27 -060083 }
84 ]);