Subversion Repository Public Repository

gpstest

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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%  
    String email=session.getAttribute("email").toString();  
    String password=session.getAttribute("password").toString();  
%>
<title>Nrusingh GPS</title>
<link href="css/jquery-ui.css" rel="stylesheet" />
<link href="css/jquery-ui-timepicker-addon.css" rel="stylesheet" media="all" type="text/css" />
<link href="css/main.css" rel="stylesheet" />
<link href="css/topmenu.css" rel="stylesheet" />
<link href="css/tablestyle.css" rel="stylesheet" />

<script src="https://maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.22&key=AIzaSyAwhtPukjfFu0p8p7KtAToIuLjqSQJmThM"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.min1.11.0.js"></script>
<script src="js/maplace.min.js"></script>
<script src="js/jquery-ui-timepicker-addon.js" type="text/javascript"></script>
<script src="js/jquery-ui-sliderAccess.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function(){
		var eml = '<%= email%>';
		//alert(eml);
		$('#loader_map').hide();
		var url = '';
		//url = 'http://23.92.61.79:8082/api/devices/';
		var position_url = 'http://23.92.61.79:8082/api/positions/';
		var device_url = 'http://23.92.61.79:8082/api/devices';
		
		var username = "admin";
		var password = "admin";

		$('#loader_left').show();
		$('#div_left_menu').hide();
		$.ajax({
			type: 'get',
			url: device_url,
			headers: {
				"Accept": "application/json",         
				"Content-Type": "application/json",
				"Authorization": "Basic " + btoa(username + ":" + password)
			},
			'dataType': 'json',
			success: function (response) {
				console.log('Success: '+JSON.stringify(response));
				$.each(response, function(k,v){
					var id = v.id;
					var name = v.name;
					var uniqueId = v.uniqueId;
					var status = v.status;
					
					var html = '';
					if(status == 'offline')
						html = "<option id='"+id+"^"+uniqueId+"^"+name+"^"+status+"' disabled>"+name+"</option> ";
					else
						html = "<option id='"+id+"^"+uniqueId+"^"+name+"^"+status+"'>"+name+"</option> ";
						
					$("#select_device_list").append(html);
				});
				$('#loader_left').hide();
				$('#div_left_menu').show();
			},
			error: function(response){
				alert('Error: '+JSON.stringify(response));
				$('#loader_left').hide();
				$('#div_left_menu').show();
			}
		});
		
		$(document).on("click", "#btn_show_history", function(event) {
			$('#loader_map').show();
			/* new Maplace({
				locations: [{"lat":"20.3458377","lon":"85.8233476","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3458377","lon":"85.8233476","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3553074","lon":"85.8273524","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3541784","lon":"85.8268995","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3516373","lon":"85.8260807","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3457986","lon":"85.8233062","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3457986","lon":"85.8233062","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3457986","lon":"85.8233062","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3458499","lon":"85.8233477","title":"","html":"","zoom":8,"icon":""},{"lat":"20.345838","lon":"85.8233458","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3458517","lon":"85.8233478","title":"","html":"","zoom":8,"icon":""},{"lat":"20.345866","lon":"85.8233828","title":"","html":"","zoom":8,"icon":""}],			
				//map_div: '#gmap-polyline',
				//controls_div: '#controls-polyline',
				controls_type: 'list',
				controls_on_map: false,
				view_all_text: 'Start',
				type: 'polyline'
			}).Load(); */
			
			
	      	var li_id = $("#select_device_list").children(":selected").attr("id");
			//alert($("#select_device_list").children(":selected").attr("id"));
	      	var id = li_id.split('^')[0];
	      	var uniqueId = li_id.split('^')[1];
	      	var name = li_id.split('^')[2];
	      	var status = li_id.split('^')[3];
	      	
	      	var fromdatestr = $('#dt1').val();
	      	//var todatestr   = $('#dt2').val();
	      	var todatestr   = $('#select_dt2').val();
	      	if(fromdatestr == null || fromdatestr == undefined || fromdatestr.length <= 0
	      			//|| todatestr == null || todatestr == undefined || todatestr.length <= 0
	      			){
	      		alert('Wrong date format !!!');
	      	}else{
	      		var from = getISOdate(fromdatestr); 
	      		//var to   = getISOdate(todatestr); 
	      		var to   = getToDate(fromdatestr, todatestr); 
	      		
	      		var url = "http://23.92.61.79:8082/api/positions?deviceId="+id+"&from="+to+"&to="+from+"";
	      		//alert(url);
	      		$.ajax({
					async:false,
					cache:false,
					dataType:"json",
					type: "get",  
					//url: "http://23.92.61.79:8082/api/positions?deviceId=1&from=2018-05-09T00:00:00.000Z&to=2018-05-09T23:59:59.000Z",
					url: url,
					//data:{id:id,uniqueId:uniqueId,name:name,status:status},
					headers: {
						"Accept": "application/json",         
						"Content-Type": "application/json",
						"Authorization": "Basic " + btoa(username + ":" + password)
					},
					'dataType': 'json',
					success: function (response) {
						var location_arr = [];
						var location_obj = {};
						$('#loader_map').hide();
						//console.log('Success: '+JSON.stringify(response));
						var html = '';
						html += '<div>';
						html += '<table id="mytable" style="width: 100%; font-size: 11px;">';
						html += 	'<tr>';
						html += 		'<th>Device Id</th>';
						html += 		'<th>Distance</th>';
						html += 		'<th>Motion</th>';
						html += 		'<th>Server Time</th>';
						html += 		'<th>Latitude</th>';
						html += 		'<th>Longitude</th>';
						html += 		'<th>Altitude</th>';
						html += 		'<th>Speed</th>';
						html += 		'<th>View</th>';
						html += 	'</tr>';
						$.each(response, function(k,v){
							var id = v.id;
							var deviceId = v.deviceId;
							var distance = v.attributes.distance;
							var motion = v.attributes.motion;
							var serverTime = v.serverTime;
							var latitude = v.latitude;
							var longitude = v.longitude;
							var altitude = v.altitude;
							var speed = v.speed;
							
							serverTime = ISO2Local_Date(serverTime);
							
							html += 	'<tr>';
							html += 		'<td>'+deviceId+'</td>';
							html += 		'<td>'+distance+'</td>';
							html += 		'<td>'+motion+'</td>';
							html += 		'<td>'+serverTime+'</td>';
							html += 		'<td>'+latitude+'</td>';
							html += 		'<td>'+longitude+'</td>';
							html += 		'<td>'+altitude+'</td>';
							html += 		'<td>'+speed+'</td>';
							html += 		'<td></td>';
							html += 	'</tr>';
							
							location_obj = {};
							location_obj["lat"]=latitude;
							location_obj["lon"]=longitude;
							location_obj["title"]="";
							location_obj["html"]="";
							location_obj["zoom"]=8;
							location_obj["icon"]="images/arrow_right.png";
							location_arr.push(location_obj);
						});
						
						html += '</table>';
						html += '</div>';
						$('#div_data').html("");
						$('#div_data').html(html);
						
						
						//  show in map
						new Maplace({
							//locations: [{"lat":"20.3458377","lon":"85.8233476","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3458377","lon":"85.8233476","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3553074","lon":"85.8273524","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3541784","lon":"85.8268995","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3516373","lon":"85.8260807","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3457986","lon":"85.8233062","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3457986","lon":"85.8233062","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3457986","lon":"85.8233062","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3458499","lon":"85.8233477","title":"","html":"","zoom":8,"icon":""},{"lat":"20.345838","lon":"85.8233458","title":"","html":"","zoom":8,"icon":""},{"lat":"20.3458517","lon":"85.8233478","title":"","html":"","zoom":8,"icon":""},{"lat":"20.345866","lon":"85.8233828","title":"","html":"","zoom":8,"icon":""}],			
							locations: location_arr,			
							//map_div: '#gmap-polyline',
							//controls_div: '#controls-polyline',
							controls_type: 'list',
							controls_on_map: false,
							view_all_text: 'Start',
							type: 'polyline'
						}).Load(); 
						
					},
					error: function (response) {
						$('#loader_map').hide();
						console.log('Error: ');
						$('#div_data').html("");
						$('#div_data').html(JSON.stringify(response));
					}
				});
	      	}
	      	 
	    });
		
		
		
		// date picker
		$("#dt1").datetimepicker({
			dateFormat: "yy-mm-dd",
            timeFormat: "HH:mm",
            //ampm:false,
            //pick12HourFormat: false,
            //use24hours: true,
            showSecond:false,
            showMillisec: false,
            showMicrosec: false,
            maxDate: 0,
            onSelect: function () {
                var dt2 = $('#dt2');
                var startDate = $(this).datepicker('getDate');
                var minDate = $(this).datepicker('getDate');
                var dt2Date = dt2.datepicker('getDate');
                //difference in days. 86400 seconds in day, 1000 ms in second
                var dateDiff = (dt2Date - minDate)/(86400 * 1000);
                
                startDate.setDate(startDate.getDate() + 30);
                if (dt2Date == null || dateDiff < 0) {
                		dt2.datepicker('setDate', minDate);
                }
                else if (dateDiff > 30){
                		dt2.datepicker('setDate', startDate);
                }
                //sets dt2 maxDate to the last day of 30 days window
                //dt2.datepicker('option', 'maxDate', startDate);
                dt2.datepicker('option', 'maxDate', 0);
                dt2.datepicker('option', 'minDate', minDate);
            }
        });
        /* $('#dt2').datetimepicker({
        	dateFormat: "yy-mm-dd",
            timeFormat: "HH:mm",
            minDate: 0
        });  */
	});
	function getISOdate(date){
		var ISOdate = '';
		var datedt = new Date(date);
      	var yr = 1900+datedt.getYear(); 
      	var mn = 1+datedt.getMonth(); 
      	var dt = datedt.getDate(); 
      	var hr = datedt.getHours(); 
      	var mi = datedt.getMinutes(); 
      	
      	
      	var year = ''+yr;
      	var mnth = (mn < 10)?'0'+mn:''+mn;
      	var date = (dt < 10)?'0'+dt:''+dt;
      	var hour = (hr < 10)?'0'+hr:''+hr;
      	var mint = (mi < 10)?'0'+mi:''+mi;
      	var scnd = '00'; 
      	ISOdate = year+'-'+mnth+'-'+date+'T'+hour+':'+mint+':'+scnd+'.000Z';
		return ISOdate;
	}
	
	function getToDate(fromdate, hours){
		var ToDate = '';
		var datedt = new Date(fromdate);
		var todt;
		if(hours == 1)
			todt = new Date(datedt - 1*60*60*1000);
		else if(hours == 2)
			todt = new Date(datedt - 2*60*60*1000);
		else if(hours == 5)
			todt = new Date(datedt - 5*60*60*1000);
		
      	var yr = 1900+todt.getYear(); 
      	var mn = 1+todt.getMonth(); 
      	var dt = todt.getDate(); 
      	var hr = todt.getHours(); 
      	var mi = todt.getMinutes(); 
      	
      	
      	var year = ''+yr;
      	var mnth = (mn < 10)?'0'+mn:''+mn;
      	var date = (dt < 10)?'0'+dt:''+dt;
      	var hour = (hr < 10)?'0'+hr:''+hr;
      	var mint = (mi < 10)?'0'+mi:''+mi;
      	var scnd = '00'; 
      	ToDate = year+'-'+mnth+'-'+date+'T'+hour+':'+mint+':'+scnd+'.000Z';
		return ToDate;
	}
	
	function ISO2Local_Date(date){
		var Localdate = '';
		date_arr = date.split('T');
		Localdate = date_arr[0]+" "+date_arr[1].substring(0,8);
		return Localdate;
	}
	
</script>

</head>
<body>
	<div class="container">
		<!-- top panel -->
		<header>
		<div><img src="images/logo1.png" style="width: 100px;"></div>
		<div style="margin-top: -95px; margin-left: 180px;"><h1><a href="login" style="text-decoration: none;color: white;">NRUSiNGH GPS TRACKER</a></h1></div>
		
		<div style="float: right; margin-top: -40px;">
			<span style="font-weight: 900; text-transform: uppercase; vertical-align: 7px;"><%=session.getAttribute("email")%></span>
			<a href="logout"><img src="images/logout.png" alt="logout" style="width: 22px; margin-right: 15px;"/></a>
		</div>
		<jsp:include page="menu.jsp" />
		</header>
		<!-- top panel ends -->

		<!-- left panel -->
		<nav> 
			<div id="loader_left">
				<img id="loader_img_left" alt="Loding ..." src="images/loader.gif" />
			</div>
			<div id="div_left_menu">
				<table>
					<tr>
						<td>Devices</td>
						<td><select id="select_device_list" name="select_device_list"></select></td>
					</tr>
				
					<tr>
						<!-- <td>From</td> -->
						<td>Date</td>
						<td><input type="text" id="dt1" style="width: 136px;"></td>
					</tr>
				
					<tr>
						<!-- <td>To</td> -->
						<td>Since</td>
						<td>
							<!-- <input type="text" id="dt2" style="width: 136px;"> -->
							<select id="select_dt2">
								<option value="1">Last 1 Hour</option>
								<option value="2">Last 2 Hour</option>
								<option value="5">Last 5 Hour</option>
							</select>
						</td>
					</tr>
				
					<tr>
						<td></td>
						<td><input type="button" id="btn_show_history" value="SHOW" /></td>
					</tr>
				</table>
			</div>
		</nav>
		<!-- left panel ends -->

		<!-- right panel -->
		<article> <!-- <p><a href="map.jsp">Map</a></p> -->
			 <div id="div_map" style="with: 400px; height: 400px;">
				<div id="loader_map" style="disply: none;">
					<img id="loader_img_map" alt="Loding ..." src="images/loader.gif" />
				</div>
				<!-- <div id="div_data" style=" overflow: auto; height:350px;"></div> -->
				<div id="gmap" style="with:600px;height:400px;"></div>
			</div> 
			
			
		</article>
		<!-- right panel ends -->

		<!-- buttom panel -->
		<footer><div style="text-align: center"> Copyright &copy; Nrusingha nath Nayak</div></footer>
		<!-- buttom panel ends -->
	</div>
</body>
</html>

Commits for gpstest/WebContent/_tracking_history.jsp

Diff revisions: vs.
Revision Author Commited Message
1 lingaraj picture lingaraj Sat 24 Nov, 2018 13:04:59 +0000