Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1 | /** |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 2 | * A module which contains the definition of the application and the base of |
| 3 | * configuration |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 4 | * |
| 5 | * @module app/index/services/index |
| 6 | * @exports app/index |
| 7 | * |
| 8 | * @author Developer Developer |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 11 | import 'bootstrap/dist/css/bootstrap.css'; |
| 12 | import 'bootstrap/dist/css/bootstrap-theme.css'; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 13 | |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 14 | import angular from 'angular'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 15 | import angular_animate from 'angular-animate'; |
| 16 | import angular_clipboard from 'angular-clipboard'; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 17 | import angular_cookies from 'angular-cookies'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 18 | import angular_route from 'angular-route'; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 19 | import angular_sanitize from 'angular-sanitize'; |
| 20 | import angular_ui_bootstrap from 'angular-ui-bootstrap'; |
| 21 | import angular_ui_router from 'angular-ui-router'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 22 | import angular_utils from 'angularUtils/src/angularUtils.js'; |
| 23 | import angular_utils_pagination from 'angularUtils/src/directives/pagination/dirPagination.js'; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 24 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 25 | require('./styles/index.scss'); |
Gunnar Mills | 1d5f52c | 2018-06-27 15:42:07 -0500 | [diff] [blame] | 26 | var config = require('../config.json'); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 27 | |
| 28 | // TODO(Ed) clean this up, add the appropriate imports to phosphor-webui |
| 29 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 30 | import services_index from './common/services/index.js'; |
| 31 | import constants from './common/services/constants.js'; |
| 32 | import dataService from './common/services/dataService.js'; |
| 33 | import api_utils from './common/services/api-utils.js'; |
| 34 | import userModel from './common/services/userModel.js'; |
| 35 | import apiInterceptor from './common/services/apiInterceptor.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 36 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 37 | import filters_index from './common/filters/index.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 38 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 39 | import directives_index from './common/directives/index.js'; |
| 40 | import errors from './common/directives/errors.js'; |
| 41 | import app_header from './common/directives/app-header.js'; |
| 42 | import app_navigation from './common/directives/app-navigation.js'; |
| 43 | import confirm from './common/directives/confirm.js'; |
| 44 | import log_event from './common/directives/log-event.js'; |
| 45 | import log_filter from './common/directives/log-filter.js'; |
| 46 | import log_search_control from './common/directives/log-search-control.js'; |
| 47 | import toggle_flag from './common/directives/toggle-flag.js'; |
| 48 | import firmware_list from './common/directives/firmware-list.js'; |
| 49 | import file from './common/directives/file.js'; |
Gunnar Mills | b7ea279 | 2018-07-18 13:01:48 -0500 | [diff] [blame] | 50 | import input from './common/directives/input.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 51 | import loader from './common/directives/loader.js'; |
| 52 | import paginate from './common/directives/paginate.js'; |
beccabroek | 75697f9 | 2018-09-04 09:34:44 -0500 | [diff] [blame] | 53 | import serial_console from './common/directives/serial-console.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 54 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 55 | import login_index from './login/index.js'; |
| 56 | import login_controller from './login/controllers/login-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 57 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 58 | import overview_index from './overview/index.js'; |
| 59 | import system_overview_controller from './overview/controllers/system-overview-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 60 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 61 | import server_control_index from './server-control/index.js'; |
| 62 | import bmc_reboot_controller from './server-control/controllers/bmc-reboot-controller.js'; |
| 63 | import power_operations_controller from './server-control/controllers/power-operations-controller.js'; |
Gunnar Mills | 52b8bde | 2018-06-21 13:16:54 -0500 | [diff] [blame] | 64 | import power_usage_controller from './server-control/controllers/power-usage-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 65 | import remote_console_window_controller from './server-control/controllers/remote-console-window-controller.js'; |
Gunnar Mills | 4129f40 | 2018-07-11 16:40:58 -0500 | [diff] [blame] | 66 | import server_led_controller from './server-control/controllers/server-led-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 67 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 68 | import server_health_index from './server-health/index.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 69 | import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js'; |
| 70 | import log_controller from './server-health/controllers/log-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 71 | import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 72 | |
James Feist | e8634e6 | 2018-09-07 14:25:48 -0700 | [diff] [blame] | 73 | import redfish_index from './redfish/index.js'; |
| 74 | import redfish_controller from './redfish/controllers/redfish-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 75 | import configuration_index from './configuration/index.js'; |
| 76 | import date_time_controller from './configuration/controllers/date-time-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 77 | import network_controller from './configuration/controllers/network-controller.js'; |
Gunnar Mills | ff64c54 | 2018-08-24 15:49:09 -0500 | [diff] [blame] | 78 | import snmp_controller from './configuration/controllers/snmp-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 79 | import firmware_controller from './configuration/controllers/firmware-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 80 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 81 | import users_index from './users/index.js'; |
| 82 | import user_accounts_controller from './users/controllers/user-accounts-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 83 | |
| 84 | import phosphor_templates from './templates.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 85 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 86 | window.angular && (function(angular) { |
| 87 | 'use strict'; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 88 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 89 | angular |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 90 | .module( |
| 91 | 'app', |
| 92 | [ |
| 93 | // Dependencies |
| 94 | 'ngRoute', 'angular-clipboard', |
| 95 | 'angularUtils.directives.dirPagination', |
| 96 | // Basic resources |
beccabroek | 0d7875b | 2018-09-11 10:39:49 -0500 | [diff] [blame] | 97 | 'app.templates', 'app.common.services', 'app.common.directives', |
| 98 | 'app.common.filters', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 99 | // Model resources |
| 100 | 'app.login', 'app.overview', 'app.serverControl', |
Gunnar Mills | 1085098 | 2018-10-22 13:20:05 -0500 | [diff] [blame^] | 101 | 'app.serverHealth', 'app.configuration', 'app.users', 'app.redfish' |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 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'); |
Gunnar Mills | dd9d4c3 | 2018-09-10 12:59:34 -0500 | [diff] [blame] | 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 | }; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 134 | } |
| 135 | ]) |
| 136 | .run([ |
| 137 | '$rootScope', '$location', 'dataService', 'userModel', |
| 138 | function($rootScope, $location, dataService, userModel) { |
| 139 | $rootScope.dataService = dataService; |
| 140 | dataService.path = $location.path(); |
| 141 | $rootScope.$on('$routeChangeStart', function(event, next, current) { |
| 142 | if (next.$$route == null || next.$$route == undefined) return; |
| 143 | if (next.$$route.authenticated) { |
| 144 | if (!userModel.isLoggedIn()) { |
| 145 | $location.path('/login'); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 146 | } |
| 147 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 148 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 149 | if (next.$$route.originalPath == '/' || |
| 150 | next.$$route.originalPath == '/login') { |
| 151 | if (userModel.isLoggedIn()) { |
| 152 | if (current && current.$$route) { |
| 153 | $location.path(current.$$route.originalPath); |
| 154 | } else { |
| 155 | $location.path('/overview/server'); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | }); |
| 160 | $rootScope.$on('$locationChangeSuccess', function(event) { |
| 161 | var path = $location.path(); |
| 162 | dataService.path = path; |
| 163 | if (['/', '/login', '/logout'].indexOf(path) == -1 && |
| 164 | path.indexOf('/login') == -1) { |
| 165 | dataService.showNavigation = true; |
| 166 | } else { |
| 167 | dataService.showNavigation = false; |
| 168 | } |
| 169 | }); |
| 170 | |
| 171 | $rootScope.$on('timedout-user', function() { |
| 172 | sessionStorage.removeItem('LOGIN_ID'); |
| 173 | $location.path('/login'); |
| 174 | }); |
| 175 | } |
| 176 | ]); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 177 | })(window.angular); |