xref: /openbmc/phosphor-webui/app/index.js (revision d0dbe3b3)
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';
38
39import filters_index from './common/filters/index.js';
40
41import directives_index from './common/directives/index.js';
42import errors from './common/directives/errors.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';
72
73import server_health_index from './server-health/index.js';
74import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js';
75import log_controller from './server-health/controllers/log-controller.js';
76import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js';
77import syslog_controller from './server-health/controllers/syslog-controller.js';
78import syslog_filter from './common/directives/syslog-filter.js';
79
80import redfish_index from './redfish/index.js';
81import redfish_controller from './redfish/controllers/redfish-controller.js';
82import configuration_index from './configuration/index.js';
83import date_time_controller from './configuration/controllers/date-time-controller.js';
84import network_controller from './configuration/controllers/network-controller.js';
85import snmp_controller from './configuration/controllers/snmp-controller.js';
86import firmware_controller from './configuration/controllers/firmware-controller.js';
87
88import users_index from './users/index.js';
89import user_accounts_controller from './users/controllers/user-accounts-controller.js';
90
91window.angular && (function(angular) {
92  'use strict';
93
94  angular
95      .module(
96          'app',
97          [
98            // Dependencies
99            'ngRoute', 'angular-clipboard', 'ngToast', 'ngAnimate',
100            'ngMessages', 'app.common.directives.dirPagination', 'ngSanitize',
101            // Basic resources
102            'app.common.services', 'app.common.directives',
103            'app.common.filters',
104            // Model resources
105            'app.login', 'app.overview', 'app.serverControl',
106            'app.serverHealth', 'app.configuration', 'app.users', 'app.redfish'
107          ])
108      // Route configuration
109      .config([
110        '$routeProvider', '$locationProvider',
111        function($routeProvider, $locationProvider) {
112          $locationProvider.hashPrefix('');
113          $routeProvider.otherwise({'redirectTo': '/login'});
114        }
115      ])
116      .config([
117        '$compileProvider',
118        function($compileProvider) {
119          $compileProvider.aHrefSanitizationWhitelist(
120              /^\s*(https?|ftp|mailto|tel|file|data|blob):/);
121        }
122      ])
123      .config([
124        '$httpProvider',
125        function($httpProvider) {
126          $httpProvider.interceptors.push('apiInterceptor');
127          $httpProvider.defaults.headers.common = {
128            'Accept': 'application/json'
129          };
130          $httpProvider.defaults.headers.post = {
131            'Content-Type': 'application/json'
132          };
133          $httpProvider.defaults.headers.put = {
134            'Content-Type': 'application/json'
135          };
136          $httpProvider.defaults.headers.patch = {
137            'Content-Type': 'application/json'
138          };
139        }
140      ])
141      .config([
142        'ngToastProvider',
143        function(ngToastProvider) {
144          ngToastProvider.configure({
145            animation: 'fade',
146            timeout: 10000,
147            dismissButton: true,
148            maxNumber: 6
149          });
150        }
151      ])
152      .run([
153        '$rootScope', '$location', 'dataService', 'userModel',
154        function($rootScope, $location, dataService, userModel) {
155          $rootScope.dataService = dataService;
156          dataService.path = $location.path();
157          $rootScope.$on('$routeChangeStart', function(event, next, current) {
158            if (next.$$route == null || next.$$route == undefined) return;
159            if (next.$$route.authenticated) {
160              if (!userModel.isLoggedIn()) {
161                $location.path('/login');
162              }
163            }
164
165            if (next.$$route.originalPath == '/' ||
166                next.$$route.originalPath == '/login') {
167              if (userModel.isLoggedIn()) {
168                if (current && current.$$route) {
169                  $location.path(current.$$route.originalPath);
170                } else {
171                  $location.path('/overview/server');
172                }
173              }
174            }
175          });
176          $rootScope.$on('$locationChangeSuccess', function(event) {
177            var path = $location.path();
178            dataService.path = path;
179            if (['/', '/login', '/logout'].indexOf(path) == -1 &&
180                path.indexOf('/login') == -1) {
181              dataService.showNavigation = true;
182            } else {
183              dataService.showNavigation = false;
184            }
185          });
186
187          $rootScope.$on('timedout-user', function() {
188            sessionStorage.removeItem('LOGIN_ID');
189            $location.path('/login');
190          });
191        }
192      ]);
193})(window.angular);
194