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