blob: 11c3576bf0a5c55d55eebf1144ff5148a36f9cbd [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',
34 'app.firmware',
35 'app.users'
Iftekharul Islam99d199f2017-03-24 15:28:25 -050036 ])
37 // Route configuration
38 .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
39 $locationProvider.hashPrefix('');
40 $routeProvider
41 .otherwise({
42 'redirectTo': '/login'
43 });
44 }])
Iftekharul Islamcd789502017-04-19 14:37:55 -050045 .config(['$compileProvider', function ($compileProvider) {
46 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|data|blob):/);
47 }])
Iftekharul Islam99d199f2017-03-24 15:28:25 -050048 .config(['$httpProvider', function($httpProvider){
Iftekharul Islamf3f7a5f2017-03-27 13:53:24 -050049 $httpProvider.defaults.timeout = 10000;
Iftekharul Islam99d199f2017-03-24 15:28:25 -050050 $httpProvider.interceptors.push('apiInterceptor');
51 }])
52 .run(['$rootScope', '$location', 'dataService', 'userModel',
53 function($rootScope, $location, dataService, userModel){
54 $rootScope.dataService = dataService;
55 dataService.path = $location.path();
56 $rootScope.$on('$routeChangeStart', function(event, next, current){
57
58 if(next.$$route == null || next.$$route == undefined) return;
59 if(next.$$route.authenticated){
60 if(!userModel.isLoggedIn()){
61 $location.path('/login');
62 }
63 }
64
65 if(next.$$route.originalPath == '/' ||
66 next.$$route.originalPath == '/login'){
67 if(userModel.isLoggedIn()){
68 if(current && current.$$route){
69 $location.path(current.$$route.originalPath);
70 }else{
71 $location.path('/overview/system');
72 }
73 }
74 }
75 });
76 $rootScope.$on('$locationChangeSuccess', function(event){
77 var path = $location.path();
78 dataService.path = path;
Iftekharul Islambb5058e2017-03-29 13:54:26 -050079 if(['/','/login','/logout'].indexOf(path) == -1 &&
80 path.indexOf('/login') == -1){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050081 dataService.showNavigation = true;
82 }else{
83 dataService.showNavigation = false;
84 }
85 });
86
87 $rootScope.$on('timedout-user', function(){
Iftekharul Islambb5058e2017-03-29 13:54:26 -050088 if(sessionStorage.getItem('LOGIN_ID') == 'FAKE_ID'){
89 return;
90 }
91
Iftekharul Islam99d199f2017-03-24 15:28:25 -050092 sessionStorage.removeItem('LOGIN_ID');
93 $location.path('/login');
94 });
95 }
96 ]);
97
98})(window.angular);