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