|
|
@@ -1,56 +1,115 @@
|
|
|
1
|
+var cargoResult = 0;
|
|
|
2
|
+var voyageResult= 0;
|
|
|
3
|
+var cargoJson = '';
|
|
|
4
|
+var voyageJson = '';
|
|
|
5
|
+
|
|
1
|
6
|
function search() {
|
|
2
|
|
- $('#result').empty();
|
|
3
|
7
|
if (!$("#query").val()) {
|
|
|
8
|
+ $('#result').empty();
|
|
4
|
9
|
return;
|
|
5
|
10
|
}
|
|
6
|
|
-
|
|
|
11
|
+
|
|
|
12
|
+ cargoResult = 0;
|
|
|
13
|
+ voyageResult= 0;
|
|
|
14
|
+ cargoJson = '';
|
|
|
15
|
+ voyageJson = '';
|
|
|
16
|
+
|
|
7
|
17
|
$.ajax({
|
|
8
|
18
|
url: 'http://localhost:8080/reporting/rest/cargo/' + $("#query").val() + '.json',
|
|
9
|
19
|
type: 'GET',
|
|
10
|
20
|
contentType: 'application/json',
|
|
11
|
|
- success: function(response) {
|
|
12
|
|
- var json = eval('(' + response + ')');
|
|
13
|
|
- var cargo = json.cargoReport.cargo;
|
|
14
|
|
- var pdfUrl = 'http://localhost:8080/reporting/rest/cargo/' + $("#query").val() + '.pdf';
|
|
15
|
|
- $('#result').append('<h2>Cargo: ' + cargo.trackingId + '</h2>').append('<table>');
|
|
16
|
|
-
|
|
17
|
|
- if (cargo.currentLocation) {
|
|
18
|
|
- $('#result').append('<tr><td>Status</td><td>' + cargo.currentStatus + ' ' + cargo.currentLocation + '</td></tr>');
|
|
19
|
|
- } else if (cargo.currentVoyage) {
|
|
20
|
|
- $('#result').append('<tr><td>Status</td><td>' + cargo.currentStatus + ' ' + cargo.currentVoyage + '</td></tr>');
|
|
21
|
|
- }
|
|
22
|
|
-
|
|
23
|
|
- $('#result').
|
|
24
|
|
- append('<tr><td>Destination</td><td>' + cargo.finalDestination + ' by ' + cargo.arrivalDeadline + '</td></tr>').
|
|
25
|
|
- append('<tr><td>ETA</td><td>' + cargo.eta + '</td></tr>');
|
|
26
|
|
-
|
|
27
|
|
-
|
|
28
|
|
- $('#result').
|
|
29
|
|
- append('<tr><td>Updated on</td><td>' + cargo.lastUpdatedOn + '</td></tr>').
|
|
30
|
|
- append('</table>');
|
|
31
|
|
-
|
|
32
|
|
- $('#result').append(json.cargoReport.misdirected);
|
|
33
|
|
-
|
|
34
|
|
- $('#result').
|
|
35
|
|
- append('<h2>Handling history</h2>');
|
|
36
|
|
- for (i in json.cargoReport.handlings) {
|
|
37
|
|
- var handling = json.cargoReport.handlings[i];
|
|
38
|
|
- $('#result').
|
|
39
|
|
- append('<tr>').
|
|
40
|
|
- append('<td>' + handling.completedOn + '</td>').
|
|
41
|
|
- append('<td>' + handling.type + '</td>').
|
|
42
|
|
- append('<td>' + handling.voyage + '</td>').
|
|
43
|
|
- append('<td>' + handling.location + '</td>').
|
|
44
|
|
- append('</tr>');
|
|
45
|
|
- }
|
|
46
|
|
- $('#result').
|
|
47
|
|
- append('</table>').
|
|
48
|
|
- append('<p><a href="' + pdfUrl + '">Download as PDF</a></p>');
|
|
49
|
|
- },
|
|
50
|
|
- error: function(response) {
|
|
51
|
|
- if (response.status == 404) {
|
|
52
|
|
- $('#result').append('<p>No cargo found with tracking ID ' + $("#query").val() + '</p>');
|
|
53
|
|
- }
|
|
54
|
|
- }
|
|
|
21
|
+ success: function(response) { cargoResult = 1; cargoJson = eval('(' + response + ')'); present(response); },
|
|
|
22
|
+ error: function(response) { cargoResult = 2; present(response); }
|
|
55
|
23
|
});
|
|
|
24
|
+
|
|
|
25
|
+ $.ajax({
|
|
|
26
|
+ url: 'http://localhost:8080/reporting/rest/voyage/' + $("#query").val() + '.json',
|
|
|
27
|
+ type: 'GET',
|
|
|
28
|
+ contentType: 'application/json',
|
|
|
29
|
+ success: function(response) { voyageResult = 1; voyageJson = eval('(' + response + ')'); present(response); },
|
|
|
30
|
+ error: function(response) { voyageResult = 2; present(response); }
|
|
|
31
|
+ });
|
|
|
32
|
+
|
|
|
33
|
+}
|
|
|
34
|
+
|
|
|
35
|
+function present(response) {
|
|
|
36
|
+ if (cargoResult == 1 && voyageResult > 0) {
|
|
|
37
|
+ presentCargo();
|
|
|
38
|
+ } else if (cargoResult == 2 && voyageResult == 1) {
|
|
|
39
|
+ presentVoyage();
|
|
|
40
|
+ } else if (cargoResult == 2 && voyageResult == 2) {
|
|
|
41
|
+ err(response);
|
|
|
42
|
+ } else {
|
|
|
43
|
+ // alert(cargoResult + ':' + voyageResult);
|
|
|
44
|
+ }
|
|
|
45
|
+}
|
|
|
46
|
+
|
|
|
47
|
+function presentCargo(response) {
|
|
|
48
|
+ var cargo = cargoJson.cargoReport.cargo;
|
|
|
49
|
+ var pdfUrl = 'http://localhost:8080/reporting/rest/cargo/' + $("#query").val() + '.pdf';
|
|
|
50
|
+ $('#result').empty();
|
|
|
51
|
+ $('#result').append('<h2>Cargo: ' + cargo.trackingId + '</h2>').append('<table>');
|
|
|
52
|
+
|
|
|
53
|
+ if (cargo.currentLocation) {
|
|
|
54
|
+ $('#result').append('<tr><td>Status</td><td>' + cargo.currentStatus + ' ' + cargo.currentLocation + '</td></tr>');
|
|
|
55
|
+ } else if (cargo.currentVoyage) {
|
|
|
56
|
+ $('#result').append('<tr><td>Status</td><td>' + cargo.currentStatus + ' ' + cargo.currentVoyage + '</td></tr>');
|
|
|
57
|
+ }
|
|
|
58
|
+
|
|
|
59
|
+ $('#result').
|
|
|
60
|
+ append('<tr><td>Destination</td><td>' + cargo.finalDestination + ' by ' + cargo.arrivalDeadline + '</td></tr>').
|
|
|
61
|
+ append('<tr><td>ETA</td><td>' + cargo.eta + '</td></tr>');
|
|
|
62
|
+
|
|
|
63
|
+ $('#result').
|
|
|
64
|
+ append('<tr><td>Updated on</td><td>' + cargo.lastUpdatedOn + '</td></tr>').
|
|
|
65
|
+ append('</table>');
|
|
|
66
|
+
|
|
|
67
|
+ $('#result').append(cargoJson.cargoReport.misdirected);
|
|
|
68
|
+
|
|
|
69
|
+ $('#result').
|
|
|
70
|
+ append('<h2>Handling history</h2><table>');
|
|
|
71
|
+ for (i in cargoJson.cargoReport.handlings) {
|
|
|
72
|
+ var handling = cargoJson.cargoReport.handlings[i];
|
|
|
73
|
+ $('#result').
|
|
|
74
|
+ append('<tr>').
|
|
|
75
|
+ append('<td>' + handling.completedOn + '</td>').
|
|
|
76
|
+ append('<td>' + handling.type + '</td>').
|
|
|
77
|
+ append('<td>' + (handling.voyage ? handling.voyage : '') + '</td>').
|
|
|
78
|
+ append('<td>' + handling.location + '</td>').
|
|
|
79
|
+ append('</tr>');
|
|
|
80
|
+ }
|
|
|
81
|
+ $('#result').
|
|
|
82
|
+ append('</table>').
|
|
|
83
|
+ append('<p><a href="' + pdfUrl + '">Download as PDF</a></p>');
|
|
56
|
84
|
}
|
|
|
85
|
+
|
|
|
86
|
+function presentVoyage(response) {
|
|
|
87
|
+ var voyage = voyageJson.voyageReport.voyage;
|
|
|
88
|
+ var pdfUrl = 'http://localhost:8080/reporting/rest/voyage/' + $("#query").val() + '.pdf';
|
|
|
89
|
+
|
|
|
90
|
+ $('#result').empty();
|
|
|
91
|
+ $('#result').
|
|
|
92
|
+ append('<h2>Voyage: ' + voyage.voyageNumber + '</h2>').append('<table>').
|
|
|
93
|
+ append('<tr><td>Status</td><td>' + voyage.currentStatus + '</td></tr>').
|
|
|
94
|
+ append('<tr><td>Next stop</td><td>' + voyage.nextStop + ' at ' + voyage.etaNextStop + '</td></tr>').
|
|
|
95
|
+ append('<tr><td>Delay</td><td>' + voyage.delayedByMinutes + ' min</td></tr>').
|
|
|
96
|
+ append('<tr><td>Updated on</td><td>' + voyage.lastUpdatedOn + '</td></tr>').
|
|
|
97
|
+ append('</table>').
|
|
|
98
|
+ append('<h2>Onboard cargos</h2><table>');
|
|
|
99
|
+ for (i in voyageJson.voyageReport.onboardCargos) {
|
|
|
100
|
+ var cargo = voyageJson.voyageReport.onboardCargos[i];
|
|
|
101
|
+ $('#result').append('<tr><td>' + cargo.trackingId + '</td><td>' + cargo.finalDestination + '</td></tr>');
|
|
|
102
|
+ }
|
|
|
103
|
+ $('#result').
|
|
|
104
|
+ append('</table>').
|
|
|
105
|
+ append('<p><a href="' + pdfUrl + '">Download as PDF</a></p>');
|
|
|
106
|
+}
|
|
|
107
|
+
|
|
|
108
|
+function err(response) {
|
|
|
109
|
+ if (response.status == 404) {
|
|
|
110
|
+ if (cargoResult == 2 && voyageResult == 2) {
|
|
|
111
|
+ $('#result').empty();
|
|
|
112
|
+ $('#result').append('<p>No cargo or voyage found</p>');
|
|
|
113
|
+ }
|
|
|
114
|
+ }
|
|
|
115
|
+}
|