blob: f799e29c413e3316ca834c04656b50d5ffa2887c [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',
19 // Basic resources
20 'app.constants',
21 'app.templates',
22 'app.vendors',
23 'app.common.services',
24 'app.common.directives',
25 'app.common.filters',
26 // Model resources
27 'app.login',
28 'app.overview'
29 ])
30 // Route configuration
31 .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
32 $locationProvider.hashPrefix('');
33 $routeProvider
34 .otherwise({
35 'redirectTo': '/login'
36 });
37 }])
38 .config(['$httpProvider', function($httpProvider){
Iftekharul Islamf3f7a5f2017-03-27 13:53:24 -050039 $httpProvider.defaults.timeout = 10000;
Iftekharul Islam99d199f2017-03-24 15:28:25 -050040 $httpProvider.interceptors.push('apiInterceptor');
41 }])
42 .run(['$rootScope', '$location', 'dataService', 'userModel',
43 function($rootScope, $location, dataService, userModel){
44 $rootScope.dataService = dataService;
45 dataService.path = $location.path();
46 $rootScope.$on('$routeChangeStart', function(event, next, current){
47
48 if(next.$$route == null || next.$$route == undefined) return;
49 if(next.$$route.authenticated){
50 if(!userModel.isLoggedIn()){
51 $location.path('/login');
52 }
53 }
54
55 if(next.$$route.originalPath == '/' ||
56 next.$$route.originalPath == '/login'){
57 if(userModel.isLoggedIn()){
58 if(current && current.$$route){
59 $location.path(current.$$route.originalPath);
60 }else{
61 $location.path('/overview/system');
62 }
63 }
64 }
65 });
66 $rootScope.$on('$locationChangeSuccess', function(event){
67 var path = $location.path();
68 dataService.path = path;
Iftekharul Islambb5058e2017-03-29 13:54:26 -050069 if(['/','/login','/logout'].indexOf(path) == -1 &&
70 path.indexOf('/login') == -1){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050071 dataService.showNavigation = true;
72 }else{
73 dataService.showNavigation = false;
74 }
75 });
76
77 $rootScope.$on('timedout-user', function(){
Iftekharul Islambb5058e2017-03-29 13:54:26 -050078 if(sessionStorage.getItem('LOGIN_ID') == 'FAKE_ID'){
79 return;
80 }
81
Iftekharul Islam99d199f2017-03-24 15:28:25 -050082 sessionStorage.removeItem('LOGIN_ID');
83 $location.path('/login');
84 });
85 }
86 ]);
87
88})(window.angular);