xref: /openbmc/phosphor-webui/app/index.js (revision 198ce1ff)
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 */
9import 'core-js/stable';
10import 'regenerator-runtime/runtime';
11import 'core-js/es/symbol';
12
13
14import 'angular/angular-csp.css';
15import 'bootstrap/dist/css/bootstrap.css';
16
17import angular from 'angular';
18import angular_animate from 'angular-animate';
19import angular_clipboard from 'angular-clipboard';
20import angular_cookies from 'angular-cookies';
21import angular_messages from 'angular-messages';
22import angular_route from 'angular-route';
23import angular_sanitize from 'angular-sanitize';
24import angular_ui_bootstrap from 'angular-ui-bootstrap';
25import angular_ui_router from 'angular-ui-router';
26import ngToast from 'ng-toast';
27import ngToast_animate from 'ng-toast/dist/ngToast-animations.css';
28import ngToast_style from 'ng-toast/dist/ngToast.css';
29
30require('./styles/index.scss');
31var config = require('../config.json');
32
33// TODO(Ed)  clean this up, add the appropriate imports to phosphor-webui
34
35import services_index from './common/services/index.js';
36import constants from './common/services/constants.js';
37import dataService from './common/services/dataService.js';
38import toastService from './common/services/toastService.js';
39import api_utils from './common/services/api-utils.js';
40import userModel from './common/services/userModel.js';
41import apiInterceptor from './common/services/apiInterceptor.js';
42import nbdServerService from './common/services/nbdServerService.js';
43
44import filters_index from './common/filters/index.js';
45
46import directives_index from './common/directives/index.js';
47import app_header from './common/directives/app-header.js';
48import app_navigation from './common/directives/app-navigation.js';
49import confirm from './common/directives/confirm.js';
50import log_event from './common/directives/log-event.js';
51import certificate from './common/directives/certificate.js';
52import log_filter from './common/directives/log-filter.js';
53import log_search_control from './common/directives/log-search-control.js';
54import ldap_user_roles from './common/directives/ldap-user-roles.js';
55import toggle_flag from './common/directives/toggle-flag.js';
56import firmware_list from './common/directives/firmware-list.js';
57import file from './common/directives/file.js';
58import input from './common/directives/input.js';
59import click_outside from './common/directives/click-outside.js';
60import loader from './common/directives/loader.js';
61import paginate from './common/directives/paginate.js';
62import serial_console from './common/directives/serial-console.js';
63import dir_paginate from './common/directives/dirPagination.js';
64import form_input_error from './common/directives/form-input-error.js';
65import icon_provider from './common/directives/icon-provider.js';
66import password_confirmation from './common/directives/password-confirmation.js';
67import password_visibility_toggle from './common/directives/password-visibility-toggle/password-visibility-toggle.js';
68
69import components_index from './common/components/index.js';
70import table_component from './common/components/table/table.js';
71import table_actions_component from './common/components/table/table-actions.js';
72import table_toolbar_component from './common/components/table/table-toolbar.js';
73import table_checkbox from './common/components/table/table-checkbox.js';
74
75import login_index from './login/index.js';
76import login_controller from './login/controllers/login-controller.js';
77
78import overview_index from './overview/index.js';
79import system_overview_controller from './overview/controllers/system-overview-controller.js';
80
81import server_control_index from './server-control/index.js';
82import bmc_reboot_controller from './server-control/controllers/bmc-reboot-controller.js';
83import power_operations_controller from './server-control/controllers/power-operations-controller.js';
84import power_usage_controller from './server-control/controllers/power-usage-controller.js';
85import remote_console_window_controller from './server-control/controllers/remote-console-window-controller.js';
86import server_led_controller from './server-control/controllers/server-led-controller.js';
87import vm_controller from './server-control/controllers/virtual-media-controller.js';
88import kvm_console from './server-control/directives/kvm-console.js';
89
90import server_health_index from './server-health/index.js';
91import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js';
92import log_controller from './server-health/controllers/log-controller.js';
93import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js';
94import syslog_controller from './server-health/controllers/syslog-controller.js';
95import syslog_filter from './common/directives/syslog-filter.js';
96import remote_logging_server from './server-health/directives/remote-logging-server.js';
97
98import redfish_index from './redfish/index.js';
99import redfish_controller from './redfish/controllers/redfish-controller.js';
100import configuration_index from './configuration/index.js';
101import date_time_controller from './configuration/controllers/date-time-controller.js';
102import network_controller from './configuration/controllers/network-controller.js';
103import snmp_controller from './configuration/controllers/snmp-controller.js';
104import firmware_controller from './configuration/controllers/firmware-controller.js';
105
106import access_control from './access-control/index.js';
107import user_controller from './access-control/controllers/user-controller.js';
108import username_validator from './access-control/directives/username-validator.js';
109import role_table from './access-control/directives/role-table.js';
110import certificate_controller from './access-control/controllers/certificate-controller.js';
111import ldap_controller from './access-control/controllers/ldap-controller.js';
112
113
114window.angular && (function(angular) {
115  'use strict';
116
117  angular
118      .module(
119          'app',
120          [
121            // Dependencies
122            'ngRoute', 'angular-clipboard', 'ngToast', 'ngAnimate',
123            'ngMessages', 'app.common.directives.dirPagination', 'ngSanitize',
124            'ui.bootstrap',
125            // Basic resources
126            'app.common.services', 'app.common.directives',
127            'app.common.filters', 'app.common.components',
128            // Model resources
129            'app.login', 'app.overview', 'app.serverControl',
130            'app.serverHealth', 'app.configuration', 'app.accessControl',
131            'app.redfish'
132          ])
133      // Route configuration
134      .config([
135        '$routeProvider', '$locationProvider',
136        function($routeProvider, $locationProvider) {
137          $locationProvider.hashPrefix('');
138          $routeProvider.when(
139              '/unauthorized', {'template': require('./403.html')})
140          $routeProvider.otherwise({'redirectTo': '/login'});
141        }
142      ])
143      .config([
144        '$compileProvider',
145        function($compileProvider) {
146          $compileProvider.aHrefSanitizationWhitelist(
147              /^\s*(https?|ftp|mailto|tel|file|data|blob):/);
148        }
149      ])
150      .config([
151        '$httpProvider',
152        function($httpProvider) {
153          $httpProvider.interceptors.push('apiInterceptor');
154          $httpProvider.defaults.headers.common = {
155            'Accept': 'application/json; charset=utf-8'
156          };
157          $httpProvider.defaults.headers.post = {
158            'Content-Type': 'application/json; charset=utf-8'
159          };
160          $httpProvider.defaults.headers.put = {
161            'Content-Type': 'application/json; charset=utf-8'
162          };
163          $httpProvider.defaults.headers.patch = {
164            'Content-Type': 'application/json; charset=utf-8'
165          };
166        }
167      ])
168      .config([
169        'ngToastProvider',
170        function(ngToastProvider) {
171          ngToastProvider.configure({
172            animation: 'fade',
173            timeout: 10000,
174            dismissButton: true,
175            maxNumber: 6
176          });
177        }
178      ])
179      .run([
180        '$rootScope', '$location', 'dataService', 'userModel',
181        function($rootScope, $location, dataService, userModel) {
182          $rootScope.dataService = dataService;
183          dataService.path = $location.path();
184          $rootScope.$on('$routeChangeStart', function(event, next, current) {
185            if (next.$$route == null || next.$$route == undefined) return;
186            if (next.$$route.authenticated) {
187              if (!userModel.isLoggedIn()) {
188                $location.path('/login');
189              }
190            }
191
192            if (next.$$route.originalPath == '/' ||
193                next.$$route.originalPath == '/login') {
194              if (userModel.isLoggedIn()) {
195                if (current && current.$$route) {
196                  $location.path(current.$$route.originalPath);
197                } else {
198                  $location.path('/overview/server');
199                }
200              }
201            }
202          });
203          $rootScope.$on('$locationChangeSuccess', function(event) {
204            var path = $location.path();
205            dataService.path = path;
206            if (['/', '/login', '/logout'].indexOf(path) == -1 &&
207                path.indexOf('/login') == -1) {
208              dataService.showNavigation = true;
209            } else {
210              dataService.showNavigation = false;
211            }
212          });
213
214          $rootScope.$on('timedout-user', function() {
215            sessionStorage.removeItem('LOGIN_ID');
216            $location.path('/login');
217          });
218        }
219      ]);
220})(window.angular);
221