templates/stop.html

changeset 134
4ac0f2e2ec4e
parent 133
091a48867bae
child 136
27324a81beca
equal deleted inserted replaced
133:091a48867bae 134:4ac0f2e2ec4e
34 { 34 {
35 background-color: #585858; 35 background-color: #585858;
36 } 36 }
37 </style> 37 </style>
38 <script> 38 <script>
39 var getJSON = function(url, callback) { 39 var getJSON = function(url, callback)
40 {
40 var xhr = new XMLHttpRequest(); 41 var xhr = new XMLHttpRequest();
41 xhr.open('GET', url, true); 42 xhr.open('GET', url, true);
42 xhr.responseType = 'json'; 43 xhr.responseType = 'json';
43 xhr.onload = function() { 44 xhr.onload = function() {
44 var status = xhr.status; 45 var status = xhr.status;
47 } 48 }
48 }; 49 };
49 xhr.send(); 50 xhr.send();
50 }; 51 };
51 52
52 var getUuid = function(blockref, originaimeddeparturetime, data, callback) { 53 function timeConverter(UNIX_timestamp)
53 var xhr = new XMLHttpRequest(); 54 {
54 var url = "../find_halt/{{ref}}/" + blockref + "/" + originaimeddeparturetime.toString();
55 xhr.open('GET', url, true);
56 xhr.responseType = 'json';
57 xhr.onload = function() {
58 var status = xhr.status;
59 if (status === 200) {
60 callback(xhr.response['id'], data);
61 }
62 };
63 xhr.send();
64 };
65
66 function timeConverter(UNIX_timestamp){
67 var a = new Date(UNIX_timestamp * 1000); 55 var a = new Date(UNIX_timestamp * 1000);
68 var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; 56 var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
69 var year = a.getFullYear(); 57 var year = a.getFullYear();
70 var month = months[a.getMonth()]; 58 var month = months[a.getMonth()];
71 var date = a.getDate(); 59 var date = a.getDate();
74 var sec = a.getSeconds(); 62 var sec = a.getSeconds();
75 var time = hour + ':' + (min < 10 ? '0' : '') + min; 63 var time = hour + ':' + (min < 10 ? '0' : '') + min;
76 return time; 64 return time;
77 } 65 }
78 66
79 function updateTime(uuid, time) { 67 function epoch()
80 const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; 68 {
69 var d = new Date();
70 if (d.getHours() < 4)
71 d.setDate(d.getDate() - 1);
72 d.setHours(0);
73 d.setMinutes(0);
74 d.setSeconds(0);
75 return Math.floor(d.getTime() / 1000);
76 }
77
78 function primarykey(data)
79 {
80 var key = data['blockref'] + '-';
81 key += (data['originaimeddeparturetime'] - epoch()).toString() + '-';
82 key += data['visitnumber'];
83 return key;
84 }
85
86 function updateTime(key, time)
87 {
81 const d = new Date(); 88 const d = new Date();
82 const now = (d.getTime() + d.getTimezoneOffset()) / 1000; 89 const now = (d.getTime() + d.getTimezoneOffset()) / 1000;
83 row = document.getElementById(uuid); 90 row = document.getElementById(key);
84 timeCell = document.getElementById(uuid + '-time'); 91 timeCell = document.getElementById(key + '-time');
85 t0 = parseInt(document.getElementById(uuid + '-stamp').innerHTML); 92 t0 = parseInt(document.getElementById(key + '-stamp').innerHTML);
86 if (Math.abs(time - t0) > 90) { 93 if (Math.abs(time - t0) > 90)
94 {
87 oldTime = timeConverter(t0); 95 oldTime = timeConverter(t0);
88 newTime = timeConverter(time); 96 newTime = timeConverter(time);
89 timeCell.innerHTML = '<s style="color:gray">' + oldTime + '</s> ⟶ <b>' + newTime + '</b>'; 97 timeCell.innerHTML = '<s style="color:gray">' + oldTime + '</s> ⟶ <b>' + newTime + '</b>';
90 } 98 }
99
91 if (time + 15 > now) 100 if (time + 15 > now)
92 row.classList.remove('gone'); 101 row.classList.remove('gone');
93 else 102 else
94 row.classList.add('gone'); 103 row.classList.add('gone');
95 } 104 }
151 var arrayLength = data['result'].length; 160 var arrayLength = data['result'].length;
152 for (var i = 0; i < arrayLength; i++) { 161 for (var i = 0; i < arrayLength; i++) {
153 var blockref = data['result'][i]['blockref']; 162 var blockref = data['result'][i]['blockref'];
154 var originaimeddeparturetime = data['result'][i]['originaimeddeparturetime']; 163 var originaimeddeparturetime = data['result'][i]['originaimeddeparturetime'];
155 var expecteddeparturetime = data['result'][i]['expecteddeparturetime']; 164 var expecteddeparturetime = data['result'][i]['expecteddeparturetime'];
156 getUuid(blockref, originaimeddeparturetime, expecteddeparturetime, function(id, expecteddeparturetime) { 165 var key = primarykey(data['result'][i]);
157 updateTime(id, expecteddeparturetime); 166 updateTime(key, expecteddeparturetime);
158 });
159 } 167 }
160 }); 168 });
161 </script> 169 </script>
162 </body> 170 </body>
163 </html> 171 </html>

mercurial