xref: /openbmc/phosphor-webui/app/index.js (revision 43366db7)
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.users'
35        ])
36        // Route configuration
37        .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
38            $locationProvider.hashPrefix('');
39            $routeProvider
40                .otherwise({
41                    'redirectTo': '/login'
42                });
43        }])
44        .config(['$compileProvider', function ($compileProvider) {
45          $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|data|blob):/);
46        }])
47        .config(['$httpProvider', function($httpProvider){
48            $httpProvider.defaults.timeout = 10000;
49            $httpProvider.interceptors.push('apiInterceptor');
50        }])
51        .run(['$rootScope', '$location', 'dataService', 'userModel',
52           function($rootScope, $location, dataService, userModel){
53           $rootScope.dataService = dataService;
54           dataService.path = $location.path();
55           $rootScope.$on('$routeChangeStart', function(event, next, current){
56
57             if(next.$$route == null || next.$$route == undefined) return;
58             if(next.$$route.authenticated){
59               if(!userModel.isLoggedIn()){
60                 $location.path('/login');
61               }
62             }
63
64             if(next.$$route.originalPath == '/' ||
65               next.$$route.originalPath == '/login'){
66                if(userModel.isLoggedIn()){
67                   if(current && current.$$route){
68                     $location.path(current.$$route.originalPath);
69                   }else{
70                     $location.path('/overview/system');
71                   }
72                }
73             }
74           });
75           $rootScope.$on('$locationChangeSuccess', function(event){
76               var path = $location.path();
77               dataService.path = path;
78               if(['/','/login','/logout'].indexOf(path) == -1 &&
79                path.indexOf('/login') == -1){
80                   dataService.showNavigation = true;
81               }else{
82                   dataService.showNavigation = false;
83               }
84           });
85
86           $rootScope.$on('timedout-user', function(){
87             if(sessionStorage.getItem('LOGIN_ID') == 'FAKE_ID'){
88                return;
89             }
90
91             sessionStorage.removeItem('LOGIN_ID');
92             $location.path('/login');
93           });
94           }
95        ]);
96
97})(window.angular);
98