blob: c60dfe9a01d89fe3e23dcad88e35b674a4aef093 [file] [log] [blame]
st782sb54df0d2017-05-04 07:48:42 -04001/*-
st782s21a87612018-01-30 17:29:36 -05002 * ============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.
st782sb54df0d2017-05-04 07:48:42 -040011 * You may obtain a copy of the License at
st782s21a87612018-01-30 17:29:36 -050012 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
st782sb54df0d2017-05-04 07:48:42 -040015 * 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.
st782s21a87612018-01-30 17:29:36 -050020 *
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 Elisetty24608a92018-04-19 14:15:29 -040036 *
st782sb54df0d2017-05-04 07:48:42 -040037 */
38'use strict';
39
40var 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',
shentao99975d35b52019-04-02 09:29:10 +080056 'b2b.att',
57 'pascalprecht.translate'
st782sb54df0d2017-05-04 07:48:42 -040058 ])
shentao99975d35b52019-04-02 09:29:10 +080059 .config(($stateProvider, $translateProvider, $urlRouterProvider, $locationProvider, $httpProvider, ngDialogProvider, $controllerProvider, hammerDefaultOptsProvider) => {
st782sb54df0d2017-05-04 07:48:42 -040060 app.controllerProvider = $controllerProvider;
61 $urlRouterProvider.otherwise('/error404');
62 $locationProvider.html5Mode(true);
shentao99975d35b52019-04-02 09:29:10 +080063 var lang = window.localStorage.lang||'EN';
64 $translateProvider.preferredLanguage(lang);
65 $translateProvider.useStaticFilesLoader({
66 prefix: '././assets/i18n/',
67 suffix: '.json'
68 })
st782sb54df0d2017-05-04 07:48:42 -040069 //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');
hb123fa70761c2019-03-20 12:20:44 -0400111 var $sanitize = $injector.get('$sanitize');
st782sb54df0d2017-05-04 07:48:42 -0400112 switch (rejection.status) {
113 case 401:
114 var globalLoginUrl = rejection.headers()['global-login-url'];
115 if (globalLoginUrl) {
hb123fa70761c2019-03-20 12:20:44 -0400116 window.location = $sanitize(globalLoginUrl +
st782sb54df0d2017-05-04 07:48:42 -0400117 (globalLoginUrl.indexOf('?') === -1 ? '?' : '') +
hb123fa70761c2019-03-20 12:20:44 -0400118 '&retUrl=' + encodeURI(window.location));
st782sb54df0d2017-05-04 07:48:42 -0400119 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
141angular.module( 'ecompApp' ).config( [
142'$compileProvider',
143function( $compileProvider )
144{
145 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
146}
147]);