xref: /openbmc/phosphor-webui/app/index.js (revision eaa40dd3)
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 'angular/angular-csp.css';
10import 'bootstrap/dist/css/bootstrap.css';
11
12import angular from 'angular';
13import angular_animate from 'angular-animate';
14import angular_clipboard from 'angular-clipboard';
15import angular_cookies from 'angular-cookies';
16import angular_messages from 'angular-messages';
17import angular_route from 'angular-route';
18import angular_sanitize from 'angular-sanitize';
19import angular_ui_bootstrap from 'angular-ui-bootstrap';
20import angular_ui_router from 'angular-ui-router';
21import ngToast from 'ng-toast';
22import ngToast_animate from 'ng-toast/dist/ngToast-animations.css';
23import ngToast_style from 'ng-toast/dist/ngToast.css';
24
25require('./styles/index.scss');
26var config = require('../config.json');
27
28// TODO(Ed)  clean this up, add the appropriate imports to phosphor-webui
29
30import services_index from './common/services/index.js';
31import constants from './common/services/constants.js';
32import dataService from './common/services/dataService.js';
33import toastService from './common/services/toastService.js';
34import api_utils from './common/services/api-utils.js';
35import userModel from './common/services/userModel.js';
36import apiInterceptor from './common/services/apiInterceptor.js';
37import nbdServerService from './common/services/nbdServerService.js';
38
39import filters_index from './common/filters/index.js';
40
41import directives_index from './common/directives/index.js';
42import app_header from './common/directives/app-header.js';
43import app_navigation from './common/directives/app-navigation.js';
44import confirm from './common/directives/confirm.js';
45import log_event from './common/directives/log-event.js';
46import certificate from './common/directives/certificate.js';
47import log_filter from './common/directives/log-filter.js';
48import log_search_control from './common/directives/log-search-control.js';
49import toggle_flag from './common/directives/toggle-flag.js';
50import firmware_list from './common/directives/firmware-list.js';
51import file from './common/directives/file.js';
52import input from './common/directives/input.js';
53import click_outside from './common/directives/click-outside.js';
54import loader from './common/directives/loader.js';
55import paginate from './common/directives/paginate.js';
56import serial_console from './common/directives/serial-console.js';
57import dir_paginate from './common/directives/dirPagination.js';
58import form_input_error from './common/directives/form-input-error.js';
59import icon_provider from './common/directives/icon-provider.js';
60
61import login_index from './login/index.js';
62import login_controller from './login/controllers/login-controller.js';
63
64import overview_index from './overview/index.js';
65import system_overview_controller from './overview/controllers/system-overview-controller.js';
66
67import server_control_index from './server-control/index.js';
68import bmc_reboot_controller from './server-control/controllers/bmc-reboot-controller.js';
69import power_operations_controller from './server-control/controllers/power-operations-controller.js';
70import power_usage_controller from './server-control/controllers/power-usage-controller.js';
71import remote_console_window_controller from './server-control/controllers/remote-console-window-controller.js';
72import server_led_controller from './server-control/controllers/server-led-controller.js';
73import kvm_controller from './server-control/controllers/kvm-controller.js';
74
75import server_health_index from './server-health/index.js';
76import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js';
77import log_controller from './server-health/controllers/log-controller.js';
78import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js';
79import syslog_controller from './server-health/controllers/syslog-controller.js';
80import syslog_filter from './common/directives/syslog-filter.js';
81import remote_logging_server from './server-health/directives/remote-logging-server.js';
82
83import redfish_index from './redfish/index.js';
84import redfish_controller from './redfish/controllers/redfish-controller.js';
85import configuration_index from './configuration/index.js';
86import date_time_controller from './configuration/controllers/date-time-controller.js';
87import certificate_controller from './configuration/controllers/certificate-controller.js';
88import network_controller from './configuration/controllers/network-controller.js';
89import snmp_controller from './configuration/controllers/snmp-controller.js';
90import firmware_controller from './configuration/controllers/firmware-controller.js';
91import vm_controller from './configuration/controllers/virtual-media-controller.js';
92
93import users_index from './users/index.js';
94import user_accounts_controller from './users/controllers/user-accounts-controller.js';
95
96window.angular && (function(angular) {
97  'use strict';
98
99  angular
100      .module(
101          'app',
102          [
103            // Dependencies
104            'ngRoute', 'angular-clipboard', 'ngToast', 'ngAnimate',
105            'ngMessages', 'app.common.directives.dirPagination', 'ngSanitize',
106            'ui.bootstrap',
107            // Basic resources
108            'app.common.services', 'app.common.directives',
109            'app.common.filters',
110            // Model resources
111            'app.login', 'app.overview', 'app.serverControl',
112            'app.serverHealth', 'app.configuration', 'app.users', 'app.redfish'
113          ])
114      // Route configuration
115      .config([
116        '$routeProvider', '$locationProvider',
117        function($routeProvider, $locationProvider) {
118          $locationProvider.hashPrefix('');
119          $routeProvider.when(
120              '/unauthorized', {'template': require('./403.html')})
121          $routeProvider.otherwise({'redirectTo': '/login'});
122        }
123      ])
124      .config([
125        '$compileProvider',
126        function($compileProvider) {
127          $compileProvider.aHrefSanitizationWhitelist(
128              /^\s*(https?|ftp|mailto|tel|file|data|blob):/);
129        }
130      ])
131      .config([
132        '$httpProvider',
133        function($httpProvider) {
134          $httpProvider.interceptors.push('apiInterceptor');
135          $httpProvider.defaults.headers.common = {
136            'Accept': 'application/json'
137          };
138          $httpProvider.defaults.headers.post = {
139            'Content-Type': 'application/json'
140          };
141          $httpProvider.defaults.headers.put = {
142            'Content-Type': 'application/json'
143          };
144          $httpProvider.defaults.headers.patch = {
145            'Content-Type': 'application/json'
146          };
147        }
148      ])
149      .config([
150        'ngToastProvider',
151        function(ngToastProvider) {
152          ngToastProvider.configure({
153            animation: 'fade',
154            timeout: 10000,
155            dismissButton: true,
156            maxNumber: 6
157          });
158        }
159      ])
160      .run([
161        '$rootScope', '$location', 'dataService', 'userModel',
162        function($rootScope, $location, dataService, userModel) {
163          $rootScope.dataService = dataService;
164          dataService.path = $location.path();
165          $rootScope.$on('$routeChangeStart', function(event, next, current) {
166            if (next.$$route == null || next.$$route == undefined) return;
167            if (next.$$route.authenticated) {
168              if (!userModel.isLoggedIn()) {
169                $location.path('/login');
170              }
171            }
172
173            if (next.$$route.originalPath == '/' ||
174                next.$$route.originalPath == '/login') {
175              if (userModel.isLoggedIn()) {
176                if (current && current.$$route) {
177                  $location.path(current.$$route.originalPath);
178                } else {
179                  $location.path('/overview/server');
180                }
181              }
182            }
183          });
184          $rootScope.$on('$locationChangeSuccess', function(event) {
185            var path = $location.path();
186            dataService.path = path;
187            if (['/', '/login', '/logout'].indexOf(path) == -1 &&
188                path.indexOf('/login') == -1) {
189              dataService.showNavigation = true;
190            } else {
191              dataService.showNavigation = false;
192            }
193          });
194
195          $rootScope.$on('timedout-user', function() {
196            sessionStorage.removeItem('LOGIN_ID');
197            $location.path('/login');
198          });
199        }
200      ]);
201})(window.angular);
202