-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmobile.htm
executable file
·726 lines (640 loc) · 35.3 KB
/
mobile.htm
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<title>GS1 Scan4Transport Mobile Demo</title>
<script src="jsQR.js"></script>
<style>
body {
font-family: 'Ropa Sans', sans-serif;
color: #333;
margin: 10px auto;
position: relative;
font-size: 1em;
}
h1 {
margin: 10px 0;
font-size: 1.8em;
}
#loadingMessage {
text-align: center;
padding: 40px;
background-color: #eee;
}
#canvas {
width: 100%;
}
#output {
margin-top: 20px;
background: #eee;
padding: 10px;
padding-bottom: 0;
}
#output div {
padding-bottom: 10px;
word-wrap: break-word;
}
#noQRFound {
text-align: center;
}
#outputData {
width: 100%; height: 200px; font-size: 0.7em;
}
#clear {
font-size: 1.5em;
}
#showHideURI {
font-size: 1.5em;
}
#showHideVideo {
font-size: 1.5em;
}
.fullwidth {
width: 100%;
}
.centred {
text-align:center; font-size: 1.5em;
}
.halfwidth {
width: 50%;
}
.thirdwidth {
width: 33%;
}
.active {
background-color: #000099;
color: #FFFFFF;
font-weight: 700;
}
.inactive {
background-color: #CCCCCC;
color: #000000;
font-weight: 400;
}
.shippingAddress {
background-color: #FFFFCC;
}
.returnAddress {
background-color: #CCCCFF;
}
.transportTaskInfo { background-color: #FFCCCC;}
.shippingAddress { background-color: #FFFFCC;}
.deliveryInstructions { background-color: #CCFFCC;}
.returnAddress { background-color: #CCCCFF;}
.freightUnitInformation { background-color: #CCFFFF;}
.otherIdentifiers { background-color: #FFCC99;}
.measurements { background-color: #D9D9D9;}
.s4tdetected { background-color: #000099; color: #FFFFFF;}
td.label { width: 50%; font-size: 1.5em;}
td.boldvalue {font-weight: 700; font-size: 1.5em;}
td.value {font-weight: 400; font-size: 1.5em;}
</style>
</head>
<body>
<h1>GS1 Scan4Transport Mobile Demo</h1>
<p>Point the rear-facing camera of your smartphone at a QR code containing Scan4Transport data.</p>
<div id="app1">
<div id="loadingMessage">🎥 Unable to access video stream (please make sure you have a webcam enabled)</div>
<canvas id="canvas" v-show="v==1"></canvas>
<div id="output">
<div v-if="u==1"><p><b>URI:</b></p><textarea id="outputData" v-model="gs1dlURI2decode"></textarea></div>
</div>
<table class="fullwidth">
<tr><td class="thirdwidth"><input class="fullwidth centred" type="button" id="showHideVideo" v-bind:value="showHideVideoText[v]" @click="toggleVideo"></td><td class="thirdwidth"><input class="fullwidth centred" type="button" id="showHideURI" v-bind:value="showHideURIText[u]" @click="toggleURI"></td><td class="thirdwidth"><input class="fullwidth centred" id="clear" type="button" @click="clearURI" value="Clear URI"></td></tr>
</table>
<hr>
<table class="fullwidth">
<tr><td class="halfwidth"><input type="button" class="fullwidth centred" value="Shipping address" @click="toggle(0)" v-bind:class="{'active' : t==0, 'inactive': t==1}"></td><td class="halfwidth"><input type="button" class="fullwidth centred" value="Return address" @click="toggle(1)" v-bind:class="{'active' : t==1, 'inactive': t==0}"></td></tr>
</table>
<div v-if="t==0" class="shippingAddress">
<table class="fullwidth">
<tbody v-for="ex in shippingAddressInfo">
<tr class="shippingAddress"><td class="label" v-bind:title="ex.definition" v-if="l==1">{{ex.label}}</td><td class="boldvalue"><span v-if="s4tObj.obj[ex.code].datatype=='gs1:CountryCode'">{{countryCodes[queryStringExtracted[ex.code]]}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:string'">{{queryStringExtracted[ex.code]}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:date'">{{gs1date3(queryStringExtracted[ex.code])}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:boolean'">{{booleanValue(queryStringExtracted[ex.code])}}</span></td></tr>
<tr class="shippingAddress" v-if="ex.geocode == true"><td></td><td>Lat: {{decodedLat}}<br/>Lon: {{decodedLon}}</td><td></td></tr>
<tr class="shippingAddress" v-if="ex.geocode == true"><td></td><td><span v-if="osMapLink"><a :href="osMapLink" target="_blank">View on OpenStreetMap</a></td><td></td></tr>
</tbody>
</table>
</div>
<div v-if="t==1" class="returnAddress">
<table class="fullwidth">
<tbody v-for="ex in returnAddressInfo">
<tr class="returnAddress"><td class="label" v-bind:title="ex.definition" v-if="l==1">{{ex.label}}</td><td class="boldvalue"><span v-if="s4tObj.obj[ex.code].datatype=='gs1:CountryCode'">{{countryCodes[queryStringExtracted[ex.code]]}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:string'">{{queryStringExtracted[ex.code]}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:date'">{{gs1date3(queryStringExtracted[ex.code])}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:boolean'">{{booleanValue(queryStringExtracted[ex.code])}}</span></td></tr>
</tbody>
</table>
</div>
<div class="otherIdentifiers">
<table class="fullwidth">
<tbody>
<tr class="otherIdentifiers"><td class="label">{{primaryValueExtracted.code}}</td><td class="boldvalue">{{primaryValueExtracted.value}}<span></td></tr>
</tbody>
<tbody v-for="ex in otherIdentifiers">
<tr class="otherIdentifiers"><td class="label" v-bind:title="ex.definition">{{ex.label}}</td><td class="value"><span v-if="s4tObj.obj[ex.code].datatype=='xsd:string'">{{queryStringExtracted[ex.code]}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:date'">{{gs1date3(queryStringExtracted[ex.code])}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:boolean'">{{booleanValue(queryStringExtracted[ex.code])}}</span></td></tr>
</tbody>
</table>
</div>
<div class="transportTaskInfo">
<table class="fullwidth">
<tbody v-for="ex in transportTaskInformation">
<tr class="transportTaskInfo"><td class="label" v-bind:title="ex.definition">{{ex.label}}</td><td class="value"><span v-if="s4tObj.obj[ex.code].datatype=='xsd:string'">{{queryStringExtracted[ex.code]}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:date'">{{gs1date3(queryStringExtracted[ex.code])}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:boolean'">{{booleanValue(queryStringExtracted[ex.code])}}</span></td></tr>
</tbody>
</table>
</div>
<div class="deliveryInstructions">
<table class="fullwidth">
<tbody v-for="ex in deliveryInstructions">
<tr class="deliveryInstructions"><td class="label" v-bind:title="ex.definition">{{ex.label}}</td><td class="value"><span v-if="s4tObj.obj[ex.code].datatype=='xsd:string'">{{queryStringExtracted[ex.code]}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:date'">{{gs1date3(queryStringExtracted[ex.code])}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:dateTime'">{{gs1date4(queryStringExtracted[ex.code])}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:boolean'">{{booleanValue(queryStringExtracted[ex.code])}}</span></td></tr>
</tbody>
</table>
</div>
<div class="freightUnitInformation">
<table class="fullwidth">
<tbody v-for="ex in freightUnitInformation">
<tr class="freightUnitInformation"><td class="label" v-bind:title="ex.definition">{{ex.label}}</td><td class="value"><span v-if="s4tObj.obj[ex.code].datatype=='xsd:string'">{{queryStringExtracted[ex.code]}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:date'">{{gs1date3(queryStringExtracted[ex.code])}}</span><span v-if="s4tObj.obj[ex.code].datatype=='xsd:boolean'">{{booleanValue(queryStringExtracted[ex.code])}}</span></td></tr>
</tbody>
</table>
</div>
<div class="measurements">
<table class="fullwidth">
<tbody v-for="ex in measurements">
<tr class="measurements"><td class="label" v-bind:title="ex.definition">{{ex.label}}</td><td class="value">{{gs1ToMeasurement(queryStringExtracted, ex.code).value}} <span v-if="gs1ToMeasurement(queryStringExtracted, ex.code).value > ''">{{ex.unit}}</span></td></tr>
</tbody>
</table>
</div>
<div class="s4tdetected">
<table class="fullwidth">
<tbody>
<tr class="s4tdetected"><td class="label">Scan4Transport URI?</td><td class="value">{{s4tDetected}}</td></tr>
</tbody>
</table>
</div>
</div>
<script>
var qrURI="";
var t=0;
var u=0;
var v=0;
var l=0;
var showHideURIText=['Show URI','Hide URI'];
var showHideVideoText=['Show Camera','Hide Camera'];
var s4tPrimaryIdentifiers=[
{"code":'00',"label":'SSCC',"grouping":'PrimaryIdentifiers',"datatype":"xsd:string","definition":'Serial Shipping Container Code (SSCC)',"example":"106141412345678908","percentEncoded":false,"pattern":"[0-9]{18}"},
{"code":'401',"label":'GINC',"grouping":'PrimaryIdentifiers',"datatype":"xsd:string","definition":'Global Identification Number for Consignment (GINC)',"example":"0614141ABC12345","percentEncoded":false,"pattern":"[0-9]{4}.{0,26}"},
{"code":'402',"label":'GSIN',"grouping":'PrimaryIdentifiers',"datatype":"xsd:string","definition":'Global Shipment Identification Number (GSIN)',"example":"06141410000000012","percentEncoded":false,"pattern":"[0-9]{17}"}
];
var s4tTerms=[
{"code":'4300',"label":'Ship-to / Deliver-to company',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'Name of the company and/or per receiving the freight unit',"example":"Café Niçoise at GS1 AISBL","percentEncoded":true},
{"code":'4301',"label":'Ship-to / Deliver-to contact',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'Name of the company and/or per receiving the freight unit',"example":"Jaco Voorspuij","percentEncoded":true},
{"code":'4302',"label":'Ship-to / Deliver-to address line 1',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'Receiving company/residential street address (Line 1)',"example":"Avenue Louise 326","percentEncoded":true},
{"code":'4303',"label":'Ship-to / Deliver-to address line 2',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'Receiving company/residential street address (Line 2)',"example":"Blue Tower","percentEncoded":true},
{"code":'4304',"label":'Ship-to / Deliver-to suburb',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'Receiving company/residential Suburb',"example":"Ixelles","percentEncoded":true},
{"code":'4305',"label":'Ship-to / Deliver-to locality (town/city)',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'Receiving company/residential Locality (town/city)',"example":"Bruxelles","percentEncoded":true},
{"code":'4306',"label":'Ship-to / Deliver-to region (state/county)',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'Receiving company Region (state/county)',"example":"Brussels-Capital Region","percentEncoded":true},
{"code":'4307',"label":'Ship-to / Deliver-to country code',"grouping":'ShippingAddressInformation',"datatype":"gs1:CountryCode","definition":'Receiving company/residential Country',"example":"BE","percentEncoded":false},
{"code":'420', "label":'Ship-to / Deliver-to postal code',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'Receiving company/residential Postcode',"example":"1050","percentEncoded":false},
{"code":'4308',"label":'Ship-to / Deliver-to phone number',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'Contact phone number for the receiver of the freight unit. Used to populate the system when no EDI has been received','example':"+32 2 788 78 00","percentEncoded":false},
{"code":'4309',"label":'Ship-to / Deliver-to geocode',"grouping":'ShippingAddressInformation',"datatype":"xsd:string","definition":'20-digit geocode representing WGS84 latitude,/longitude for ship-to/deliver-to location','example':"14220219500001282028","percentEncoded":false,"geocode":true},
{"code":'4310',"label":'Return-to company name',"grouping":'ReturnAddressInformation',"datatype":"xsd:string","definition":'Company name for the return to address',"example":"GS1 Global Office","percentEncoded":true},
{"code":'4311',"label":'Return-to contact',"grouping":'ReturnAddressInformation',"datatype":"xsd:string","definition":'Name of the contact freight unit is to be returned to',"example":"Dan Mullen","percentEncoded":true},
{"code":'4312',"label":'Return-to address line 1',"grouping":'ReturnAddressInformation',"datatype":"xsd:string","definition":'Return to company/residential street address (Line 1)',"example":"300 Charles Ewing Boulevard","percentEncoded":true},
{"code":'4313',"label":'Return-to address line 2',"grouping":'ReturnAddressInformation',"datatype":"xsd:string","definition":'Return to company/residential street address (Line 2)',"example":"Ground Floor Suite","percentEncoded":true},
{"code":'4314',"label":'Return-to suburb',"grouping":'ReturnAddressInformation',"datatype":"xsd:string","definition":'Return to company/residential Suburb',"example":"Ewingville","percentEncoded":true},
{"code":'4315',"label":'Return-to locality (town/city)',"grouping":'ReturnAddressInformation',"datatype":"xsd:string","definition":'Return to company/residential Locality (town/city)',"example":"Ewing","percentEncoded":true},
{"code":'4316',"label":'Return-to region (state/county)',"grouping":'ReturnAddressInformation',"datatype":"xsd:string","definition":'Return to company/residential Region (state/county)',"example":"New Jersey","percentEncoded":true},
{"code":'4317',"label":'Return-to country code',"grouping":'ReturnAddressInformation',"datatype":"gs1:CountryCode","definition":'Return to company/residential Country',"example":"US","percentEncoded":false},
{"code":'4318',"label":'Return-to postal code',"grouping":'ReturnAddressInformation',"datatype":"xsd:string","definition":'Return to company/residential Postcode',"example":"08628","percentEncoded":false},
{"code":'4319',"label":'Return-to phone number',"grouping":'ReturnAddressInformation',"datatype":"xsd:string","definition":'Contact phone number for the receiver of the freight unit. Used to populate the system when no EDI has been received','example':"+32 2 788 78 00","percentEncoded":false},
{"code":'4320',"label":'Service code description',"grouping":'TransportTaskInformation',"datatype":"xsd:string","definition":'Freight service code specifies if it is a standard, express, overnight, same day service, etc. This will be unique to the shipper.',"example":"express","percentEncoded":true},
{"code":'4321',"label":'Dangerous goods flag',"grouping":'FreightUnitInformation',"datatype":"xsd:boolean","definition":'A flag to indicate if the freight unit contains Dangerous Goods',"example":"0","percentEncoded":false},
{"code":'4322',"label":'Authority to leave',"grouping":'DeliveryInstructions',"datatype":"xsd:boolean","definition":'This indicates to the operator that he/she may leave the transport unit at the destination location. Implies the operator does not need to hand the transport unit over to a person. Also implies no signature from recipient is required.',"example":"0","percentEncoded":false},
{"code":'4323',"label":'Signature required flag',"grouping":'DeliveryInstructions',"datatype":"xsd:boolean","definition":'This indicates to the operator that the operator must get a signature from the recipient for having delivered the transport unit to the intended destination. This implies that delivery must be made to a person.',"example":"1","percentEncoded":false},
{"code":'4324',"label":'Not before delivery date time',"grouping":'DeliveryInstructions',"datatype":"xsd:dateTime","definition":'In transportation, it is a common business requirement to not deliver before a set date.',"example":"2020-01-18","percentEncoded":false},
{"code":'4325',"label":'Not after delivery date time',"grouping":'DeliveryInstructions',"datatype":"xsd:dateTime","definition":'In transportation, it is a common business requirement to deliver before a set date.',"example":"2020-01-25","percentEncoded":false},
{"code":'4326',"label":'Release date',"grouping":'DeliveryInstructions',"datatype":"xsd:date","definition":"Sometimes transport service providers are required to 'hold' transport units for a while before these transport units are allowed to be sent out to recipients.","example":"2020-01-15","percentEncoded":false},
{"code":'401',"label":'GINC',"grouping":'OtherIdentifiers',"datatype":"xsd:string","definition":'Global Identification Number for Consignment (GINC)',"example":"9521234ABC12345","percentEncoded":false},
{"code":'402',"label":'GSIN',"grouping":'OtherIdentifiers',"datatype":"xsd:string","definition":'Global Shipment Identification Number (GSIN)',"example":"95212340000000012","percentEncoded":false},
{"code":'8003',"label":'GRAI',"grouping":'OtherIdentifiers',"datatype":"xsd:string","definition":'Global Returnable Asset Identifier (GRAI)',"example":"095211411234545678","percentEncoded":false},
{"code":'403',"label":'Routing code',"grouping":'OtherIdentifiers',"datatype":"xsd:string","definition":'Routing Code: AI(403)',"example":"DEF19485","percentEncoded":false},
{"code":'410',"label":'Ship-to / Deliver-to GLN',"grouping":'OtherIdentifiers',"datatype":"xsd:string","definition":'Ship-to / Deliver-to GLN',"example":"9529876987658","percentEncoded":false},
{"code":'413',"label":'Ship-for / Deliver-for GLN',"grouping":'OtherIdentifiers',"datatype":"xsd:string","definition":'Ship-for / Deliver-for GLN',"example":"9529876567898","percentEncoded":false},
{"code":'330n',"label":'Logistic Weight (kg)',"grouping":'Measurements',"datatype":"gs1:Measurement","definition":'Logistic weight (kg)',"example":"13.542","unit":"kg","percentEncoded":false},
{"code":'331n',"label":'Length of first dimension (m)',"grouping":'Measurements',"datatype":"gs1:Measurement","definition":'Length of first dimension (m)',"example":"0.75","unit":"m","percentEncoded":false},
{"code":'332n',"label":'Width of second dimension (m)',"grouping":'Measurements',"datatype":"gs1:Measurement","definition":'Width of second dimension (m)',"example":"0.55","unit":"m","percentEncoded":false},
{"code":'333n',"label":'Depth, thickness, height (m)',"grouping":'Measurements',"datatype":"gs1:Measurement","definition":'Depth, thickness, height or third dimension (m)',"example":"0.35","unit":"m","percentEncoded":false},
{"code":'336n',"label":'Logistic volume (cubic metres)',"grouping":'Measurements',"datatype":"gs1:Measurement","definition":'Logistic volume (cubic metres)',"example":"0.085","unit":"m^3","percentEncoded":false}
];
function filterByGrouping(grouping) {
return function(element) {
return element.grouping==grouping;
};
}
function filterExcludeGrouping(grouping) {
return function(element) {
return element.grouping!==grouping;
};
}
function filterByLabel(id) {
return function(element) {
return element.label==id;
};
}
function filterExcludeLabel(id) {
return function(element) {
return element.label!==id;
};
}
function gs1date(xsdDate) {
return xsdDate.replace(/\d\d(\d\d)-(\d\d)-(\d\d)/,"$1$2$3");
}
function gs1measurement(val) {
var ndp=0;
var rv={};
var numeric="";
if (val.indexOf(".")> -1) {
var parts=val.split(".");
ndp=parts[1].length;
numeric=parts[0]+parts[1];
} else {
numeric=val;
}
if (numeric.length < 6) {
numeric="0".repeat(6-numeric.length)+numeric;
}
rv.ndp=ndp;
rv.sixdigit=numeric;
return rv;
}
function latlon2geocode(lat,lon) {
function pad10(str) {
return "0".repeat(10-str.length)+str;
}
let rv="";
if ((lat!=="") && (lon !=="")) {
let la=parseFloat(lat);
let lo=parseFloat(lon);
if (lo < 0) {
lo+=360;
}
la+=90;
let lat7=Math.floor(la*1e7+0.499);
let lon7=Math.floor(lo*1e7+0.499);
rv= pad10(lat7.toString())+pad10(lon7.toString());
}
return rv;
}
function geocode2latlon(geocode) {
function truncateAfter7Digits(str) {
let re=new RegExp('^([-]?\\d+\\.\\d{7})(\\d+)$');
if (re.test(str)) {
let arr = re.exec(str);
return arr[1];
} else {
return str;
}
}
let re=new RegExp('^[0-9]{20}$');
if ( (geocode !=="") && (re.test(geocode)) ) {
let clat=geocode.substr(0,10);
let clon=geocode.substr(10,10);
let lat=(parseInt(clat)-900000000)/1e7;
let lon=parseInt(clon)/1.00000000e7;
if (lon > 180) {
lon -=360;
}
return {"lat":truncateAfter7Digits(lat.toString()),"lon":truncateAfter7Digits(lon.toString())};
} else {
return {}
}
}
function osmMapURL(lat,lon) {
if ((lat!=="")&&(lon!=="")){
return "https://www.openstreetmap.org/?mlat="+lat+"+&mlon="+lon+"#map=18/"+lat+"/"+lon;
} else {
return "";
}
}
function processS4Tarray(s4tTerms) {
var orderedKeys=[];
var obj={};
var rv={};
s4tTerms.forEach(function(element) {
orderedKeys.push(element.code);
obj[element.code]=element;
});
rv.orderedKeys=orderedKeys;
rv.obj=obj;
return rv;
}
var s4tObj=processS4Tarray(s4tTerms);
var mode=0;
var zeroToFive=["0","1","2","3","4","5"];
var countryCodes={"AF":"Afghanistan","AX":"Åland Islands","AL":"Albania","DZ":"Algeria","AS":"American Samoa","AD":"Andorra","AO":"Angola","AI":"Anguilla","AQ":"Antarctica","AG":"Antigua and Barbuda","AR":"Argentina","AM":"Armenia","AW":"Aruba","AU":"Australia","AT":"Austria","AZ":"Azerbaijan","BS":"Bahamas","BH":"Bahrain","BD":"Bangladesh","BB":"Barbados","BY":"Belarus","BE":"Belgium","BZ":"Belize","BJ":"Benin","BM":"Bermuda","BT":"Bhutan","BT":"Bhutan","BO":"Bolivia (Plurinational State of)","BO":"Bolivia (Plurinational State of)","BQ":"Bonaire, Sint Eustatius and Saba","BA":"Bosnia and Herzegovina","BW":"Botswana","BV":"Bouvet Island","BR":"Brazil","IO":"British Indian Ocean Territory","BN":"Brunei Darussalam","BG":"Bulgaria","BF":"Burkina Faso","BI":"Burundi","KH":"Cambodia","CM":"Cameroon","CA":"Canada","CV":"Cabo Verde","KY":"Cayman Islands","CF":"Central African Republic","TD":"Chad","CL":"Chile","CL":"Chile","CN":"China","CX":"Christmas Island","CC":"Cocos (Keeling) Islands","CO":"Colombia","CO":"Colombia","KM":"Comoros","CG":"Congo","CD":"Congo (Democratic Republic of the)","CK":"Cook Islands","CR":"Costa Rica","CI":"Côte d'Ivoire","HR":"Croatia","CU":"Cuba","CU":"Cuba","CW":"Curaçao","CY":"Cyprus","CZ":"Czech Republic","DK":"Denmark","DJ":"Djibouti","DM":"Dominica","DO":"Dominican Republic","EC":"Ecuador","EG":"Egypt","SV":"El Salvador","SV":"El Salvador","GQ":"Equatorial Guinea","ER":"Eritrea","EE":"Estonia","ET":"Ethiopia","FK":"Falkland Islands (Malvinas)","FO":"Faroe Islands","FJ":"Fiji","FI":"Finland","FR":"France","GF":"French Guiana","PF":"French Polynesia","TF":"French Southern Territories","GA":"Gabon","GM":"Gambia","GE":"Georgia","DE":"Germany","GH":"Ghana","GI":"Gibraltar","GR":"Greece","GL":"Greenland","GD":"Grenada","GP":"Guadeloupe","GU":"Guam","GT":"Guatemala","GG":"Guernsey","GN":"Guinea","GW":"Guinea-Bissau","GY":"Guyana","HT":"Haiti","HT":"Haiti","HM":"Heard Island and McDonald Islands","VA":"Holy See","HN":"Honduras","HK":"Hong Kong","HU":"Hungary","IS":"Iceland","IN":"India","ID":"Indonesia","IR":"Iran (Islamic Republic of)","IQ":"Iraq","IE":"Ireland","IM":"Isle of Man","IL":"Israel","IT":"Italy","JM":"Jamaica","JP":"Japan","JE":"Jersey","JO":"Jordan","KZ":"Kazakhstan","KE":"Kenya","KI":"Kiribati","KP":"Korea (Democratic People's Republic of)","KR":"Korea (Republic of)","KW":"Kuwait","KG":"Kyrgyzstan","LA":"Lao People's Democratic Republic","LV":"Latvia","LB":"Lebanon","LS":"Lesotho","LS":"Lesotho","LR":"Liberia","LY":"Libya","LI":"Liechtenstein","LT":"Lithuania","LU":"Luxembourg","MO":"Macao","MK":"Macedonia (the former Yugoslav Republic of)","MG":"Madagascar","MW":"Malawi","MY":"Malaysia","MV":"Maldives","ML":"Mali","MT":"Malta","MH":"Marshall Islands","MQ":"Martinique","MR":"Mauritania","MU":"Mauritius","YT":"Mayotte","MX":"Mexico","MX":"Mexico","FM":"Micronesia (Federated States of)","MD":"Moldova (Republic of)","MC":"Monaco","MN":"Mongolia","ME":"Montenegro","MS":"Montserrat","MA":"Morocco","MZ":"Mozambique","MM":"Myanmar","NA":"Namibia","NA":"Namibia","NR":"Nauru","NP":"Nepal","NL":"Netherlands","NC":"New Caledonia","NZ":"New Zealand","NI":"Nicaragua","NE":"Niger","NG":"Nigeria","NU":"Niue","NF":"Norfolk Island","MP":"Northern Mariana Islands","NO":"Norway","OM":"Oman","PK":"Pakistan","PW":"Palau","PS":"Palestine, State of","PA":"Panama","PA":"Panama","PG":"Papua New Guinea","PY":"Paraguay","PE":"Peru","PH":"Philippines","PN":"Pitcairn","PL":"Poland","PT":"Portugal","PR":"Puerto Rico","QA":"Qatar","RE":"Réunion","RO":"Romania","RU":"Russian Federation","RW":"Rwanda","BL":"Saint Barthélemy","SH":"Saint Helena, Ascension and Tristan da Cunha","KN":"Saint Kitts and Nevis","LC":"Saint Lucia","MF":"Saint Martin (French part)","PM":"Saint Pierre and Miquelon","VC":"Saint Vincent and the Grenadines","WS":"Samoa","SM":"San Marino","ST":"Sao Tome and Principe","SA":"Saudi Arabia","SN":"Senegal","RS":"Serbia","SC":"Seychelles","SL":"Sierra Leone","SG":"Singapore","SX":"Sint Maarten (Dutch part)","SK":"Slovakia","SI":"Slovenia","SB":"Solomon Islands","SO":"Somalia","ZA":"South Africa","GS":"South Georgia and the South Sandwich Islands","SS":"South Sudan","ES":"Spain","LK":"Sri Lanka","SD":"Sudan","SR":"Suriname","SJ":"Svalbard and Jan Mayen","SZ":"Swaziland","SE":"Sweden","CH":"Switzerland","SY":"Syrian Arab Republic","TW":"Taiwan, Province of China","TJ":"Tajikistan","TZ":"Tanzania, United Republic of","TH":"Thailand","TL":"Timor-Leste","TG":"Togo","TK":"Tokelau","TO":"Tonga","TT":"Trinidad and Tobago","TN":"Tunisia","TR":"Turkey","TM":"Turkmenistan","TC":"Turks and Caicos Islands","TV":"Tuvalu","UG":"Uganda","UA":"Ukraine","AE":"United Arab Emirates","GB":"United Kingdom of Great Britain and Northern Ireland","US":"United States of America","UM":"United States Minor Outlying Islands","UY":"Uruguay","UY":"Uruguay","UZ":"Uzbekistan","VU":"Vanuatu","VE":"Venezuela (Bolivarian Republic of)","VN":"Viet Nam","VG":"Virgin Islands (British)","VI":"Virgin Islands (U.S.)","WF":"Wallis and Futuna","EH":"Western Sahara","YE":"Yemen","ZM":"Zambia","ZW":"Zimbabwe"};
var sscc="";
var uriStem="";
var s4tData={};
var gs1dlURI2decode="";
var booleans={"1":"Yes","0":"No",undefined:""};
var app1=Vue.createApp({
data() {
return {
gs1dlURI2decode : gs1dlURI2decode,
t : t,
u : u,
showHideURIText : showHideURIText,
v : v,
l : l,
showHideVideoText : showHideVideoText,
s4tTerms: s4tTerms,
sscc: sscc,
uriStem: uriStem,
s4tData: s4tData,
qrURI: qrURI,
mode: mode,
booleans: booleans,
zeroToFive: zeroToFive,
gs1dlURI2decode : gs1dlURI2decode,
countryCodes : countryCodes
}
},
computed : {
decodedGeo : function() {
let g = this.queryStringExtracted['4309'];
return geocode2latlon(g);
},
decodedLat : function() {
if (this.decodedGeo.hasOwnProperty("lat")) {
return this.decodedGeo.lat;
} else {
return "";
}
},
decodedLon : function() {
if (this.decodedGeo.hasOwnProperty("lon")) {
return this.decodedGeo.lon;
} else {
return "";
}
},
osMapLink : function() {
return osmMapURL(this.decodedLat,this.decodedLon);
},
s4tObj : function() {
return processS4Tarray(this.s4tTerms);
},
s4tDataJSON : function() {
return JSON.stringify(this.s4tData);
},
deliveryInstructions : function() {
return s4tTerms.filter(filterByGrouping("DeliveryInstructions"));
},
taskInfo : function() {
return s4tTerms.filter(filterByGrouping("TransportTaskInformation"));
},
returnAddressInfo : function() {
return s4tTerms.filter(filterByGrouping("ReturnAddressInformation"));
},
shippingAddressInfo : function() {
return s4tTerms.filter(filterByGrouping("ShippingAddressInformation"));
},
transportTaskInformation : function() {
return s4tTerms.filter(filterByGrouping("TransportTaskInformation"));
},
freightUnitInformation: function() {
return s4tTerms.filter(filterByGrouping("FreightUnitInformation"));
},
otherIdentifiers: function() {
return s4tTerms.filter(filterByGrouping("OtherIdentifiers")).filter(filterExcludeLabel(this.primaryValueExtracted.code));
},
measurements: function() {
return s4tTerms.filter(filterByGrouping("Measurements"));
},
queryStringExtracted: function() {
var uri=this.gs1dlURI2decode;
var qso={};
if (uri !== undefined && uri !== null && uri !== "") {
if (uri.indexOf(" ")> -1) {
uri=uri.substr(0,uri.indexOf(" "));
}
var qsa=uri.substr(1-(0-uri.indexOf("?"))).split("&");
qsa.forEach(function(el) {
if (el !== undefined) {
var kv=el.split("=");
if (kv[1] !== null & kv[1] !== undefined) {
var v=kv[1].replace(/\+/g,"%20");
qso[kv[0]]=decodeURIComponent(v);
}
}
});
}
return qso;
},
s4tDetected : function() {
let rv="No";
if (this.gs1dlURI2decode.slice(-4) == "&s4t") {
rv="Yes";
}
return rv;
},
primaryValueExtracted : function() {
let pathInfo="";
let rv={};
let c={"00":"SSCC","402":"GSIN","401":"GINC"};
let digits=new RegExp("^\\d+$");
if (this.gs1dlURI2decode !== undefined && this.gs1dlURI2decode !== null && this.gs1dlURI2decode !== "") {
var inq = this.gs1dlURI2decode.indexOf("?");
if (inq== -1) {
pathInfo = this.gs1dlURI2decode;
} else {
pathInfo = this.gs1dlURI2decode.substr(0,this.gs1dlURI2decode.indexOf("?"));
}
var rePath=new RegExp("\\/(sscc|00|gsin|402|ginc|401)\\/(\\d{4}.+?)$");
if (rePath.test(pathInfo)) {
let code=pathInfo.match(rePath)[1].toUpperCase();
if (digits.test(code)) {
code=c[code];
}
rv.code=code;
rv.value=pathInfo.match(rePath)[2];
} else {
rv.code="";
rv.value="";
}
}
return rv;
},
uriStemExtracted: function() {
var uriStem="";
if (this.gs1dlURI2decode !== undefined && this.gs1dlURI2decode !== null && this.gs1dlURI2decode !== "") {
var inq = this.gs1dlURI2decode.indexOf("?");
if (inq== -1) {
pathInfo = this.gs1dlURI2decode;
} else {
pathInfo = this.gs1dlURI2decode.substr(0,this.gs1dlURI2decode.indexOf("?"));
}
var rePath=new RegExp("\\/(sscc|00|gsin|402|ginc|401)\\/(\\d{4}.+?)$");
if (rePath.test(pathInfo)) {
let l=pathInfo.match(rePath)[0].length;
uriStem = pathInfo.substr(0,pathInfo.length-l);
}
}
return uriStem;
},
queryString: function() {
s4to=JSON.parse(this.s4tDataJSON);
kvPairs=[];
s4tObj.orderedKeys.forEach(function(k) {
if ((s4to.hasOwnProperty(k)) && (s4to[k] !== "")) {
var valToEncode=encodeURIComponent(s4to[k]);
if (this.s4tObj.obj[k].datatype=="xsd:date") {
valToEncode=gs1date(s4to[k]);
}
if (this.s4tObj.obj[k].datatype=="gs1:Measurement") {
var rv=gs1measurement(s4to[k]);
valToEncode = rv.sixdigit;
k=k.replace("n",rv.ndp);
}
kvPairs.push(k+"="+valToEncode);
}
});
return kvPairs.join("&");
},
gs1dlURI: function() {
var uriStem=this.uriStem.replace(/\/$/,"");
var qs=this.queryString.replace(/\%20/g,"+");
var dl = "";
if (this.primaryValue !== "") {
dl = uriStem+"/"+this.primaryAIobj.code+"/"+this.primaryValue;
if (qs !== "") {
dl+="?"+qs;
}
}
this.generateQR(dl);
this.gs1dlURI2decode = dl;
return dl;
}
},
methods : {
clearURI : function() {
this.gs1dlURI2decode="";
},
toggle : function(e) {
this.t=e;
},
toggleURI : function() {
this.u=1-this.u;
},
toggleVideo : function() {
this.v=1-this.v;
},
gs1ToMeasurement: function(queryStringExtracted,code) {
var rv={};
this.zeroToFive.forEach(function(el) {
var tempCode=code.replace("n",el);
if (queryStringExtracted.hasOwnProperty(tempCode)) {
rv.value=queryStringExtracted[tempCode]/Math.pow(10,parseInt(el));
rv.code=tempCode;
}
});
return rv;
},
gs1date3: function(gs1Date) {
var rv="";
var regexDate= new RegExp("^\\d{6}$");
if (gs1Date !== undefined && regexDate.test(gs1Date)) {
var doubleDigits = gs1Date.split(/(\d{2})/);
// TODO determine this correctly based on whether >=51 - see Gen Specs
var year=parseInt(doubleDigits[1]);
var currentYear=new Date().getFullYear().toString();
var currentLastYY=parseInt(currentYear.substr(-2));
var currentFirstYY=parseInt(currentYear.substr(0,2));
var diff=year-currentLastYY;
var fullyear=currentFirstYY.toString()+year.toString();
if (diff >=51 && diff <= 99) {
fullyear=(currentFirstYY-1).toString()+year.toString();
}
if (diff >= -99 && diff <= -50) {
fullyear=(currentFirstYY+1).toString()+year.toString();
}
if (fullyear !== undefined) {
rv=doubleDigits[5]+"/"+doubleDigits[3]+"/"+fullyear;
}
}
return rv;
},
gs1date4: function(gs1Date) {
var rv="";
var regexDate= new RegExp("^\\d{6}|\\d{8}|\\d{10}$");
if (gs1Date !== undefined && regexDate.test(gs1Date)) {
var doubleDigits = gs1Date.split(/(\d{2})/);
// TODO determine this correctly based on whether >=51 - see Gen Specs
var year=parseInt(doubleDigits[1]);
var currentYear=new Date().getFullYear().toString();
var currentLastYY=parseInt(currentYear.substr(-2));
var currentFirstYY=parseInt(currentYear.substr(0,2));
var diff=year-currentLastYY;
var fullyear=currentFirstYY.toString()+year.toString();
if (diff >=51 && diff <= 99) {
fullyear=(currentFirstYY-1).toString()+year.toString();
}
if (diff >= -99 && diff <= -50) {
fullyear=(currentFirstYY+1).toString()+year.toString();
}
var hour="00";
var min="00";
if (gs1Date.length > 6) {
hour=doubleDigits[7];
}
if (gs1Date.length > 8) {
min=doubleDigits[9];
}
if (fullyear !== undefined) {
rv=doubleDigits[5]+"/"+doubleDigits[3]+"/"+fullyear+" "+hour+":"+min;
}
}
return rv;
},
setMode: function(el) {
this.mode=el;
},
booleanValue: function(el) {
return this.booleans[el];
}
}
}).mount("#app1");
var video = document.createElement("video");
var canvasElement = document.getElementById("canvas");
var canvas = canvasElement.getContext("2d");
var loadingMessage = document.getElementById("loadingMessage");
var outputContainer = document.getElementById("output");
var outputMessage = document.getElementById("outputMessage");
var outputData = document.getElementById("outputData");
// Use facingMode: environment to attemt to get the front camera on phones
navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } }).then(function(stream) {
video.srcObject = stream;
video.setAttribute("playsinline", true); // required to tell iOS safari we don't want fullscreen
video.play();
requestAnimationFrame(tick);
});
function tick() {
loadingMessage.innerText = "⌛ Loading video..."
if (video.readyState === video.HAVE_ENOUGH_DATA) {
loadingMessage.hidden = true;
canvasElement.hidden = false;
outputContainer.hidden = false;
canvasElement.height = video.videoHeight;
canvasElement.width = video.videoWidth;
canvas.drawImage(video, 0, 0, canvasElement.width, canvasElement.height);
var imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
var code = jsQR(imageData.data, imageData.width, imageData.height, {
inversionAttempts: "dontInvert",
});
if (code) {
if (code.data !== "") {
app1.gs1dlURI2decode=code.data;
app1.v=0;
}
}
}
requestAnimationFrame(tick);
}
</script>
</body></html>