xref: /openbmc/phosphor-webui/app/index.js (revision 51946552)
1/**
2 * A module which contains the definition of the application and the base of configuration
3 *
4 * @module app/index/services/index
5 * @exports app/index
6 *
7 * @author Developer Developer
8 * @version 0.10.0
9 * @since 0.0.1
10 */
11
12window.angular && (function (angular) {
13    'use strict';
14
15    angular
16        .module('app', [
17            // Dependencies
18            'ngRoute',
19            'angular-clipboard',
20            'angularUtils.directives.dirPagination',
21            // Basic resources
22            'app.constants',
23            'app.templates',
24            'app.vendors',
25            'app.common.services',
26            'app.common.directives',
27            'app.common.filters',
28            // Model resources
29            'app.login',
30            'app.overview',
31            'app.serverControl',
32            'app.serverHealth',
33            'app.configuration',
34            'app.firmware',
35            'app.users'
36        ])
37        // Route configuration
38        .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
39            $locationProvider.hashPrefix('');
40            $routeProvider
41                .otherwise({
42                    'redirectTo': '/login'
43                });
44        }])
45        .config(['$compileProvider', function ($compileProvider) {
46          $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|data|blob):/);
47        }])
48        .config(['$httpProvider', function($httpProvider){
49            $httpProvider.defaults.timeout = 10000;
50            $httpProvider.interceptors.push('apiInterceptor');
51        }])
52        .run(['$rootScope', '$location', 'dataService', 'userModel',
53           function($rootScope, $location, dataService, userModel){
54           $rootScope.dataService = dataService;
55           dataService.path = $location.path();
56           $rootScope.$on('$routeChangeStart', function(event, next, current){
57
58             if(next.$$route == null || next.$$route == undefined) return;
59             if(next.$$route.authenticated){
60               if(!userModel.isLoggedIn()){
61                 $location.path('/login');
62               }
63             }
64
65             if(next.$$route.originalPath == '/' ||
66               next.$$route.originalPath == '/login'){
67                if(userModel.isLoggedIn()){
68                   if(current && current.$$route){
69                     $location.path(current.$$route.originalPath);
70                   }else{
71                     $location.path('/overview/system');
72                   }
73                }
74             }
75           });
76           $rootScope.$on('$locationChangeSuccess', function(event){
77               var path = $location.path();
78               dataService.path = path;
79               if(['/','/login','/logout'].indexOf(path) == -1 &&
80                path.indexOf('/login') == -1){
81                   dataService.showNavigation = true;
82               }else{
83                   dataService.showNavigation = false;
84               }
85           });
86
87           $rootScope.$on('timedout-user', function(){
88             if(sessionStorage.getItem('LOGIN_ID') == 'FAKE_ID'){
89                return;
90             }
91
92             sessionStorage.removeItem('LOGIN_ID');
93             $location.path('/login');
94           });
95           }
96        ]);
97
98})(window.angular);
99