nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / 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         'att.abs',
33         'att.gridster',
34         'uuid',
35         'ui.bootstrap',
36         'ngMaterial'
37     ])
38     .config(($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider, ngDialogProvider) => {
39         $urlRouterProvider.otherwise('/error404');
40         $locationProvider.html5Mode(true);
41
42         //initialize get if not there
43         if (!$httpProvider.defaults.headers.get) {
44              $httpProvider.defaults.headers.get = {};
45         }
46
47         //withCredentials flag on the XHR object - add cookie to XHR requests
48         $httpProvider.defaults.withCredentials = true;
49         $httpProvider.defaults.useXDoain = true;
50         $httpProvider.defaults.timeout = 30000;
51
52         //default configuration for ngDialog modal
53         ngDialogProvider.setDefaults({
54             className: 'ngdialog-theme-default',
55             showClose: true,
56             closeByDocument: false,
57             closeByEscape: false
58         });
59
60
61         var myHostName;
62         myHostName = location.host;
63
64         if (!(myHostName.includes("localhost"))) {
65             $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
66             $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
67             $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
68         }
69
70
71         //interceptor here:
72         var interceptor = function ($q, $injector, $log) {
73             return {
74                 'responseError': function (rejection) {
75                     $log.error('Interceptor rejection: ' + JSON.stringify(rejection));
76                     var $state = $injector.get('$state');
77                     switch (rejection.status) {
78                         case 401:
79                             var globalLoginUrl = rejection.headers()['global-login-url'];
80                             if (globalLoginUrl) {
81                                 window.location = globalLoginUrl +
82                                     (globalLoginUrl.indexOf('?') === -1 ? '?' : '') +
83                                     '&retUrl=' + encodeURI(window.location);
84                                 return;
85                             }
86                             break;
87                         case 403:
88                             // $state.go('root.applicationsHome');
89                             //handle forbidden error
90                             break;
91                         // case 404:
92                         //     $state.go('/login.htm');
93                         //     //handle forbidden error
94                         //     break;
95                         default:
96                         //handle internal server error
97                     }
98                     return $q.reject(rejection);
99                 }
100             };
101         };
102         $httpProvider.interceptors.push(interceptor);
103
104     }).run(($http, CacheFactory) => {
105         //default configuration for cache factory
106         $http.defaults.cache = CacheFactory('defaultCache', {
107             maxAge: 15 * 60 * 1000, // Items added to this cache expire after 15 minutes
108             cacheFlushInterval: 60 * 60 * 1000, // This cache will clear itself every hour
109             deleteOnExpire: 'aggressive' // Items will be deleted from this cache when they expire
110         });
111     });
112
113
114 angular.module( 'ecompApp' ).config( [
115 '$compileProvider',
116 function( $compileProvider )
117 {
118         $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
119 }
120 ]);