xref: /openbmc/phosphor-webui/app/index.js (revision dbf04811)
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 */
9
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_route from 'angular-route';
17import angular_sanitize from 'angular-sanitize';
18import angular_ui_bootstrap from 'angular-ui-bootstrap';
19import angular_ui_router from 'angular-ui-router';
20
21require('./styles/index.scss');
22var config = require('../config.json');
23
24// TODO(Ed)  clean this up, add the appropriate imports to phosphor-webui
25
26import services_index from './common/services/index.js';
27import constants from './common/services/constants.js';
28import dataService from './common/services/dataService.js';
29import api_utils from './common/services/api-utils.js';
30import userModel from './common/services/userModel.js';
31import apiInterceptor from './common/services/apiInterceptor.js';
32
33import filters_index from './common/filters/index.js';
34
35import directives_index from './common/directives/index.js';
36import errors from './common/directives/errors.js';
37import app_header from './common/directives/app-header.js';
38import app_navigation from './common/directives/app-navigation.js';
39import confirm from './common/directives/confirm.js';
40import log_event from './common/directives/log-event.js';
41import log_filter from './common/directives/log-filter.js';
42import log_search_control from './common/directives/log-search-control.js';
43import toggle_flag from './common/directives/toggle-flag.js';
44import firmware_list from './common/directives/firmware-list.js';
45import file from './common/directives/file.js';
46import input from './common/directives/input.js';
47import loader from './common/directives/loader.js';
48import paginate from './common/directives/paginate.js';
49import serial_console from './common/directives/serial-console.js';
50import dir_paginate from './common/directives/dirPagination.js';
51
52import login_index from './login/index.js';
53import login_controller from './login/controllers/login-controller.js';
54
55import overview_index from './overview/index.js';
56import system_overview_controller from './overview/controllers/system-overview-controller.js';
57
58import server_control_index from './server-control/index.js';
59import bmc_reboot_controller from './server-control/controllers/bmc-reboot-controller.js';
60import power_operations_controller from './server-control/controllers/power-operations-controller.js';
61import power_usage_controller from './server-control/controllers/power-usage-controller.js';
62import remote_console_window_controller from './server-control/controllers/remote-console-window-controller.js';
63import server_led_controller from './server-control/controllers/server-led-controller.js';
64
65import server_health_index from './server-health/index.js';
66import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js';
67import log_controller from './server-health/controllers/log-controller.js';
68import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js';
69
70import redfish_index from './redfish/index.js';
71import redfish_controller from './redfish/controllers/redfish-controller.js';
72import configuration_index from './configuration/index.js';
73import date_time_controller from './configuration/controllers/date-time-controller.js';
74import network_controller from './configuration/controllers/network-controller.js';
75import snmp_controller from './configuration/controllers/snmp-controller.js';
76import firmware_controller from './configuration/controllers/firmware-controller.js';
77
78import users_index from './users/index.js';
79import user_accounts_controller from './users/controllers/user-accounts-controller.js';
80
81window.angular && (function(angular) {
82  'use strict';
83
84  angular
85      .module(
86          'app',
87          [
88            // Dependencies
89            'ngRoute', 'angular-clipboard',
90            'app.common.directives.dirPagination',
91            // Basic resources
92            'app.common.services', 'app.common.directives',
93            'app.common.filters',
94            // Model resources
95            'app.login', 'app.overview', 'app.serverControl',
96            'app.serverHealth', 'app.configuration', 'app.users', 'app.redfish'
97          ])
98      // Route configuration
99      .config([
100        '$routeProvider', '$locationProvider',
101        function($routeProvider, $locationProvider) {
102          $locationProvider.hashPrefix('');
103          $routeProvider.otherwise({'redirectTo': '/login'});
104        }
105      ])
106      .config([
107        '$compileProvider',
108        function($compileProvider) {
109          $compileProvider.aHrefSanitizationWhitelist(
110              /^\s*(https?|ftp|mailto|tel|file|data|blob):/);
111        }
112      ])
113      .config([
114        '$httpProvider',
115        function($httpProvider) {
116          $httpProvider.interceptors.push('apiInterceptor');
117          $httpProvider.defaults.headers.common = {
118            'Accept': 'application/json'
119          };
120          $httpProvider.defaults.headers.post = {
121            'Content-Type': 'application/json'
122          };
123          $httpProvider.defaults.headers.put = {
124            'Content-Type': 'application/json'
125          };
126          $httpProvider.defaults.headers.patch = {
127            'Content-Type': 'application/json'
128          };
129        }
130      ])
131      .run([
132        '$rootScope', '$location', 'dataService', 'userModel',
133        function($rootScope, $location, dataService, userModel) {
134          $rootScope.dataService = dataService;
135          dataService.path = $location.path();
136          $rootScope.$on('$routeChangeStart', function(event, next, current) {
137            if (next.$$route == null || next.$$route == undefined) return;
138            if (next.$$route.authenticated) {
139              if (!userModel.isLoggedIn()) {
140                $location.path('/login');
141              }
142            }
143
144            if (next.$$route.originalPath == '/' ||
145                next.$$route.originalPath == '/login') {
146              if (userModel.isLoggedIn()) {
147                if (current && current.$$route) {
148                  $location.path(current.$$route.originalPath);
149                } else {
150                  $location.path('/overview/server');
151                }
152              }
153            }
154          });
155          $rootScope.$on('$locationChangeSuccess', function(event) {
156            var path = $location.path();
157            dataService.path = path;
158            if (['/', '/login', '/logout'].indexOf(path) == -1 &&
159                path.indexOf('/login') == -1) {
160              dataService.showNavigation = true;
161            } else {
162              dataService.showNavigation = false;
163            }
164          });
165
166          $rootScope.$on('timedout-user', function() {
167            sessionStorage.removeItem('LOGIN_ID');
168            $location.path('/login');
169          });
170        }
171      ]);
172})(window.angular);
173