xref: /openbmc/phosphor-webui/app/index.js (revision d089e001)
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 * @author Developer Developer
9 */
10
11import 'bootstrap/dist/css/bootstrap.css';
12import 'bootstrap/dist/css/bootstrap-theme.css';
13import 'font-awesome/css/font-awesome.css';
14
15import angular from 'angular';
16import angular_animate from 'angular-animate';
17import angular_clipboard from 'angular-clipboard';
18import angular_cookies from 'angular-cookies';
19import angular_route from 'angular-route';
20import angular_sanitize from 'angular-sanitize';
21import angular_ui_bootstrap from 'angular-ui-bootstrap';
22import angular_ui_router from 'angular-ui-router';
23import angular_utils from 'angularUtils/src/angularUtils.js';
24import angular_utils_pagination from 'angularUtils/src/directives/pagination/dirPagination.js';
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 api_utils from './common/services/api-utils.js';
35import userModel from './common/services/userModel.js';
36import apiInterceptor from './common/services/apiInterceptor.js';
37
38import filters_index from './common/filters/index.js';
39
40import directives_index from './common/directives/index.js';
41import errors from './common/directives/errors.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 log_filter from './common/directives/log-filter.js';
47import log_search_control from './common/directives/log-search-control.js';
48import toggle_flag from './common/directives/toggle-flag.js';
49import firmware_list from './common/directives/firmware-list.js';
50import file from './common/directives/file.js';
51import loader from './common/directives/loader.js';
52import paginate from './common/directives/paginate.js';
53
54import login_index from './login/index.js';
55import login_controller from './login/controllers/login-controller.js';
56
57import overview_index from './overview/index.js';
58import system_overview_controller from './overview/controllers/system-overview-controller.js';
59
60import server_control_index from './server-control/index.js';
61import bmc_reboot_controller from './server-control/controllers/bmc-reboot-controller.js';
62import power_operations_controller from './server-control/controllers/power-operations-controller.js';
63import power_usage_controller from './server-control/controllers/power-usage-controller.js';
64import remote_console_controller from './server-control/controllers/remote-console-controller.js';
65import remote_console_window_controller from './server-control/controllers/remote-console-window-controller.js';
66import server_led_controller from './server-control/controllers/server-led-controller.js';
67
68import server_health_index from './server-health/index.js';
69import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js';
70import log_controller from './server-health/controllers/log-controller.js';
71import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js';
72
73import configuration_index from './configuration/index.js';
74import date_time_controller from './configuration/controllers/date-time-controller.js';
75import network_controller from './configuration/controllers/network-controller.js';
76import firmware_controller from './configuration/controllers/firmware-controller.js';
77
78import multi_server_index from './multi-server/index.js';
79import multi_server_controller from './multi-server/controllers/multi-server-controller.js';
80
81import users_index from './users/index.js';
82import user_accounts_controller from './users/controllers/user-accounts-controller.js';
83
84import phosphor_templates from './templates.js';
85import phosphor_vendors from './vendors.js';
86
87window.angular && (function(angular) {
88  'use strict';
89
90  angular
91      .module(
92          'app',
93          [
94            // Dependencies
95            'ngRoute', 'angular-clipboard',
96            'angularUtils.directives.dirPagination',
97            // Basic resources
98            'app.templates', 'app.vendors', 'app.common.services',
99            'app.common.directives', 'app.common.filters',
100            // Model resources
101            'app.login', 'app.overview', 'app.serverControl',
102            'app.serverHealth', 'app.configuration', 'app.users',
103            'app.multiServer'
104          ])
105      // Route configuration
106      .config([
107        '$routeProvider', '$locationProvider',
108        function($routeProvider, $locationProvider) {
109          $locationProvider.hashPrefix('');
110          $routeProvider.otherwise({'redirectTo': '/login'});
111        }
112      ])
113      .config([
114        '$compileProvider',
115        function($compileProvider) {
116          $compileProvider.aHrefSanitizationWhitelist(
117              /^\s*(https?|ftp|mailto|tel|file|data|blob):/);
118        }
119      ])
120      .config([
121        '$httpProvider',
122        function($httpProvider) {
123          $httpProvider.interceptors.push('apiInterceptor');
124        }
125      ])
126      .run([
127        '$rootScope', '$location', 'dataService', 'userModel',
128        function($rootScope, $location, dataService, userModel) {
129          $rootScope.dataService = dataService;
130          dataService.path = $location.path();
131          $rootScope.$on('$routeChangeStart', function(event, next, current) {
132            if (next.$$route == null || next.$$route == undefined) return;
133            if (next.$$route.authenticated) {
134              if (!userModel.isLoggedIn()) {
135                $location.path('/login');
136              }
137            }
138
139            if (next.$$route.originalPath == '/' ||
140                next.$$route.originalPath == '/login') {
141              if (userModel.isLoggedIn()) {
142                if (current && current.$$route) {
143                  $location.path(current.$$route.originalPath);
144                } else {
145                  $location.path('/overview/server');
146                }
147              }
148            }
149          });
150          $rootScope.$on('$locationChangeSuccess', function(event) {
151            var path = $location.path();
152            dataService.path = path;
153            if (['/', '/login', '/logout'].indexOf(path) == -1 &&
154                path.indexOf('/login') == -1) {
155              dataService.showNavigation = true;
156            } else {
157              dataService.showNavigation = false;
158            }
159          });
160
161          $rootScope.$on('timedout-user', function() {
162            sessionStorage.removeItem('LOGIN_ID');
163            $location.path('/login');
164          });
165        }
166      ]);
167})(window.angular);
168