blob: f19efaeafc05420acb60d1d91938c8e82cd0af86 [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 Islam115984a2017-03-09 09:47:35 -060040 .run(['$rootScope', '$location', 'dataService', 'userModel',
41 function($rootScope, $location, dataService, userModel){
Iftekharul Islamf157d372017-03-08 11:11:27 -060042 $rootScope.dataService = dataService;
43 dataService.path = $location.path();
Iftekharul Islam115984a2017-03-09 09:47:35 -060044 $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 Islamf157d372017-03-08 11:11:27 -060065 $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 ]);