Revize d68f7bbd
Přidáno uživatelem Jan Kohlíček před téměř 7 roky(ů)
frontend/app.js | ||
---|---|---|
4 | 4 |
APP_NAME: 'PVPK', |
5 | 5 |
APP_VERSION: 1.0, |
6 | 6 |
API_URL: API_URL, |
7 |
API_TOKEN: API_TOKEN |
|
7 |
API_TOKEN: API_TOKEN, |
|
8 |
DEFAULT_POSITION: {LAT: 49.53, LNG: 13.3}, |
|
9 |
DEFAULT_ZOOM: 10 |
|
8 | 10 |
}); |
9 | 11 |
|
10 |
|
|
12 |
//PRIPRAVA PRO REFAKTORING |
|
11 | 13 |
// app.config(function($stateProvider, $locationProvider) { |
12 | 14 |
// // $stateProvider |
13 | 15 |
// // .state('report',{ |
... | ... | |
29 | 31 |
// $locationProvider.html5Mode(true); |
30 | 32 |
// }); |
31 | 33 |
|
32 |
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { |
|
33 |
|
|
34 |
}]); |
|
35 |
|
|
36 | 34 |
|
37 | 35 |
app.controller('mainController', function ($rootScope, $scope, $http, $window) { |
38 | 36 |
|
... | ... | |
73 | 71 |
var toTime = new Date(); |
74 | 72 |
toTime.setHours(16, 0, 0, 0); |
75 | 73 |
|
76 |
var toDate = new Date(); |
|
74 |
|
|
75 |
var toDate = new Date(new Date().getTime() - (1 * 24 * 60 * 60 * 1000)); |
|
76 |
|
|
77 |
//DODELAT OMEZENI |
|
78 |
$scope.maxDate = toDate; |
|
77 | 79 |
var fromDate = new Date(toDate.getTime() - (30 * 24 * 60 * 60 * 1000)); |
78 | 80 |
|
79 | 81 |
var params = $location.search(); |
... | ... | |
88 | 90 |
}; |
89 | 91 |
|
90 | 92 |
$scope.locations = []; |
91 |
$scope.showLocationsLoading = false;
|
|
93 |
$scope.showSearchLoading = false;
|
|
92 | 94 |
|
93 |
if (params.location!=null && params.location.length > 2) {
|
|
95 |
if (params.location != null && params.location.length > 2) {
|
|
94 | 96 |
$scope.searchLocations(false); |
95 | 97 |
} |
96 | 98 |
}; |
97 | 99 |
|
98 | 100 |
|
99 | 101 |
$scope.searchLocations = function (saveToUrl) { |
100 |
$scope.showLocationsLoading = true; |
|
102 |
if (!$scope.search.location || $scope.search.location.length <= 1) { |
|
103 |
$scope.locations = []; |
|
104 |
return; |
|
105 |
} |
|
106 |
|
|
107 |
$scope.showSearchLoading = true; |
|
101 | 108 |
|
102 | 109 |
if (saveToUrl) |
103 | 110 |
$location.search({ |
104 | 111 |
location: $scope.search.location, |
105 |
fromDate: $scope.search.fromDate.getTime(), |
|
106 |
toDate: $scope.search.toDate.getTime(), |
|
107 |
fromTime: $scope.search.fromTime.getTime(), |
|
108 |
toTime: $scope.search.toTime.getTime(), |
|
112 |
// fromDate: $scope.search.fromDate.getTime(),
|
|
113 |
// toDate: $scope.search.toDate.getTime(),
|
|
114 |
// fromTime: $scope.search.fromTime.getTime(),
|
|
115 |
// toTime: $scope.search.toTime.getTime(),
|
|
109 | 116 |
direction: $scope.search.direction ? 1 : 0 |
110 | 117 |
}); |
111 | 118 |
|
112 |
Device({jwt: config.API_TOKEN}).query({
|
|
119 |
Device.query({ |
|
113 | 120 |
address: $scope.search.location, |
114 | 121 |
showDirection: $scope.search.direction ? 1 : 0 |
115 | 122 |
}, function (data) { |
116 | 123 |
$scope.locations = data; |
117 |
$scope.showLocationsLoading = false;
|
|
124 |
$scope.showSearchLoading = false;
|
|
118 | 125 |
|
119 | 126 |
var params = $location.search(); |
120 |
if(!saveToUrl && jQuery.grep($scope.locations, function(e){ return e.id === params.deviceId; }).length>0){ |
|
127 |
if (!saveToUrl && jQuery.grep($scope.locations, function (e) { |
|
128 |
return e.id === params.deviceId; |
|
129 |
}).length > 0) { |
|
121 | 130 |
$scope.selectDevice(params.deviceId); |
122 | 131 |
} |
123 | 132 |
|
124 | 133 |
}, function (response) { |
125 |
$scope.showLocationsLoading = false;
|
|
134 |
$scope.showSearchLoading = false;
|
|
126 | 135 |
console.log('Error api all Devices'); |
127 | 136 |
$rootScope.handleErrorResponse(response); |
128 | 137 |
}); |
129 | 138 |
}; |
130 | 139 |
|
131 | 140 |
$scope.selectDevice = function (id) { |
132 |
$scope.deviceId = id; |
|
133 |
|
|
134 | 141 |
var searchObject = $location.search(); |
135 | 142 |
searchObject.deviceId = id; |
136 | 143 |
$location.search(searchObject); |
137 | 144 |
|
138 |
Device({jwt: config.API_TOKEN}).get({ |
|
139 |
id: id |
|
145 |
$rootScope.$emit('activeMarker', {id: id}); |
|
146 |
$rootScope.$emit('infoLocation', {id: id}); |
|
147 |
}; |
|
148 |
|
|
149 |
}); |
|
150 |
|
|
151 |
|
|
152 |
app.controller('infoController', function ($rootScope, $scope, config, Device, Vehicle) { |
|
153 |
|
|
154 |
this.$onInit = function () { |
|
155 |
$rootScope.selectDevice = null; |
|
156 |
$scope.vehicles = []; |
|
157 |
$scope.showInfoLoading = false; |
|
158 |
|
|
159 |
Vehicle.query(null, function (data) { |
|
160 |
$scope.vehicles = data; |
|
161 |
}, function (response) { |
|
162 |
$rootScope.graphShow = false; |
|
163 |
console.log('Error api all Vehicles'); |
|
164 |
$rootScope.handleErrorResponse(response); |
|
165 |
}); |
|
166 |
}; |
|
167 |
|
|
168 |
$rootScope.$on('infoLocation', function (event, args) { |
|
169 |
$scope.showInfoLoading = true; |
|
170 |
|
|
171 |
Device.get({ |
|
172 |
id: args.id |
|
140 | 173 |
// dateFrom: $scope.search.fromDate.getTime(), |
141 | 174 |
// dateTo: $scope.search.toDate.getTime(), |
142 | 175 |
// timeFrom: $scope.search.fromTime.getTime(), |
143 | 176 |
// timeTo: $scope.search.toTime.getTime(), |
144 | 177 |
// direction: $scope.search.direction ? 1 : 0 |
145 | 178 |
}, function (data) { |
146 |
$rootScope.$emit('renderGraph', data); |
|
179 |
$rootScope.selectDevice = data; |
|
180 |
$scope.showInfoLoading = false; |
|
147 | 181 |
}, function (response) { |
182 |
$rootScope.selectDevice = null; |
|
183 |
$scope.showInfoLoading = false; |
|
148 | 184 |
console.log('Error api get Devices'); |
149 | 185 |
$rootScope.handleErrorResponse(response); |
150 | 186 |
}); |
151 |
}; |
|
152 | 187 |
|
188 |
}); |
|
189 |
|
|
190 |
$scope.infoClose = function () { |
|
191 |
$rootScope.selectDevice = null; |
|
192 |
|
|
193 |
$rootScope.$emit('setDefaultMap', null); |
|
194 |
}; |
|
153 | 195 |
}); |
154 | 196 |
|
155 | 197 |
|
156 |
app.controller('graphController', function ($rootScope, $scope, config, Vehicle) {
|
|
198 |
app.controller('mapController', function ($rootScope, $scope, config, Device) {
|
|
157 | 199 |
|
158 | 200 |
this.$onInit = function () { |
159 |
$rootScope.graphShow = false; |
|
160 |
$scope.vehicles = []; |
|
161 |
}; |
|
162 | 201 |
|
163 |
$rootScope.$on("renderGraph", function (event, args) { |
|
164 |
$rootScope.graphShow = true; |
|
165 |
|
|
166 |
Vehicle({jwt: config.API_TOKEN}).query(null, function (data) { |
|
167 |
$scope.vehicles = data; |
|
202 |
$scope.map = new GMaps({ |
|
203 |
div: '#map', |
|
204 |
zoomControl: true, |
|
205 |
mapTypeControl: false, |
|
206 |
scaleControl: false, |
|
207 |
streetViewControl: false, |
|
208 |
rotateControl: false, |
|
209 |
fullscreenControl: false, |
|
210 |
mapTypeId: 'roadmap', |
|
211 |
zoom: config.DEFAULT_ZOOM, |
|
212 |
lat: config.DEFAULT_POSITION.LAT, |
|
213 |
lng: config.DEFAULT_POSITION.LNG |
|
214 |
}); |
|
168 | 215 |
|
216 |
Device.query({showDirection: 0}, function (data) { |
|
217 |
$scope.createMarkerNext(data, 0); |
|
169 | 218 |
}, function (response) { |
170 |
$rootScope.graphShow = false; |
|
171 |
console.log('Error api all Vehicles'); |
|
219 |
console.log('Error api all Devices'); |
|
172 | 220 |
$rootScope.handleErrorResponse(response); |
173 | 221 |
}); |
174 |
});
|
|
222 |
}; |
|
175 | 223 |
|
176 |
}); |
|
224 |
$scope.createMarkerNext = function (data, i) { |
|
225 |
var lctn = data[i]; |
|
226 |
|
|
227 |
GMaps.geocode({ |
|
228 |
address: lctn.street + ', ' + lctn.town + ', Plzeňský kraj', |
|
229 |
callback: function (results, status) { |
|
230 |
if (status === 'OK') { |
|
231 |
latlng = results[0].geometry.location; |
|
232 |
|
|
233 |
var marker = $scope.map.addMarker({ |
|
234 |
lat: latlng.lat(), |
|
235 |
lng: latlng.lng(), |
|
236 |
title: lctn.name, |
|
237 |
label: 'U', |
|
238 |
click: function (e) { |
|
239 |
$rootScope.$emit('infoLocation', {id: lctn.id}); |
|
240 |
//alert("asdfas"); |
|
241 |
}, |
|
242 |
infoWindow: { |
|
243 |
content: '<h6 class="mb-1">' + lctn.name + '</h6>' |
|
244 |
+ '<address>' + lctn.street + ', ' + lctn.town + '</address>' |
|
245 |
}, |
|
246 |
id: lctn.id |
|
247 |
}); |
|
248 |
|
|
249 |
} else if (status === 'ZERO_RESULTS') { |
|
250 |
console.log('No results found address'); |
|
251 |
} |
|
252 |
|
|
253 |
i++; |
|
254 |
if (i < data.length) { |
|
255 |
setTimeout(function () { |
|
256 |
$scope.createMarkerNext(data, i); |
|
257 |
}, 900); |
|
258 |
} |
|
259 |
} |
|
260 |
}); |
|
177 | 261 |
|
178 |
app.controller('mapController', function ($scope) {
|
|
262 |
};
|
|
179 | 263 |
|
180 |
this.$onInit = function () { |
|
264 |
$rootScope.$on('activeMarker', function (event, args) { |
|
265 |
var id = args.id; |
|
266 |
for (var i = 0, marker; marker = $scope.map.markers[i]; i++) { |
|
267 |
if (marker.id && marker.id === id && marker.infoWindow) { |
|
268 |
$scope.map.setCenter(marker.position.lat(), marker.position.lng()); |
|
269 |
$scope.map.setZoom(12); |
|
270 |
marker.infoWindow.open($scope.map, marker); |
|
271 |
return; |
|
272 |
} |
|
273 |
} |
|
274 |
}); |
|
181 | 275 |
|
182 |
}; |
|
276 |
$rootScope.$on('setDefaultMap', function (event, args) { |
|
277 |
$scope.map.setCenter(config.DEFAULT_POSITION.LAT, config.DEFAULT_POSITION.LNG); |
|
278 |
$scope.map.setZoom(config.DEFAULT_ZOOM); |
|
279 |
$scope.map.hideInfoWindows(); |
|
280 |
}); |
|
183 | 281 |
|
184 | 282 |
}); |
185 | 283 |
|
186 | 284 |
|
187 | 285 |
app.factory("Device", function ($resource, config) { |
188 |
return function (headers) { |
|
189 |
return $resource(config.API_URL + "/devices/:id", {id: '@id'}, { |
|
190 |
'get': { |
|
191 |
url: config.API_URL + '/devices/:id', |
|
192 |
method: 'GET', |
|
193 |
headers: headers || {} |
|
194 |
}, |
|
195 |
'query': { |
|
196 |
url: config.API_URL + '/devices', |
|
197 |
method: 'GET', |
|
198 |
isArray: true, |
|
199 |
headers: headers || {} |
|
200 |
} |
|
201 |
}); |
|
202 |
}; |
|
286 |
return $resource(config.API_URL + "/devices/:id", {id: '@id'}, { |
|
287 |
'get': { |
|
288 |
url: config.API_URL + '/devices/:id', |
|
289 |
method: 'GET', |
|
290 |
headers: {jwt: config.API_TOKEN} |
|
291 |
}, |
|
292 |
'query': { |
|
293 |
url: config.API_URL + '/devices', |
|
294 |
method: 'GET', |
|
295 |
isArray: true, |
|
296 |
headers: {jwt: config.API_TOKEN} |
|
297 |
} |
|
298 |
}); |
|
203 | 299 |
}); |
204 | 300 |
|
205 | 301 |
app.factory("Vehicle", function ($resource, config) { |
206 |
return function (headers) { |
|
207 |
return $resource(config.API_URL + "/vehicles", null, { |
|
208 |
'query': { |
|
209 |
url: config.API_URL + '/vehicles', |
|
210 |
method: 'GET', |
|
211 |
isArray: true, |
|
212 |
headers: headers || {} |
|
213 |
} |
|
214 |
}); |
|
215 |
}; |
|
302 |
return $resource(config.API_URL + "/vehicles", null, { |
|
303 |
'query': { |
|
304 |
url: config.API_URL + '/vehicles', |
|
305 |
method: 'GET', |
|
306 |
isArray: true, |
|
307 |
headers: {jwt: config.API_TOKEN} |
|
308 |
} |
|
309 |
}); |
|
216 | 310 |
}); |
Také k dispozici: Unified diff
refs #6754: Zobrazení detektorů na mapě, na vybranou lokalitu se zoomuje, kliknutím na marker se zobrazí info