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 | * |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 8 | */ |
Ed Tanous | 11adec7 | 2018-12-19 17:59:28 -0800 | [diff] [blame] | 9 | import 'angular/angular-csp.css'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 10 | import 'bootstrap/dist/css/bootstrap.css'; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 11 | |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 12 | import angular from 'angular'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 13 | import angular_animate from 'angular-animate'; |
| 14 | import angular_clipboard from 'angular-clipboard'; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 15 | import angular_cookies from 'angular-cookies'; |
beccabroek | a3b397d | 2019-01-23 14:03:20 -0600 | [diff] [blame] | 16 | import angular_messages from 'angular-messages'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 17 | import angular_route from 'angular-route'; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 18 | import angular_sanitize from 'angular-sanitize'; |
| 19 | import angular_ui_bootstrap from 'angular-ui-bootstrap'; |
| 20 | import angular_ui_router from 'angular-ui-router'; |
beccabroek | a30394b | 2018-12-14 17:19:45 -0600 | [diff] [blame] | 21 | import ngToast from 'ng-toast'; |
| 22 | import ngToast_animate from 'ng-toast/dist/ngToast-animations.css'; |
| 23 | import ngToast_style from 'ng-toast/dist/ngToast.css'; |
| 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'; |
beccabroek | 27ce84d | 2019-02-05 15:43:17 -0600 | [diff] [blame] | 33 | import toastService from './common/services/toastService.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 34 | import api_utils from './common/services/api-utils.js'; |
| 35 | import userModel from './common/services/userModel.js'; |
| 36 | import apiInterceptor from './common/services/apiInterceptor.js'; |
beccabroek | 44da471 | 2019-03-20 13:24:23 -0500 | [diff] [blame] | 37 | import nbdServerService from './common/services/nbdServerService.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 filters_index from './common/filters/index.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 40 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 41 | import directives_index from './common/directives/index.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 42 | import app_header from './common/directives/app-header.js'; |
| 43 | import app_navigation from './common/directives/app-navigation.js'; |
| 44 | import confirm from './common/directives/confirm.js'; |
| 45 | import log_event from './common/directives/log-event.js'; |
beccabroek | 309b5da | 2018-11-07 12:22:31 -0600 | [diff] [blame] | 46 | import certificate from './common/directives/certificate.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 47 | import log_filter from './common/directives/log-filter.js'; |
| 48 | import log_search_control from './common/directives/log-search-control.js'; |
| 49 | import toggle_flag from './common/directives/toggle-flag.js'; |
| 50 | import firmware_list from './common/directives/firmware-list.js'; |
| 51 | import file from './common/directives/file.js'; |
Gunnar Mills | b7ea279 | 2018-07-18 13:01:48 -0500 | [diff] [blame] | 52 | import input from './common/directives/input.js'; |
Ryan Arnell | 84e7a93 | 2018-12-13 10:50:17 -0600 | [diff] [blame] | 53 | import click_outside from './common/directives/click-outside.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 54 | import loader from './common/directives/loader.js'; |
| 55 | import paginate from './common/directives/paginate.js'; |
beccabroek | 75697f9 | 2018-09-04 09:34:44 -0500 | [diff] [blame] | 56 | import serial_console from './common/directives/serial-console.js'; |
beccabroek | bd500cd | 2018-12-03 15:53:09 -0600 | [diff] [blame] | 57 | import dir_paginate from './common/directives/dirPagination.js'; |
beccabroek | a09cc2d | 2019-01-23 14:26:55 -0600 | [diff] [blame] | 58 | import form_input_error from './common/directives/form-input-error.js'; |
Yoshie Muranaka | c86ce3c | 2019-06-05 12:30:30 -0500 | [diff] [blame] | 59 | import icon_provider from './common/directives/icon-provider.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 login_index from './login/index.js'; |
| 62 | import login_controller from './login/controllers/login-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 63 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 64 | import overview_index from './overview/index.js'; |
| 65 | import system_overview_controller from './overview/controllers/system-overview-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 66 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 67 | import server_control_index from './server-control/index.js'; |
| 68 | import bmc_reboot_controller from './server-control/controllers/bmc-reboot-controller.js'; |
| 69 | import power_operations_controller from './server-control/controllers/power-operations-controller.js'; |
Gunnar Mills | 52b8bde | 2018-06-21 13:16:54 -0500 | [diff] [blame] | 70 | import power_usage_controller from './server-control/controllers/power-usage-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 71 | 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] | 72 | import server_led_controller from './server-control/controllers/server-led-controller.js'; |
Ed tanous | e9211cb | 2018-04-22 10:53:28 -0700 | [diff] [blame] | 73 | import kvm_controller from './server-control/controllers/kvm-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 74 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 75 | import server_health_index from './server-health/index.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 76 | import inventory_overview_controller from './server-health/controllers/inventory-overview-controller.js'; |
| 77 | import log_controller from './server-health/controllers/log-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 78 | import sensors_overview_controller from './server-health/controllers/sensors-overview-controller.js'; |
AppaRao Puli | b1289ec | 2018-11-14 20:33:30 +0530 | [diff] [blame] | 79 | import syslog_controller from './server-health/controllers/syslog-controller.js'; |
AppaRao Puli | a2e36e0 | 2018-12-31 17:01:51 +0530 | [diff] [blame] | 80 | import syslog_filter from './common/directives/syslog-filter.js'; |
Yoshie Muranaka | e4194ce | 2019-05-24 14:33:56 -0500 | [diff] [blame] | 81 | import remote_logging_server from './server-health/directives/remote-logging-server.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 82 | |
James Feist | e8634e6 | 2018-09-07 14:25:48 -0700 | [diff] [blame] | 83 | import redfish_index from './redfish/index.js'; |
| 84 | import redfish_controller from './redfish/controllers/redfish-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 85 | import configuration_index from './configuration/index.js'; |
| 86 | import date_time_controller from './configuration/controllers/date-time-controller.js'; |
beccabroek | 309b5da | 2018-11-07 12:22:31 -0600 | [diff] [blame] | 87 | import certificate_controller from './configuration/controllers/certificate-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 88 | import network_controller from './configuration/controllers/network-controller.js'; |
Gunnar Mills | ff64c54 | 2018-08-24 15:49:09 -0500 | [diff] [blame] | 89 | import snmp_controller from './configuration/controllers/snmp-controller.js'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 90 | import firmware_controller from './configuration/controllers/firmware-controller.js'; |
beccabroek | 44da471 | 2019-03-20 13:24:23 -0500 | [diff] [blame] | 91 | import vm_controller from './configuration/controllers/virtual-media-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 92 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 93 | import users_index from './users/index.js'; |
| 94 | import user_accounts_controller from './users/controllers/user-accounts-controller.js'; |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 95 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 96 | window.angular && (function(angular) { |
| 97 | 'use strict'; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 98 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 99 | angular |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 100 | .module( |
| 101 | 'app', |
| 102 | [ |
| 103 | // Dependencies |
beccabroek | a30394b | 2018-12-14 17:19:45 -0600 | [diff] [blame] | 104 | 'ngRoute', 'angular-clipboard', 'ngToast', 'ngAnimate', |
beccabroek | a3b397d | 2019-01-23 14:03:20 -0600 | [diff] [blame] | 105 | 'ngMessages', 'app.common.directives.dirPagination', 'ngSanitize', |
Yoshie Muranaka | e4194ce | 2019-05-24 14:33:56 -0500 | [diff] [blame] | 106 | 'ui.bootstrap', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 107 | // Basic resources |
Gunnar Mills | af0e3b4 | 2018-11-06 16:47:22 -0600 | [diff] [blame] | 108 | 'app.common.services', 'app.common.directives', |
beccabroek | 0d7875b | 2018-09-11 10:39:49 -0500 | [diff] [blame] | 109 | 'app.common.filters', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 110 | // Model resources |
| 111 | 'app.login', 'app.overview', 'app.serverControl', |
Gunnar Mills | 1085098 | 2018-10-22 13:20:05 -0500 | [diff] [blame] | 112 | 'app.serverHealth', 'app.configuration', 'app.users', 'app.redfish' |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 113 | ]) |
| 114 | // Route configuration |
| 115 | .config([ |
| 116 | '$routeProvider', '$locationProvider', |
| 117 | function($routeProvider, $locationProvider) { |
| 118 | $locationProvider.hashPrefix(''); |
Yoshie Muranaka | eaa40dd | 2019-07-17 15:30:00 -0500 | [diff] [blame^] | 119 | $routeProvider.when( |
| 120 | '/unauthorized', {'template': require('./403.html')}) |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 121 | $routeProvider.otherwise({'redirectTo': '/login'}); |
| 122 | } |
| 123 | ]) |
| 124 | .config([ |
| 125 | '$compileProvider', |
| 126 | function($compileProvider) { |
| 127 | $compileProvider.aHrefSanitizationWhitelist( |
| 128 | /^\s*(https?|ftp|mailto|tel|file|data|blob):/); |
| 129 | } |
| 130 | ]) |
| 131 | .config([ |
| 132 | '$httpProvider', |
| 133 | function($httpProvider) { |
| 134 | $httpProvider.interceptors.push('apiInterceptor'); |
Gunnar Mills | dd9d4c3 | 2018-09-10 12:59:34 -0500 | [diff] [blame] | 135 | $httpProvider.defaults.headers.common = { |
| 136 | 'Accept': 'application/json' |
| 137 | }; |
| 138 | $httpProvider.defaults.headers.post = { |
| 139 | 'Content-Type': 'application/json' |
| 140 | }; |
| 141 | $httpProvider.defaults.headers.put = { |
| 142 | 'Content-Type': 'application/json' |
| 143 | }; |
| 144 | $httpProvider.defaults.headers.patch = { |
| 145 | 'Content-Type': 'application/json' |
| 146 | }; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 147 | } |
| 148 | ]) |
beccabroek | a30394b | 2018-12-14 17:19:45 -0600 | [diff] [blame] | 149 | .config([ |
| 150 | 'ngToastProvider', |
| 151 | function(ngToastProvider) { |
| 152 | ngToastProvider.configure({ |
| 153 | animation: 'fade', |
| 154 | timeout: 10000, |
| 155 | dismissButton: true, |
| 156 | maxNumber: 6 |
| 157 | }); |
| 158 | } |
| 159 | ]) |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 160 | .run([ |
| 161 | '$rootScope', '$location', 'dataService', 'userModel', |
| 162 | function($rootScope, $location, dataService, userModel) { |
| 163 | $rootScope.dataService = dataService; |
| 164 | dataService.path = $location.path(); |
| 165 | $rootScope.$on('$routeChangeStart', function(event, next, current) { |
| 166 | if (next.$$route == null || next.$$route == undefined) return; |
| 167 | if (next.$$route.authenticated) { |
| 168 | if (!userModel.isLoggedIn()) { |
| 169 | $location.path('/login'); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 170 | } |
| 171 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 172 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 173 | if (next.$$route.originalPath == '/' || |
| 174 | next.$$route.originalPath == '/login') { |
| 175 | if (userModel.isLoggedIn()) { |
| 176 | if (current && current.$$route) { |
| 177 | $location.path(current.$$route.originalPath); |
| 178 | } else { |
| 179 | $location.path('/overview/server'); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | }); |
| 184 | $rootScope.$on('$locationChangeSuccess', function(event) { |
| 185 | var path = $location.path(); |
| 186 | dataService.path = path; |
| 187 | if (['/', '/login', '/logout'].indexOf(path) == -1 && |
| 188 | path.indexOf('/login') == -1) { |
| 189 | dataService.showNavigation = true; |
| 190 | } else { |
| 191 | dataService.showNavigation = false; |
| 192 | } |
| 193 | }); |
| 194 | |
| 195 | $rootScope.$on('timedout-user', function() { |
| 196 | sessionStorage.removeItem('LOGIN_ID'); |
| 197 | $location.path('/login'); |
| 198 | }); |
| 199 | } |
| 200 | ]); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 201 | })(window.angular); |