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