st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 1 | /*- |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 2 | * ============LICENSE_START========================================== |
| 3 | * ONAP Portal |
| 4 | * =================================================================== |
| 5 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 6 | * =================================================================== |
| 7 | * |
| 8 | * Unless otherwise specified, all software contained herein is licensed |
| 9 | * under the Apache License, Version 2.0 (the "License"); |
| 10 | * you may not use this software except in compliance with the License. |
st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 11 | * You may obtain a copy of the License at |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 20 | * |
| 21 | * Unless otherwise specified, all documentation contained herein is licensed |
| 22 | * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); |
| 23 | * you may not use this documentation except in compliance with the License. |
| 24 | * You may obtain a copy of the License at |
| 25 | * |
| 26 | * https://creativecommons.org/licenses/by/4.0/ |
| 27 | * |
| 28 | * Unless required by applicable law or agreed to in writing, documentation |
| 29 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 31 | * See the License for the specific language governing permissions and |
| 32 | * limitations under the License. |
| 33 | * |
| 34 | * ============LICENSE_END============================================ |
| 35 | * |
Hima Elisetty | 24608a9 | 2018-04-19 14:15:29 -0400 | [diff] [blame] | 36 | * |
st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 37 | */ |
| 38 | 'use strict'; |
| 39 | |
| 40 | var app = angular.module('ecompApp', [ |
| 41 | 'ngCookies', |
| 42 | 'ngResource', |
| 43 | 'ngSanitize', |
| 44 | 'ui.router', |
| 45 | 'ecomp.conf', |
| 46 | 'ngMessages', |
| 47 | 'ui.select', |
| 48 | 'angular-cache', |
| 49 | 'ngDialog', |
| 50 | 'gridster', |
| 51 | 'angular-gestures', |
| 52 | 'uuid', |
| 53 | 'ui.bootstrap', |
| 54 | 'ngMaterial', |
| 55 | 'oc.lazyLoad', |
shentao999 | 75d35b5 | 2019-04-02 09:29:10 +0800 | [diff] [blame] | 56 | 'b2b.att', |
| 57 | 'pascalprecht.translate' |
st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 58 | ]) |
shentao999 | 75d35b5 | 2019-04-02 09:29:10 +0800 | [diff] [blame] | 59 | .config(($stateProvider, $translateProvider, $urlRouterProvider, $locationProvider, $httpProvider, ngDialogProvider, $controllerProvider, hammerDefaultOptsProvider) => { |
st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 60 | app.controllerProvider = $controllerProvider; |
| 61 | $urlRouterProvider.otherwise('/error404'); |
| 62 | $locationProvider.html5Mode(true); |
shentao999 | 75d35b5 | 2019-04-02 09:29:10 +0800 | [diff] [blame] | 63 | var lang = window.localStorage.lang||'EN'; |
| 64 | $translateProvider.preferredLanguage(lang); |
| 65 | $translateProvider.useStaticFilesLoader({ |
| 66 | prefix: '././assets/i18n/', |
| 67 | suffix: '.json' |
| 68 | }) |
st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 69 | //initialize get if not there |
| 70 | if (!$httpProvider.defaults.headers.get) { |
| 71 | $httpProvider.defaults.headers.get = {}; |
| 72 | } |
| 73 | var myHostName; |
| 74 | myHostName = location.host; |
| 75 | |
| 76 | |
| 77 | //withCredentials flag on the XHR object - add cookie to XHR requests |
| 78 | if (!(myHostName.includes("localhost"))) { // Don't load this for Mock |
| 79 | $httpProvider.defaults.withCredentials = true; |
| 80 | } |
| 81 | |
| 82 | $httpProvider.defaults.useXDomain = true; |
| 83 | $httpProvider.defaults.timeout = 30000; |
| 84 | |
| 85 | //default configuration for ngDialog modal |
| 86 | ngDialogProvider.setDefaults({ |
| 87 | className: 'ngdialog-theme-default', |
| 88 | showClose: true, |
| 89 | closeByDocument: false, |
| 90 | closeByEscape: false |
| 91 | }); |
| 92 | |
| 93 | //hammer defaults for gestures |
| 94 | hammerDefaultOptsProvider.set({ |
| 95 | recognizers: [[Hammer.Pan, 'enabled']] |
| 96 | }); |
| 97 | |
| 98 | if (!(myHostName.includes("localhost"))) { |
| 99 | $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; |
| 100 | $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; |
| 101 | $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | //interceptor here: |
| 106 | var interceptor = function ($q, $injector, $log) { |
| 107 | return { |
| 108 | 'responseError': function (rejection) { |
| 109 | $log.error('Interceptor rejection: ' + JSON.stringify(rejection)); |
| 110 | var $state = $injector.get('$state'); |
hb123f | a70761c | 2019-03-20 12:20:44 -0400 | [diff] [blame] | 111 | var $sanitize = $injector.get('$sanitize'); |
st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 112 | switch (rejection.status) { |
| 113 | case 401: |
| 114 | var globalLoginUrl = rejection.headers()['global-login-url']; |
| 115 | if (globalLoginUrl) { |
hb123f | a70761c | 2019-03-20 12:20:44 -0400 | [diff] [blame] | 116 | window.location = $sanitize(globalLoginUrl + |
st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 117 | (globalLoginUrl.indexOf('?') === -1 ? '?' : '') + |
hb123f | a70761c | 2019-03-20 12:20:44 -0400 | [diff] [blame] | 118 | '&retUrl=' + encodeURI(window.location)); |
st782s | b54df0d | 2017-05-04 07:48:42 -0400 | [diff] [blame] | 119 | return; |
| 120 | } |
| 121 | break; |
| 122 | default: |
| 123 | //handle internal server error |
| 124 | } |
| 125 | return $q.reject(rejection); |
| 126 | } |
| 127 | }; |
| 128 | }; |
| 129 | $httpProvider.interceptors.push(interceptor); |
| 130 | |
| 131 | }).run(($http, CacheFactory) => { |
| 132 | //default configuration for cache factory |
| 133 | $http.defaults.cache = CacheFactory('defaultCache', { |
| 134 | maxAge: 15 * 60 * 1000, // Items added to this cache expire after 15 minutes |
| 135 | cacheFlushInterval: 60 * 60 * 1000, // This cache will clear itself every hour |
| 136 | deleteOnExpire: 'aggressive' // Items will be deleted from this cache when they expire |
| 137 | }); |
| 138 | }); |
| 139 | |
| 140 | |
| 141 | angular.module( 'ecompApp' ).config( [ |
| 142 | '$compileProvider', |
| 143 | function( $compileProvider ) |
| 144 | { |
| 145 | $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/); |
| 146 | } |
| 147 | ]); |