xref: /openbmc/phosphor-webui/app/index.js (revision 81ad97e4)
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';
74import status_icon from './common/components/status-icon.js';
75
76import login_index from './login/index.js';
77import login_controller from './login/controllers/login-controller.js';
78
79import overview_index from './overview/index.js';
80import system_overview_controller from './overview/controllers/system-overview-controller.js';
81
82import server_control_index from './server-control/index.js';
83import bmc_reboot_controller from './server-control/controllers/bmc-reboot-controller.js';
84import power_operations_controller from './server-control/controllers/power-operations-controller.js';
85import power_usage_controller from './server-control/controllers/power-usage-controller.js';
86import remote_console_window_controller from './server-control/controllers/remote-console-window-controller.js';
87import server_led_controller from './server-control/controllers/server-led-controller.js';
88import vm_controller from './server-control/controllers/virtual-media-controller.js';
89import kvm_console from './server-control/directives/kvm-console.js';
90import kvm_window_controller from './server-control/controllers/kvm-window-controller.js';
91
92import server_health_index from './server-health/index.js';
93import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js';
94import log_controller from './server-health/controllers/log-controller.js';
95import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js';
96import syslog_controller from './server-health/controllers/syslog-controller.js';
97import syslog_filter from './common/directives/syslog-filter.js';
98import remote_logging_server from './server-health/directives/remote-logging-server.js';
99
100import redfish_index from './redfish/index.js';
101import redfish_controller from './redfish/controllers/redfish-controller.js';
102import configuration_index from './configuration/index.js';
103import date_time_controller from './configuration/controllers/date-time-controller.js';
104import network_controller from './configuration/controllers/network-controller.js';
105import snmp_controller from './configuration/controllers/snmp-controller.js';
106import firmware_controller from './configuration/controllers/firmware-controller.js';
107
108import access_control from './access-control/index.js';
109import user_controller from './access-control/controllers/user-controller.js';
110import username_validator from './access-control/directives/username-validator.js';
111import role_table from './access-control/directives/role-table.js';
112import certificate_controller from './access-control/controllers/certificate-controller.js';
113import ldap_controller from './access-control/controllers/ldap-controller.js';
114
115
116window.angular && (function(angular) {
117  'use strict';
118
119  angular
120      .module(
121          'app',
122          [
123            // Dependencies
124            'ngRoute', 'angular-clipboard', 'ngToast', 'ngAnimate',
125            'ngMessages', 'app.common.directives.dirPagination', 'ngSanitize',
126            'ui.bootstrap',
127            // Basic resources
128            'app.common.services', 'app.common.directives',
129            'app.common.filters', 'app.common.components',
130            // Model resources
131            'app.login', 'app.overview', 'app.serverControl',
132            'app.serverHealth', 'app.configuration', 'app.accessControl',
133            'app.redfish'
134          ])
135      // Route configuration
136      .config([
137        '$routeProvider', '$locationProvider',
138        function($routeProvider, $locationProvider) {
139          $locationProvider.hashPrefix('');
140          $routeProvider.when(
141              '/unauthorized', {'template': require('./403.html')})
142          $routeProvider.otherwise({'redirectTo': '/login'});
143        }
144      ])
145      .config([
146        '$compileProvider',
147        function($compileProvider) {
148          $compileProvider.aHrefSanitizationWhitelist(
149              /^\s*(https?|ftp|mailto|tel|file|data|blob):/);
150        }
151      ])
152      .config([
153        '$httpProvider',
154        function($httpProvider) {
155          $httpProvider.interceptors.push('apiInterceptor');
156          $httpProvider.defaults.headers.common = {
157            'Accept': 'application/json; charset=utf-8'
158          };
159          $httpProvider.defaults.headers.post = {
160            'Content-Type': 'application/json; charset=utf-8'
161          };
162          $httpProvider.defaults.headers.put = {
163            'Content-Type': 'application/json; charset=utf-8'
164          };
165          $httpProvider.defaults.headers.patch = {
166            'Content-Type': 'application/json; charset=utf-8'
167          };
168        }
169      ])
170      .config([
171        'ngToastProvider',
172        function(ngToastProvider) {
173          ngToastProvider.configure({
174            animation: 'fade',
175            timeout: 10000,
176            dismissButton: true,
177            maxNumber: 6
178          });
179        }
180      ])
181      .run([
182        '$rootScope', '$location', 'dataService', 'userModel',
183        function($rootScope, $location, dataService, userModel) {
184          $rootScope.dataService = dataService;
185          dataService.path = $location.path();
186          $rootScope.$on('$routeChangeStart', function(event, next, current) {
187            if (next.$$route == null || next.$$route == undefined) return;
188            if (next.$$route.authenticated) {
189              if (!userModel.isLoggedIn()) {
190                $location.path('/login');
191              }
192            }
193
194            if (next.$$route.originalPath == '/' ||
195                next.$$route.originalPath == '/login') {
196              if (userModel.isLoggedIn()) {
197                if (current && current.$$route) {
198                  $location.path(current.$$route.originalPath);
199                } else {
200                  $location.path('/overview/server');
201                }
202              }
203            }
204          });
205          $rootScope.$on('$locationChangeSuccess', function(event) {
206            var path = $location.path();
207            dataService.path = path;
208            if (['/', '/login', '/logout'].indexOf(path) == -1 &&
209                path.indexOf('/login') == -1) {
210              dataService.showNavigation = true;
211            } else {
212              dataService.showNavigation = false;
213            }
214          });
215
216          $rootScope.$on('timedout-user', function() {
217            sessionStorage.removeItem('LOGIN_ID');
218            $location.path('/login');
219          });
220        }
221      ]);
222})(window.angular);
223