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