blob: f5c26920fd12b04893a8557efc0e73de2dd9187c [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){
39 //console.log($httpProvider.interceptors);
40 $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;
69 if(['/','/login','/logout'].indexOf(path) == -1){
70 dataService.showNavigation = true;
71 }else{
72 dataService.showNavigation = false;
73 }
74 });
75
76 $rootScope.$on('timedout-user', function(){
77 sessionStorage.removeItem('LOGIN_ID');
78 $location.path('/login');
79 });
80 }
81 ]);
82
83})(window.angular);