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