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 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 input from './common/directives/input.js'; 52import click_outside from './common/directives/click-outside.js'; 53import loader from './common/directives/loader.js'; 54import paginate from './common/directives/paginate.js'; 55import serial_console from './common/directives/serial-console.js'; 56import dir_paginate from './common/directives/dirPagination.js'; 57 58import login_index from './login/index.js'; 59import login_controller from './login/controllers/login-controller.js'; 60 61import overview_index from './overview/index.js'; 62import system_overview_controller from './overview/controllers/system-overview-controller.js'; 63 64import server_control_index from './server-control/index.js'; 65import bmc_reboot_controller from './server-control/controllers/bmc-reboot-controller.js'; 66import power_operations_controller from './server-control/controllers/power-operations-controller.js'; 67import power_usage_controller from './server-control/controllers/power-usage-controller.js'; 68import remote_console_window_controller from './server-control/controllers/remote-console-window-controller.js'; 69import server_led_controller from './server-control/controllers/server-led-controller.js'; 70 71import server_health_index from './server-health/index.js'; 72import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js'; 73import log_controller from './server-health/controllers/log-controller.js'; 74import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js'; 75 76import redfish_index from './redfish/index.js'; 77import redfish_controller from './redfish/controllers/redfish-controller.js'; 78import configuration_index from './configuration/index.js'; 79import date_time_controller from './configuration/controllers/date-time-controller.js'; 80import network_controller from './configuration/controllers/network-controller.js'; 81import snmp_controller from './configuration/controllers/snmp-controller.js'; 82import firmware_controller from './configuration/controllers/firmware-controller.js'; 83 84import users_index from './users/index.js'; 85import user_accounts_controller from './users/controllers/user-accounts-controller.js'; 86 87window.angular && (function(angular) { 88 'use strict'; 89 90 angular 91 .module( 92 'app', 93 [ 94 // Dependencies 95 'ngRoute', 'angular-clipboard', 'ngToast', 'ngAnimate', 96 'ngMessages', 'app.common.directives.dirPagination', 'ngSanitize', 97 // Basic resources 98 'app.common.services', 'app.common.directives', 99 'app.common.filters', 100 // Model resources 101 'app.login', 'app.overview', 'app.serverControl', 102 'app.serverHealth', 'app.configuration', 'app.users', 'app.redfish' 103 ]) 104 // Route configuration 105 .config([ 106 '$routeProvider', '$locationProvider', 107 function($routeProvider, $locationProvider) { 108 $locationProvider.hashPrefix(''); 109 $routeProvider.otherwise({'redirectTo': '/login'}); 110 } 111 ]) 112 .config([ 113 '$compileProvider', 114 function($compileProvider) { 115 $compileProvider.aHrefSanitizationWhitelist( 116 /^\s*(https?|ftp|mailto|tel|file|data|blob):/); 117 } 118 ]) 119 .config([ 120 '$httpProvider', 121 function($httpProvider) { 122 $httpProvider.interceptors.push('apiInterceptor'); 123 $httpProvider.defaults.headers.common = { 124 'Accept': 'application/json' 125 }; 126 $httpProvider.defaults.headers.post = { 127 'Content-Type': 'application/json' 128 }; 129 $httpProvider.defaults.headers.put = { 130 'Content-Type': 'application/json' 131 }; 132 $httpProvider.defaults.headers.patch = { 133 'Content-Type': 'application/json' 134 }; 135 } 136 ]) 137 .config([ 138 'ngToastProvider', 139 function(ngToastProvider) { 140 ngToastProvider.configure({ 141 animation: 'fade', 142 timeout: 10000, 143 dismissButton: true, 144 maxNumber: 6 145 }); 146 } 147 ]) 148 .run([ 149 '$rootScope', '$location', 'dataService', 'userModel', 150 function($rootScope, $location, dataService, userModel) { 151 $rootScope.dataService = dataService; 152 dataService.path = $location.path(); 153 $rootScope.$on('$routeChangeStart', function(event, next, current) { 154 if (next.$$route == null || next.$$route == undefined) return; 155 if (next.$$route.authenticated) { 156 if (!userModel.isLoggedIn()) { 157 $location.path('/login'); 158 } 159 } 160 161 if (next.$$route.originalPath == '/' || 162 next.$$route.originalPath == '/login') { 163 if (userModel.isLoggedIn()) { 164 if (current && current.$$route) { 165 $location.path(current.$$route.originalPath); 166 } else { 167 $location.path('/overview/server'); 168 } 169 } 170 } 171 }); 172 $rootScope.$on('$locationChangeSuccess', function(event) { 173 var path = $location.path(); 174 dataService.path = path; 175 if (['/', '/login', '/logout'].indexOf(path) == -1 && 176 path.indexOf('/login') == -1) { 177 dataService.showNavigation = true; 178 } else { 179 dataService.showNavigation = false; 180 } 181 }); 182 183 $rootScope.$on('timedout-user', function() { 184 sessionStorage.removeItem('LOGIN_ID'); 185 $location.path('/login'); 186 }); 187 } 188 ]); 189})(window.angular); 190