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