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