-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
179 lines (159 loc) · 6.18 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', [
'ngRoute',
'myApp.version',
'ngLoadScript',
'ui.bootstrap',
'ngCookies',
'imageupload'
]).config(config)
.run(run);
myApp.directive('onErrorSrc', function () {
return {
link: function (scope, element, attrs) {
element.bind('error', function () {
if (attrs.src != attrs.onErrorSrc) {
attrs.$set('src', attrs.onErrorSrc);
}
});
}
}
});
config.$inject = ['$routeProvider', '$locationProvider',
'$sceDelegateProvider', 'subpageDetailsProvider', '$qProvider'];
function config($routeProvider, $locationProvider,
$sceDelegateProvider, subpageDetailsProvider, $qProvider) {
$locationProvider.hashPrefix('');
$sceDelegateProvider.resourceUrlWhitelist(['**']);
$qProvider.errorOnUnhandledRejections(false);
$routeProvider
.when('/', {
controller: 'HomeController',
templateUrl: 'home/home.view.html',
controllerAs: 'vm'
})
.when("/#", {
controller: 'HomeController',
templateUrl: 'home/home.view.html',
controllerAs: 'vm'
})
.when('/login', {
controller: 'LoginController',
templateUrl: 'login/login.view.html',
controllerAs: 'vm'
})
.when('/xy-coords', {
controller: "XyCoordController",
templateUrl: 'utils/xy-finder.view.html',
controllerAs: "vm"
})
.when('/articles', {
controller: "ArticlesController",
templateUrl: 'home/articles.view.html',
controllerAs: "vm"
})
.when('/articles/:name', {
controller: "ArticlesController",
templateUrl: 'home/article_detail.view.html',
controllerAs: "vm"
})
.otherwise({ redirectTo: '/home' });;
//DETAILS
var subpages = Object.keys(subpageDetailsProvider.$get());
for (var i = 0; i < subpages.length; i++) {
$routeProvider.when(subpages[i], {
controller: 'HomeController',
templateUrl: 'home/home.view.html',
controllerAs: 'vm'
})
.when(subpages[i] + '/:name', {
controller: 'DetailsController',
templateUrl: 'home/details.view.html',
controllerAs: 'vm'
});
};
// $locationProvider.html5Mode({
// enabled: true,
// requireBase: false
// });
}
run.$inject = ['$rootScope', '$location', 'googleService', 'userPersistenceService'];
function run($rootScope, $location, googleService, userPersistenceService) {
console.log("*****In RUN******");
console.log("The location path is: " + $location.path());
$rootScope.postLoginRoute = $location.path();
console.log("postLoginRoute just set to (in Run) : " + $rootScope.postLoginRoute);
$rootScope.$on("$routeChangeStart", function (event, next, current) {
console.log("in routeChangeStart");
console.log("The next template is: " + next.templateUrl);
console.log("postLogInRoute in routeChangeStart is: " + $rootScope.postLoginRoute);
//console.log($rootScope.loggedInUser.name);
// if ($rootScope.loggedInUser == null) {
if (userPersistenceService.getUserNameData() == null) {
console.log("no logged in user");
if (next.templateUrl === "login/login.view.html") {
console.log("The location path already is login and the next template matches");
}
else {
console.log("$location.path is not login, so redirecting - it is: " + $location.path());
$location.path('/login');
}
}
else {
//if SRD user, restrict access:
if (userPersistenceService.getSrdUserData() === "true") {
if (next.originalPath.indexOf("srd") == -1 && !(next.originalPath === "/") && !(next.originalPath == "/login")) {
alert("You cannot access this page. Restricted for SRD users");
$location.path('/');
}
}
console.log(userPersistenceService.getUserNameData());
console.log(userPersistenceService.getUserEmailData());
$rootScope.loggedInUser = {};
$rootScope.loggedInUser.email = userPersistenceService.getUserEmailData();
$rootScope.loggedInUser.fullName = userPersistenceService.getUserNameData();
$rootScope.rajUphaar = userPersistenceService.getRajUphaar();
console.log("app.js - location: ", $rootScope.loggedInUser);
}
});
//write all the names of the url - and the pageDetails for each one...
//make a factory of subpage - inject it above and also inject into this function.
//then return the pageDetails of the according section - you have to pass in
// the section
//or rather create a factory for all the details and then do a lookup through the calculator here.
$rootScope.$on('$locationChangeSuccess', function () {
$rootScope.actualLocation = $location.path();
});
$rootScope.$watch(function () { return $location.path() }, function (newLocation, oldLocation) {
if ($rootScope.actualLocation === newLocation) {
//if the old location has several sublayers, then go the last layer
var ol_split = oldLocation.split("/")
if (ol_split.length >= 3) {
var correctLocation = "";
for (var i = 0; i < ol_split.length - 1; i++) {
console.log(ol_split[i]);
correctLocation = correctLocation + ol_split[i] + "/";
}
console.log(correctLocation);
$location.path(correctLocation);
}
}
});
}
// run.$inject = ['$rootScope', '$location', '$cookieStore', '$http'];
// function run($rootScope, $location, $cookieStore, $http) {
// // keep user logged in after page refresh
// $rootScope.globals = $cookieStore.get('globals') || {};
// if ($rootScope.globals.currentUser) {
// $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
// }
// $rootScope.$on('$locationChangeStart', function (event, next, current) {
// // redirect to login page if not logged in and trying to access a restricted page
// var restrictedPage = $.inArray($location.path(), ['/login', '/register']) === -1;
// var loggedIn = $rootScope.globals.currentUser;
// if (restrictedPage && !loggedIn) {
// $location.path('/login');
// }
// });
// }