xref: /openbmc/phosphor-webui/app/index.js (revision 569ccf66)
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';
13
14import angular from 'angular';
15import angular_animate from 'angular-animate';
16import angular_clipboard from 'angular-clipboard';
17import angular_cookies from 'angular-cookies';
18import angular_route from 'angular-route';
19import angular_sanitize from 'angular-sanitize';
20import angular_ui_bootstrap from 'angular-ui-bootstrap';
21import angular_ui_router from 'angular-ui-router';
22import angular_utils from 'angularUtils/src/angularUtils.js';
23import angular_utils_pagination from 'angularUtils/src/directives/pagination/dirPagination.js';
24
25require('./styles/index.scss');
26var config = require('../config.json');
27
28// TODO(Ed)  clean this up, add the appropriate imports to phosphor-webui
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 input from './common/directives/input.js';
51import loader from './common/directives/loader.js';
52import paginate from './common/directives/paginate.js';
53import serial_console from './common/directives/serial-console.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 power_usage_controller from './server-control/controllers/power-usage-controller.js';
65import remote_console_window_controller from './server-control/controllers/remote-console-window-controller.js';
66import server_led_controller from './server-control/controllers/server-led-controller.js';
67
68import server_health_index from './server-health/index.js';
69import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js';
70import log_controller from './server-health/controllers/log-controller.js';
71import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js';
72
73import redfish_index from './redfish/index.js';
74import redfish_controller from './redfish/controllers/redfish-controller.js';
75import configuration_index from './configuration/index.js';
76import date_time_controller from './configuration/controllers/date-time-controller.js';
77import network_controller from './configuration/controllers/network-controller.js';
78import snmp_controller from './configuration/controllers/snmp-controller.js';
79import firmware_controller from './configuration/controllers/firmware-controller.js';
80
81import users_index from './users/index.js';
82import user_accounts_controller from './users/controllers/user-accounts-controller.js';
83
84import phosphor_templates from './templates.js';
85
86window.angular && (function(angular) {
87  'use strict';
88
89  angular
90      .module(
91          'app',
92          [
93            // Dependencies
94            'ngRoute', 'angular-clipboard',
95            'angularUtils.directives.dirPagination',
96            // Basic resources
97            'app.templates', 'app.common.services', 'app.common.directives',
98            'app.common.filters',
99            // Model resources
100            'app.login', 'app.overview', 'app.serverControl',
101            'app.serverHealth', 'app.configuration', 'app.users', 'app.redfish'
102          ])
103      // Route configuration
104      .config([
105        '$routeProvider', '$locationProvider',
106        function($routeProvider, $locationProvider) {
107          $locationProvider.hashPrefix('');
108          $routeProvider.otherwise({'redirectTo': '/login'});
109        }
110      ])
111      .config([
112        '$compileProvider',
113        function($compileProvider) {
114          $compileProvider.aHrefSanitizationWhitelist(
115              /^\s*(https?|ftp|mailto|tel|file|data|blob):/);
116        }
117      ])
118      .config([
119        '$httpProvider',
120        function($httpProvider) {
121          $httpProvider.interceptors.push('apiInterceptor');
122          $httpProvider.defaults.headers.common = {
123            'Accept': 'application/json'
124          };
125          $httpProvider.defaults.headers.post = {
126            'Content-Type': 'application/json'
127          };
128          $httpProvider.defaults.headers.put = {
129            'Content-Type': 'application/json'
130          };
131          $httpProvider.defaults.headers.patch = {
132            'Content-Type': 'application/json'
133          };
134        }
135      ])
136      .run([
137        '$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})(window.angular);
178