blob: a481d867a64d8bbdccada2bdbf3bae203be31e12 [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',
56 'b2b.att'
57 ])
58 .config(($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider, ngDialogProvider, $controllerProvider, hammerDefaultOptsProvider) => {
59 app.controllerProvider = $controllerProvider;
60 $urlRouterProvider.otherwise('/error404');
61 $locationProvider.html5Mode(true);
62
63 //initialize get if not there
64 if (!$httpProvider.defaults.headers.get) {
65 $httpProvider.defaults.headers.get = {};
66 }
67 var myHostName;
68 myHostName = location.host;
69
70
71 //withCredentials flag on the XHR object - add cookie to XHR requests
72 if (!(myHostName.includes("localhost"))) { // Don't load this for Mock
73 $httpProvider.defaults.withCredentials = true;
74 }
75
76 $httpProvider.defaults.useXDomain = true;
77 $httpProvider.defaults.timeout = 30000;
78
79 //default configuration for ngDialog modal
80 ngDialogProvider.setDefaults({
81 className: 'ngdialog-theme-default',
82 showClose: true,
83 closeByDocument: false,
84 closeByEscape: false
85 });
86
87 //hammer defaults for gestures
88 hammerDefaultOptsProvider.set({
89 recognizers: [[Hammer.Pan, 'enabled']]
90 });
91
92 if (!(myHostName.includes("localhost"))) {
93 $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
94 $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
95 $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
96 }
97
98
99 //interceptor here:
100 var interceptor = function ($q, $injector, $log) {
101 return {
102 'responseError': function (rejection) {
103 $log.error('Interceptor rejection: ' + JSON.stringify(rejection));
104 var $state = $injector.get('$state');
105 switch (rejection.status) {
106 case 401:
107 var globalLoginUrl = rejection.headers()['global-login-url'];
108 if (globalLoginUrl) {
109 window.location = globalLoginUrl +
110 (globalLoginUrl.indexOf('?') === -1 ? '?' : '') +
111 '&retUrl=' + encodeURI(window.location);
112 return;
113 }
114 break;
115 default:
116 //handle internal server error
117 }
118 return $q.reject(rejection);
119 }
120 };
121 };
122 $httpProvider.interceptors.push(interceptor);
123
124 }).run(($http, CacheFactory) => {
125 //default configuration for cache factory
126 $http.defaults.cache = CacheFactory('defaultCache', {
127 maxAge: 15 * 60 * 1000, // Items added to this cache expire after 15 minutes
128 cacheFlushInterval: 60 * 60 * 1000, // This cache will clear itself every hour
129 deleteOnExpire: 'aggressive' // Items will be deleted from this cache when they expire
130 });
131 });
132
133
134angular.module( 'ecompApp' ).config( [
135'$compileProvider',
136function( $compileProvider )
137{
138 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
139}
140]);