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