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