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