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