blob: 890c67a74a5126648354a4e035cef94959fc3a6e [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001/**
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
12window.angular && (function (angular) {
13 'use strict';
14
15 angular
16 .module('app', [
17 // Dependencies
18 'ngRoute',
Iftekharul Islamcd789502017-04-19 14:37:55 -050019 'angular-clipboard',
20 'angularUtils.directives.dirPagination',
Iftekharul Islam99d199f2017-03-24 15:28:25 -050021 // 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 Islamcd789502017-04-19 14:37:55 -050030 'app.overview',
31 'app.serverControl',
32 'app.serverHealth',
33 'app.configuration',
Iftekharul Islamcd789502017-04-19 14:37:55 -050034 'app.users'
Iftekharul Islam99d199f2017-03-24 15:28:25 -050035 ])
36 // Route configuration
37 .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
38 $locationProvider.hashPrefix('');
39 $routeProvider
40 .otherwise({
41 'redirectTo': '/login'
42 });
43 }])
Iftekharul Islamcd789502017-04-19 14:37:55 -050044 .config(['$compileProvider', function ($compileProvider) {
45 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|data|blob):/);
46 }])
Iftekharul Islam99d199f2017-03-24 15:28:25 -050047 .config(['$httpProvider', function($httpProvider){
Iftekharul Islam8947e702017-07-27 10:28:07 -050048 $httpProvider.defaults.timeout = 20000;
Iftekharul Islam99d199f2017-03-24 15:28:25 -050049 $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 Davis9dd479d2017-08-18 16:35:00 -050070 $location.path('/overview/server');
Iftekharul Islam99d199f2017-03-24 15:28:25 -050071 }
72 }
73 }
74 });
75 $rootScope.$on('$locationChangeSuccess', function(event){
76 var path = $location.path();
77 dataService.path = path;
Iftekharul Islambb5058e2017-03-29 13:54:26 -050078 if(['/','/login','/logout'].indexOf(path) == -1 &&
79 path.indexOf('/login') == -1){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050080 dataService.showNavigation = true;
81 }else{
82 dataService.showNavigation = false;
83 }
84 });
85
86 $rootScope.$on('timedout-user', function(){
Iftekharul Islambb5058e2017-03-29 13:54:26 -050087 if(sessionStorage.getItem('LOGIN_ID') == 'FAKE_ID'){
88 return;
89 }
90
Iftekharul Islam99d199f2017-03-24 15:28:25 -050091 sessionStorage.removeItem('LOGIN_ID');
92 $location.path('/login');
93 });
94 }
95 ]);
96
97})(window.angular);