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