xref: /openbmc/phosphor-webui/app/index.js (revision 15374c85)
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 */
9
10import 'bootstrap/dist/css/bootstrap.css';
11import 'bootstrap/dist/css/bootstrap-theme.css';
12import "font-awesome/css/font-awesome.css"
13import angular from 'angular';
14import angular_cookies from 'angular-cookies';
15import angular_sanitize from 'angular-sanitize';
16import angular_ui_router from 'angular-ui-router';
17import angular_animate from 'angular-animate';
18import angular_clipboard from 'angular-clipboard';
19import angular_ui_bootstrap from 'angular-ui-bootstrap';
20import angular_route from 'angular-route';
21import angular_utils from 'angularUtils/src/angularUtils.js';
22import angular_utils_pagination from 'angularUtils/src/directives/pagination/dirPagination.js';
23require('./styles/index.scss')
24
25// TODO(Ed)  clean this up, add the appropriate imports to phosphor-webui
26
27import constants_index from './constants/index.js'
28import environment_constants from './constants/environment-constants.js'
29
30import services_index from './common/services/index.js'
31import constants from './common/services/constants.js'
32import dataService from './common/services/dataService.js'
33import api_utils from './common/services/api-utils.js'
34import userModel from './common/services/userModel.js'
35import apiInterceptor from './common/services/apiInterceptor.js'
36
37import filters_index from './common/filters/index.js'
38
39import directives_index from './common/directives/index.js'
40import errors from './common/directives/errors.js'
41import app_header from './common/directives/app-header.js'
42import app_navigation from './common/directives/app-navigation.js'
43import confirm from './common/directives/confirm.js'
44import log_event from './common/directives/log-event.js'
45import log_filter from './common/directives/log-filter.js'
46import log_search_control from './common/directives/log-search-control.js'
47import toggle_flag from './common/directives/toggle-flag.js'
48import firmware_list from './common/directives/firmware-list.js'
49import file from './common/directives/file.js'
50import loader from './common/directives/loader.js'
51import paginate from './common/directives/paginate.js'
52
53import login_index from './login/index.js'
54import login_controller from './login/controllers/login-controller.js'
55
56import overview_index from './overview/index.js'
57import system_overview_controller from './overview/controllers/system-overview-controller.js'
58
59import server_control_index from './server-control/index.js'
60import bmc_reboot_controller from './server-control/controllers/bmc-reboot-controller.js'
61import power_operations_controller from './server-control/controllers/power-operations-controller.js'
62import remote_console_controller from './server-control/controllers/remote-console-controller.js'
63import remote_console_window_controller from './server-control/controllers/remote-console-window-controller.js'
64
65import server_health_index from './server-health/index.js'
66import diagnostics_controller from './server-health/controllers/diagnostics-controller.js'
67import inventory_controller from './server-health/controllers/inventory-controller.js'
68import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js'
69import log_controller from './server-health/controllers/log-controller.js'
70import power_consumption_controller from './server-health/controllers/power-consumption-controller.js'
71import sensors_controller from './server-health/controllers/sensors-controller.js'
72import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js'
73import unit_id_controller from './server-health/controllers/unit-id-controller.js'
74
75import configuration_index from './configuration/index.js'
76import date_time_controller from './configuration/controllers/date-time-controller.js'
77import file_controller from './configuration/controllers/file-controller.js'
78import network_controller from './configuration/controllers/network-controller.js'
79import security_controller from './configuration/controllers/security-controller.js'
80import firmware_controller from './configuration/controllers/firmware-controller.js'
81
82import firmware_index from './firmware/index.js'
83import bmc_controller from './firmware/controllers/bmc-controller.js'
84import server_controller from './firmware/controllers/server-controller.js'
85
86import multi_server_index from './multi-server/index.js'
87import multi_server_controller from './multi-server/controllers/multi-server-controller.js'
88
89import users_index from './users/index.js'
90import user_accounts_controller from './users/controllers/user-accounts-controller.js'
91
92import phosphor_templates from './templates.js';
93import phosphor_vendors from './vendors.js';
94
95window.angular && (function (angular) {
96    'use strict';
97
98    angular
99        .module('app', [
100            // Dependencies
101            'ngRoute',
102            'angular-clipboard',
103            'angularUtils.directives.dirPagination',
104            // Basic resources
105            'app.constants',
106            'app.templates',
107            'app.vendors',
108            'app.common.services',
109            'app.common.directives',
110            'app.common.filters',
111            // Model resources
112            'app.login',
113            'app.overview',
114            'app.serverControl',
115            'app.serverHealth',
116            'app.configuration',
117            'app.users',
118            'app.multiServer'
119        ])
120        // Route configuration
121        .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
122            $locationProvider.hashPrefix('');
123            $routeProvider
124                .otherwise({
125                    'redirectTo': '/login'
126                });
127        }])
128        .config(['$compileProvider', function ($compileProvider) {
129          $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|data|blob):/);
130        }])
131        .config(['$httpProvider', function($httpProvider){
132            $httpProvider.defaults.timeout = 20000;
133            $httpProvider.interceptors.push('apiInterceptor');
134        }])
135        .run(['$rootScope', '$location', 'dataService', 'userModel',
136           function($rootScope, $location, dataService, userModel){
137           $rootScope.dataService = dataService;
138           dataService.path = $location.path();
139           $rootScope.$on('$routeChangeStart', function(event, next, current){
140             if(next.$$route == null || next.$$route == undefined) return;
141             if(next.$$route.authenticated){
142               if(!userModel.isLoggedIn()){
143                 $location.path('/login');
144               }
145             }
146
147             if(next.$$route.originalPath == '/' ||
148               next.$$route.originalPath == '/login'){
149                if(userModel.isLoggedIn()){
150                   if(current && current.$$route){
151                     $location.path(current.$$route.originalPath);
152                   }else{
153                     $location.path('/overview/server');
154                   }
155                }
156             }
157           });
158           $rootScope.$on('$locationChangeSuccess', function(event){
159               var path = $location.path();
160               dataService.path = path;
161               if(['/','/login','/logout'].indexOf(path) == -1 &&
162                path.indexOf('/login') == -1){
163                   dataService.showNavigation = true;
164               }else{
165                   dataService.showNavigation = false;
166               }
167           });
168
169           $rootScope.$on('timedout-user', function(){
170             sessionStorage.removeItem('LOGIN_ID');
171             $location.path('/login');
172           });
173           }
174        ]);
175
176})(window.angular);
177