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