-
Notifications
You must be signed in to change notification settings - Fork 2
/
delivery_associate_add_form.html
785 lines (678 loc) · 31.6 KB
/
delivery_associate_add_form.html
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Daakiya - Route Optimization and Delivery Management</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<link href="./css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="css/theme.css" rel="stylesheet"/>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="./accessKeys.js"></script>
<link rel="icon" href="./img/favicon-d.png">
</head>
<html>
<body>
<!-- Fixed navbar -->
<!--<nav class="navbar navbar-inverse navbar-fixed-top">-->
<!-- <div class="container">-->
<!-- <div class="navbar-header">-->
<!-- <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"-->
<!-- aria-expanded="false" aria-controls="navbar">-->
<!-- <span class="sr-only">Toggle navigation</span>-->
<!-- <span class="icon-bar"></span>-->
<!-- <span class="icon-bar"></span>-->
<!-- <span class="icon-bar"></span>-->
<!-- </button>-->
<!-- <a class="navbar-brand" href="#">Daakiya</a>-->
<!-- </div>-->
<!-- <div id="navbar" class="navbar-collapse collapse">-->
<!-- <ul class="nav navbar-nav">-->
<!-- <li><a href="#">Dashboard</a></li>-->
<!-- <li><a href="#">Delivery Associates</a></li>-->
<!-- <li><a href="#">Orders</a></li>-->
<!-- <li><a href="#">Routes</a></li>-->
<!-- <!– <li class="dropdown">–>-->
<!-- <!– <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>–>-->
<!-- <!– <ul class="dropdown-menu">–>-->
<!-- <!– <li><a href="#">Action</a></li>–>-->
<!-- <!– <li><a href="#">Another action</a></li>–>-->
<!-- <!– <li><a href="#">Something else here</a></li>–>-->
<!-- <!– <li role="separator" class="divider"></li>–>-->
<!-- <!– <li class="dropdown-header">Nav header</li>–>-->
<!-- <!– <li><a href="#">Separated link</a></li>–>-->
<!-- <!– <li><a href="#">One more separated link</a></li>–>-->
<!-- <!– </ul>–>-->
<!-- <!– </li>–>-->
<!-- </ul>-->
<!-- </div><!–/.nav-collapse –>-->
<!-- </div>-->
<!--</nav>-->
<div id="navbarLoader"></div>
<style type="text/css">
.body {
font-family: 'Raleway', sans-serif;
}
.thumbnail {
padding: 4px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
display: inline-block;
max-width: 100%;
height: auto;
box-shadow: 0 1px 2px rgba(0, 0, 0, .075);
}
.header {
margin-top: -19px;
margin-bottom: 29px;
background: linear-gradient(45deg, #083100 0%, #336d61 100%);
box-shadow: 0px 8px 31px 0px #0e0b0b96 inset;
padding-top: 28px;
padding-bottom: 27px;
color: #ececec;
text-shadow: 1px 1px 1px #000;
background: linear-gradient(45deg, #0e1d0c 0%, #335a6d 100%);
}
.header .dropdown-menu {
text-shadow: 0px 0px 0px #000;
/*display:table;*/
}
.dropdown-menu {
top: 27px;
left: 0px;
/*display: table;*/
width: 556px;
}
</style>
<div class="">
<div class="container">
<div class="">
<div class="row">
<!-- <div class="col-xs-12 col-md-12 col-lg-6" style="height: 450px;">-->
<!-- <!– <div class="form-group">–>-->
<!-- <!– <div class="hidden-xs">–>-->
<!-- <!– <input type="password" class="form-control" id="pwd" >–>-->
<!-- <!– </div>–>-->
<!-- <!– </div>–>-->
<!-- <div class="">-->
<!-- <div class="dropdown">-->
<!-- <!– <input onchange="" class="form-control" id="typeahead" placeholder="Search order address here..." type="text"–>-->
<!-- <!– autocomplete="off" data-provide="typeahead"/>–>-->
<!-- <input onchange="this.value = strip(this.value);" class="form-control"-->
<!-- id="typeahead"-->
<!-- class=" typeahead"-->
<!-- placeholder="Start typing order address here to geocode."-->
<!-- style="-->
<!-- height: 38px;-->
<!-- /*box-shadow: 0px 0px 4px 0px #0000005c inset;*/-->
<!-- /*border: 1px solid #CCC;*/-->
<!-- /*margin-bottom: 0px;*/-->
<!-- /*z-index: 3;*/-->
<!-- /*position: absolute;*/-->
<!-- /*margin-top: 31px;*/-->
<!-- /*width: 77%;*/-->
<!-- /*height: 38px;*/-->
<!-- /*box-shadow: 0px 0px 4px 0px #000 inset;*/-->
<!-- /*border: 1px solid black;*/-->
<!-- /* color: #000; */-->
<!-- /* font-size: 23px; */-->
<!-- /*margin-left: 67px;*/-->
<!-- "-->
<!-- type="search"-->
<!-- autocomplete="off" data-provide="typeahead"/>-->
<!-- </div>-->
<!-- </div>-->
<!-- <br/>-->
<!-- <div class="col-xs-12 col-md-12 col-lg-12" style="height: 480px; border:1px solid #CCC;">-->
<!-- <div id="map"-->
<!-- style="height: 100%;width: 100%;position: absolute;top: 0px;left: 0px;-->
<!-- background-color: transparent;-->
<!-- box-shadow: 1px 1px 7px 4px #CCC;-->
<!-- border: 1px solid #CCC;"-->
<!-- ></div>-->
<!-- </div>-->
<!-- </div>-->
<div class="col-xs-12 col-md-10 col-lg-11" style="margin-top: 33px;">
<h1 class="text-center">Delivery Associate Details</h1>
<hr/>
<div class="col-xs-12 col-md-12 col-lg-6">
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-3">Name*: </label>
<div class="col-sm-9">
<input autocomplete="new-customer" id="customerName" type="text" class="form-control" id="deliveryAssociateName" placeholder="Enter Delivery Associate Name" required/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Employee ID: </label>
<div class="col-sm-9">
<input autocomplete="new-customer" id="deliveryAssociateEmpId" type="text" class="form-control" placeholder="Enter Employee ID" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Address*:</label>
<div class="col-sm-9">
<input autocomplete="new-address" id="deliveryAssociateAddress" type="text" class="form-control" placeholder="Enter Delivery Associate address" required/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Enter Email*:</label>
<div class="col-sm-9">
<input autocomplete="new-address" id="deliveryAssociateEmail" type="text" class="form-control" placeholder="Delivery Associate Email" required/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Password*:</label>
<div class="col-sm-9">
<input autocomplete="new-address" id="deliveryAssociatePassword" type="password" class="form-control" placeholder="Default Password" required/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">License Type*:</label>
<div class="col-sm-3">
<select class="form-control col-lg-3" id="licence">
<option>4 Wheeler</option>
<option>2 Wheeler</option>
<option>Both</option>
</select>
</div>
</div>
</form>
</div>
<div class="col-xs-12 col-md-12 col-lg-6" >
<div id="trackinglicenceForm" style="display: none;">
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-3">Tracking ID: </label>
<div class="col-sm-9">
<input autocomplete="new-customer" id="trackingId" type="text" class="form-control" placeholder="Tracking ID" readonly/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Device ID: </label>
<div class="col-sm-9">
<input autocomplete="new-customer" id="deviceId" type="text" class="form-control" placeholder="Device ID" readonly/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Device Name:</label>
<div class="col-sm-9">
<input autocomplete="new-address" id="deviceName" type="text" class="form-control" placeholder="Device Name" />
</div>
</div>
</form>
<script type="text/javascript" src="./js/qrcode.min.js"></script>
<div class="col-xs-12 col-md-12 col-lg-12">
<div id="qrcode" class="text-center col-xs-12 col-md-12 col-lg-4"
style="" ></div>
<div class="col-xs-12 col-md-12 col-lg-7">
<p>Download <a href="https://play.google.com/store/apps/details?id=com.here.iotsenderapp&hl=en" target="_blank">HERE Tracker App </a> from Google Play store and scan the barcode to connect tracking
<a href="https://play.google.com/store/apps/details?id=com.here.iotsenderapp&hl=en" target="_blank" ><img src="img/google_play_store.png" style="height: 70px;"/></a>
</p>
</div>
</div>
</div>
<div id="getNewLicence" style="display: table;">
<div class="text-center col-xs-12 col-md-12 col-lg-12">
<img height="100px" src="./img/here-logo.png" />
</div>
<h3 class="text-center col-xs-12 col-md-12 col-lg-12">HERE Tracking Device Activation</h3>
<div class="text-center col-xs-12 col-md-12 col-lg-12" >
<button type="button" id="addDevice" onClick="activateNewTrackingLicence();" class="btn btn-primary">Activate new device licence</button>
</div>
</div>
<div id="locationLoader" style="display: none;" class="text-center col-xs-12 col-md-12 col-lg-12" >
<img height="200px" src="./img/location_loader.gif" />
</div>
<div id="limitExceededMessage" style="display: none;" class="text-center col-xs-12 col-md-12 col-lg-12" >
<h3>Unable to generate new Device Licence, Limit Exceeded</h3>
</div>
</div>
<div class="col-xs-12 col-md-12 col-lg-12" >
<!-- <br/>-->
<!-- <div class="text-center col-xs-12 col-md-12 col-lg-12" >-->
<!-- <button type="button" id="addDeliveryAssociate" class="btn btn-lg btn-default">Add new delivery associate</button>-->
<!-- </div>-->
<br/>
<div class="text-center col-xs-12 col-md-12 col-lg-6" >
<button type="button" id="addDeliveryAssociate" onclick="addDeliveryAssociate();" class="btn btn-lg btn-default">Add new delivery associate</button>
</div>
</div>
<div class="col-xs-12 col-md-10 col-lg-11">
</div>
<div class="form-group">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel"><span id="myMessage">New message</span></h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="window.location.reload();">Add an another delivery associate</button>
<a href="./delivery_associates_list_view.html" type="button" class="btn btn-primary">View all delivery associates</a>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
$("#navbarLoader").load('./templates/navbar_standard.html')
});
</script>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="container" role="main">
<div class="row">
</div>
</div> <!-- /container -->
<style type="text/css">
.background-input {
background-color:#d9edff;
color:#000;
}
</style>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="./js/vendor/jquery-3.4.1.min.js"><\/script>')</script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/docs.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
<!-- Firebase App (the core Firebase SDK) is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-app.js"></script>
<!-- Add Firebase products that you want to use -->
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-firestore.js"></script>
<script type="text/javascript">
// Your web app's Firebase configuration
var firebaseConfig = module_firebaseConfig;
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Get a reference to the database service
//var database = firebase.database();
var db = firebase.firestore();
var userId = "";
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
console.log("Loaded ", user)
$("#emailId").text(user.email)
//Fetch all orders belonging to that user id - auth.currentUser.uid
let currentUserId = firebase.auth().currentUser.uid; //W0snQdSu0hdDUmTH85BlJKzkPTr2
console.log("currentUserId: ",currentUserId)
userId = currentUserId;
} else {
// No user is signed in.
window.location.href = "/";
}
});
async function addDeliveryAssociate (){
try{
document.getElementById("addDeliveryAssociate").setAttribute("disabled","true");
let validationFailed = false;
//Check whether every value is present - id="customerName"
let customerName = document.getElementById("customerName").value;
if (customerName == ""){
$("#customerName").addClass("background-input");
validationFailed = true;
//return;
}
//id="deliveryAssociateAddress"
let deliveryAssociateAddress = document.getElementById("deliveryAssociateAddress").value;
if (deliveryAssociateAddress == ""){
$("#deliveryAssociateAddress").addClass("background-input")
validationFailed = true;
//return;
}
//id="deliveryAssociateEmail"
let deliveryAssociateEmail = document.getElementById("deliveryAssociateEmail").value;
if (deliveryAssociateEmail == ""){
$("#deliveryAssociateEmail").addClass("background-input")
validationFailed = true;
//return;
}
//id="deliveryAssociateEmail"
let deliveryAssociatePassword = document.getElementById("deliveryAssociatePassword").value;
if (deliveryAssociatePassword == ""){
$("#deliveryAssociatePassword").addClass("background-input")
validationFailed = true;
//return;
}
//id="deliveryAssociatePassword"
let licenceSelect = document.getElementById("licence");
let licenceOption = licenceSelect.options[licenceSelect.selectedIndex].value;//id="licence"
// if (licenceOption == ""){
// //$("#deliveryAssociateEmail").addClass("background-input")
// validationFailed = true;
// //return;
// }
if (validationFailed){
console.log("Please correct the errors..")
document.getElementById("addDeliveryAssociate").removeAttribute("disabled");
return;
}
//Check deviceID, TrackingId, DeviceName
let trackingId = document.getElementById("trackingId").value;
let deviceId = document.getElementById("deviceId").value;
let deviceName = document.getElementById("deviceName").value;
let employeeId = document.getElementById("deliveryAssociateEmpId").value;//
//Store the new name to HERE Tracking Registry
if (trackingId != ""){
let data = await getTrackingAccessToken();
console.log("token:", data.accessToken)
let accessToken = data.accessToken;
if (data && data.accessToken) {
//Change Device Name to Device - new Date().getTime()
let responseNewName = await editDeviceDetails (trackingId, deviceName ,accessToken)
}
}
//Add Data to Firebase under `delivery_associates` table
//var firebaseConfig = module_firebaseConfig;
// Initialize Firebase
//firebase.initializeApp(firebaseConfig);
// Get a reference to the database service
//var database = firebase.database();
var db = firebase.firestore();
let doc = {
status : "AVAILABLE",
associateName: customerName,
employeeId : employeeId,
deliveryAssociateAddress : deliveryAssociateAddress,
deliveryAssociateEmail : deliveryAssociateEmail,
deliveryAssociatePassword : deliveryAssociatePassword,
trackingId : trackingId,
deviceId : deviceId,
deviceName : deviceName,
licenceType : licenceOption,
createdBy : firebase.auth().currentUser.uid
}
//Add a delivery boy to database
let userRegistered = {
userRegistered : false,
errorMessage : {}
};
try {
const auth = firebase.auth();
let isLoggedIn = await auth.createUserWithEmailAndPassword (deliveryAssociateEmail, deliveryAssociatePassword);
console.log(isLoggedIn)
if (isLoggedIn) {
userRegistered.userRegistered = true;
console.log("User created...")
//window.location.refresh();
}
}catch (e) {
console.log("error: unable to register: ", e)
userRegistered.errorMessage = e
//$("#errorMessage").text(e.message)
//$('#errorMessage').show()
}
let documentAdd = await db.collection("delivery_associates").add(doc);
console.log(documentAdd)
if (documentAdd) {
console.log("document successfully added..")
//genrerateNumber();
// if (trackingId != ""){
// $("#myMessage").text("Delivery Associate added successfully, Save the QR..")
// }
let messageText = "Delivery Associate added successfully";
if (userRegistered.userRegistered == false) {
messageText += " However user is not registered. ";
if (userRegistered.errorMessage.message){
messageText += " Error : "+userRegistered.errorMessage.message
}
}
$("#myMessage").text(messageText)
document.getElementById("addDeliveryAssociate").removeAttribute("disabled");
$('#myModal').modal({show: true})
}
document.getElementById("addDeliveryAssociate").removeAttribute("disabled");
}catch(error){
document.getElementById("addDeliveryAssociate").removeAttribute("disabled");
console.log(error);
}
}
async function activateNewTrackingLicence () {
$("#getNewLicence").hide()
$("#locationLoader").show()
try{
let data = await getTrackingAccessToken();
console.log("token:", data.accessToken)
if (data && data.accessToken){
//Get new licence and create a QR Code for it
let appId = module_HERETrackingAccount.trackingAppId;//"zsP1dvyg3Avu97H3kQlG"
let accessToken = data.accessToken;
let deviceDetails = await getNewDeviceLicence(appId, accessToken);
let deviceId = await deviceDetails.deviceId;//"0017e281-6ccd-4e9d-8d92-7d7e2f79919b";
let deviceSecret = await deviceDetails.deviceSecret;//"WIymDxqdYE6XeJyvu3cS-mrNraAZLXsqvndlQjI56iY";
//Get its Tracking ID by making a call into HERE Registry - https://tracking.api.here.com/registry/v2/devices/02ffe85a-2537-4939-9b7d-f76377690962
let trackingdata = await addToDeviceRegistry(deviceId, accessToken);
let trackingId = trackingdata.trackingId;
console.log(trackingId)
//Change Device Name to Device - new Date().getTime()
let deviceName = "Device "+(new Date().getTime())
let responseNewName = await editDeviceDetails (trackingId, deviceName ,accessToken)
var qrcode = new QRCode("qrcode", {
text: "QRCODE",
width: 125,
height: 125,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
qrcode.makeCode('{"id":"'+deviceId+'", "secret":"'+deviceSecret+'"}');
//Update the textboxes - for trackingId deviceId deviceName
document.getElementById("trackingId").value = trackingId;
document.getElementById("deviceId").value = deviceId;
document.getElementById("deviceName").value = deviceName;
//Hide Loader
$("#locationLoader").hide()
// also append the same in tracking id, name of device and device id in text boxes
$('#trackinglicenceForm').show();
}
else {
$("#locationLoader").hide()
$("#limitExceededMessage").show()
}
}
catch (error)
{
console.log(error);
$("#locationLoader").hide()
$("#limitExceededMessage").show()
}
}
function getTrackingAccessToken (){
return new Promise ((resolve, reject) => {
let strTrackingAppEmail = module_HERETrackingAccount.trackingEmail;//"[email protected]"
let strTrackingAppPassword = module_HERETrackingAccount.trackingPassword// "Q2hpcmFnIzAwNw==" //btoa("passwordString")
//Tracking Access Token URL - https://tracking.api.here.com/users/v2/login
$.ajax({
url: 'https://tracking.api.here.com/users/v2/login',
dataType: 'json',
type: 'post',
contentType: 'application/json',
data: JSON.stringify( {
"email": ""+strTrackingAppEmail,
"password": ""+atob(strTrackingAppPassword)
} ),
processData: false,
success: function( data, textStatus, jQxhr ){
//$('#response pre').html( JSON.stringify( data ) );
console.log("data", data);
resolve(data)
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( errorThrown );
reject(jqXhr)
}
});
});
}
//POST - https://tracking.api.here.com/registry/v2/{appId}/one-device
//Authorization - Bearer data.accessToken
//Content-Type - application/json
//Output {"deviceId":"0017e281-6ccd-4e9d-8d92-7d7e2f79919b","deviceSecret":"WIymDxqdYE6XeJyvu3cS-mrNraAZLXsqvndlQjI56iY"}
//Create QR - of above such that {"id":"0017e281-6ccd-4e9d-8d92-7d7e2f79919b","secret":"WIymDxqdYE6XeJyvu3cS-mrNraAZLXsqvndlQjI56iY"}
//Call To Dummy Function as stated above
function getNewDeviceLicence (tracking_appId, accessToken) {
return new Promise((resolve, reject) => {
//Retrieve Data from Tracking API - Eg https://tracking.api.here.com/traces/v2/HERE-970436b8-ab88-4c86-864e-70bdf7faa98c?count=1000 - [{"description":"","enabled":true,"key":"Content-Type","type":"text","value":"application/json"},{"description":"","enabled":true,"key":"Authorization","type":"text","value":"Bearer h1.QqQ1511VSx110Ql_bkhY4w.}
// let data = {"deviceId":"0017e281-6ccd-4e9d-8d92-7d7e2f79919b","deviceSecret":"WIymDxqdYE6XeJyvu3cS-mrNraAZLXsqvndlQjI56iY"}
// resolve(data);
$.ajax({
url: 'https://tracking.api.here.com/registry/v2/'+tracking_appId+'/one-device',
headers: {
'Authorization': 'Bearer '+accessToken,
'Content-Type': 'application/json'
},
dataType: 'json',
type: 'post',
contentType: 'application/json',
processData: false,
success: function( data, textStatus, jQxhr ){
console.log("data", data);
resolve( data )
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( jqXhr );
reject(jqXhr)
}
});
});
}
//Get its Tracking ID by making a call into HERE Registry - PUT - https://tracking.api.here.com/registry/v2/devices/02ffe85a-2537-4939-9b7d-f76377690962
//Heraders / appjson / bearer - token
//OUTPUT - DeviceTrackingID - {"trackingId":"HERE-63a74ed5-18f1-4013-bd74-3562459335b3"}
function addToDeviceRegistry (deviceId, accessToken) {
return new Promise((resolve, reject) => {
//Retrieve Data from Tracking API - Eg https://tracking.api.here.com/traces/v2/HERE-970436b8-ab88-4c86-864e-70bdf7faa98c?count=1000 - [{"description":"","enabled":true,"key":"Content-Type","type":"text","value":"application/json"},{"description":"","enabled":true,"key":"Authorization","type":"text","value":"Bearer h1.QqQ1511VSx110Ql_bkhY4w.}
// let data = {"trackingId":"HERE-63a74ed5-18f1-4013-bd74-3562459335b3"}
// resolve(data)
$.ajax({
url: 'https://tracking.api.here.com/registry/v2/devices/'+deviceId,
headers: {
'Authorization': 'Bearer '+accessToken,
'Content-Type': 'application/json'
},
dataType: 'json',
type: 'put',
contentType: 'application/json',
processData: false,
success: function( data, textStatus, jQxhr ){
console.log("data", data);
resolve( data )
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( jqXhr );
reject(jqXhr)
}
});
});
}
/**https://tracking.api.here.com/shadows/v2/{HERE-TrackingID from above}HERE-970436b8-ab88-4c86-864e-70bdf7faa98c same header params
body : {
"desired": {
"payload": {
"refAppData": {
"name": "Device"+new Date().getTime(),
"icon": "GENERIC"
}
}
}
}
OUTPUT {
"desired": {
"payload": {
"refAppData": {
"name": "Device ",
"icon": "GENERIC"
}
},
"timestamp": 1560518125100,
"system": {
"stateVersion": 1,
"lastModifiedGeofenceTimestamp": 0
}
}
}
**/
function editDeviceDetails (trackingId, newName ,accessToken){
return new Promise((resolve, reject) => {
//Retrieve Data from Tracking API - Eg https://tracking.api.here.com/traces/v2/HERE-970436b8-ab88-4c86-864e-70bdf7faa98c?count=1000 - [{"description":"","enabled":true,"key":"Content-Type","type":"text","value":"application/json"},{"description":"","enabled":true,"key":"Authorization","type":"text","value":"Bearer h1.QqQ1511VSx110Ql_bkhY4w.}
// let data = {"trackingId":"HERE-63a74ed5-18f1-4013-bd74-3562459335b3"}
// resolve(data)
$.ajax({
url: 'https://tracking.api.here.com/shadows/v2/'+trackingId,
headers: {
'Authorization': 'Bearer '+accessToken,
'Content-Type': 'application/json'
},
data: JSON.stringify(
{
"desired": {
"payload": {
"refAppData": {
"name": ""+newName,
"icon": "GENERIC"
}
}
}
}
),
dataType: 'json',
type: 'put',
contentType: 'application/json',
processData: false,
success: function( data, textStatus, jQxhr ){
//$('#response pre').html( JSON.stringify( data ) );
console.log("data", data);
resolve( data )
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( jqXhr );
reject(jqXhr)
}
});
});
}
</script>
<svg xmlns="http://www.w3.org/2000/svg" width="1140" height="500" viewBox="0 0 1140 500" preserveAspectRatio="none"
style="display: none; visibility: hidden; position: absolute; top: -100%; left: -100%;">
<defs>
<style type="text/css"></style>
</defs>
<text x="0" y="57" style="font-weight:bold;font-size:57pt;font-family:Arial, Helvetica, Open Sans, sans-serif">
</text>
</svg>
</body>
</html>