Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1 | /** |
| 2 | * A module which contains the definition of the application and the base of configuration |
| 3 | * |
| 4 | * @module app/index/services/index |
| 5 | * @exports app/index |
| 6 | * |
| 7 | * @author Developer Developer |
| 8 | * @version 0.10.0 |
| 9 | * @since 0.0.1 |
| 10 | */ |
| 11 | |
| 12 | window.angular && (function (angular) { |
| 13 | 'use strict'; |
| 14 | |
| 15 | angular |
| 16 | .module('app', [ |
| 17 | // Dependencies |
| 18 | 'ngRoute', |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 19 | 'angular-clipboard', |
| 20 | 'angularUtils.directives.dirPagination', |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 21 | // Basic resources |
| 22 | 'app.constants', |
| 23 | 'app.templates', |
| 24 | 'app.vendors', |
| 25 | 'app.common.services', |
| 26 | 'app.common.directives', |
| 27 | 'app.common.filters', |
| 28 | // Model resources |
| 29 | 'app.login', |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 30 | 'app.overview', |
| 31 | 'app.serverControl', |
| 32 | 'app.serverHealth', |
| 33 | 'app.configuration', |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 34 | 'app.users' |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 35 | ]) |
| 36 | // Route configuration |
| 37 | .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { |
| 38 | $locationProvider.hashPrefix(''); |
| 39 | $routeProvider |
| 40 | .otherwise({ |
| 41 | 'redirectTo': '/login' |
| 42 | }); |
| 43 | }]) |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 44 | .config(['$compileProvider', function ($compileProvider) { |
| 45 | $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|data|blob):/); |
| 46 | }]) |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 47 | .config(['$httpProvider', function($httpProvider){ |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 48 | $httpProvider.defaults.timeout = 20000; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 49 | $httpProvider.interceptors.push('apiInterceptor'); |
| 50 | }]) |
| 51 | .run(['$rootScope', '$location', 'dataService', 'userModel', |
| 52 | function($rootScope, $location, dataService, userModel){ |
| 53 | $rootScope.dataService = dataService; |
| 54 | dataService.path = $location.path(); |
| 55 | $rootScope.$on('$routeChangeStart', function(event, next, current){ |
| 56 | |
| 57 | if(next.$$route == null || next.$$route == undefined) return; |
| 58 | if(next.$$route.authenticated){ |
| 59 | if(!userModel.isLoggedIn()){ |
| 60 | $location.path('/login'); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if(next.$$route.originalPath == '/' || |
| 65 | next.$$route.originalPath == '/login'){ |
| 66 | if(userModel.isLoggedIn()){ |
| 67 | if(current && current.$$route){ |
| 68 | $location.path(current.$$route.originalPath); |
| 69 | }else{ |
Michael Davis | 9dd479d | 2017-08-18 16:35:00 -0500 | [diff] [blame^] | 70 | $location.path('/overview/server'); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | } |
| 74 | }); |
| 75 | $rootScope.$on('$locationChangeSuccess', function(event){ |
| 76 | var path = $location.path(); |
| 77 | dataService.path = path; |
Iftekharul Islam | bb5058e | 2017-03-29 13:54:26 -0500 | [diff] [blame] | 78 | if(['/','/login','/logout'].indexOf(path) == -1 && |
| 79 | path.indexOf('/login') == -1){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 80 | dataService.showNavigation = true; |
| 81 | }else{ |
| 82 | dataService.showNavigation = false; |
| 83 | } |
| 84 | }); |
| 85 | |
| 86 | $rootScope.$on('timedout-user', function(){ |
Iftekharul Islam | bb5058e | 2017-03-29 13:54:26 -0500 | [diff] [blame] | 87 | if(sessionStorage.getItem('LOGIN_ID') == 'FAKE_ID'){ |
| 88 | return; |
| 89 | } |
| 90 | |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 91 | sessionStorage.removeItem('LOGIN_ID'); |
| 92 | $location.path('/login'); |
| 93 | }); |
| 94 | } |
| 95 | ]); |
| 96 | |
| 97 | })(window.angular); |