summaryrefslogtreecommitdiff
path: root/public/static/js/travelynx-actions.js
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-10-29 21:18:46 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-10-29 21:18:46 +0100
commit663b4dc6d89d21caa6b670d69780754b40910d90 (patch)
tree17571683194e5c26a036c69e0f2130280ec31457 /public/static/js/travelynx-actions.js
parentf13b4755c7db9df079c6fdb0d22679358a9585b9 (diff)
live update of next station via javascript
Diffstat (limited to 'public/static/js/travelynx-actions.js')
-rw-r--r--public/static/js/travelynx-actions.js68
1 files changed, 65 insertions, 3 deletions
diff --git a/public/static/js/travelynx-actions.js b/public/static/js/travelynx-actions.js
index 0df6989..92a0a58 100644
--- a/public/static/js/travelynx-actions.js
+++ b/public/static/js/travelynx-actions.js
@@ -1,14 +1,40 @@
+var j_departure = 0;
var j_duration = 0;
var j_arrival = 0;
+var j_dest = '';
+var j_stops = [];
function upd_journey_data() {
$('.countdown').each(function() {
- j_duration = $(this).data('duration');
- j_arrival = $(this).data('arrival');
+ var journey_data = $(this).data('journey');
+ if (journey_data) {
+ journey_data = journey_data.split(';');
+ j_departure = parseInt(journey_data[0]);
+ j_arrival = parseInt(journey_data[1]);
+ j_duration = j_arrival - j_departure;
+ }
+ var journey_dest = $(this).data('dest');
+ if (journey_dest) {
+ j_dest = journey_dest;
+ }
+ var stops = $(this).data('route');
+ if (stops) {
+ stops = stops.split('|');
+ j_stops = [];
+ for (var stop_id in stops) {
+ var stopdata = stops[stop_id].split(';');
+ for (var i = 1; i < 5; i++) {
+ stopdata[i] = parseInt(stopdata[i]);
+ }
+ j_stops.push(stopdata);
+ }
+ }
});
}
function upd_countdown() {
var now = Date.now() / 1000;
- if (j_arrival > 0) {
+ if (j_departure > now) {
+ $('.countdown').text('Abfahrt in ' + Math.round((j_departure - now)/60) + ' Minuten');
+ } else if (j_arrival > 0) {
if (j_arrival > now) {
$('.countdown').text('Ankunft in ' + Math.round((j_arrival - now)/60) + ' Minuten');
} else {
@@ -16,6 +42,22 @@ function upd_countdown() {
}
}
}
+function hhmm(epoch) {
+ var date = new Date(epoch * 1000);
+ var h = date.getHours();
+ var m = date.getMinutes();
+ return (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m);
+}
+function odelay(sched, rt) {
+ if (sched < rt) {
+ return ' (+' + ((rt - sched) / 60) + ')';
+ }
+ else if (sched == rt) {
+ return '';
+ }
+ return ' (' + ((rt - sched) / 60) + ')';
+}
+
function tvly_run(link, req, err_callback) {
var error_icon = '<i class="material-icons">error</i>';
var progressbar = $('<div class="progress"><div class="indeterminate"></div></div>');
@@ -74,6 +116,26 @@ function tvly_journey_progress() {
progress = 1;
}
$('.progress .determinate').css('width', (progress * 100) + '%');
+
+ for (stop in j_stops) {
+ var stop_name = j_stops[stop][0];
+ var sched_arr = j_stops[stop][1];
+ var rt_arr = j_stops[stop][2];
+ var sched_dep = j_stops[stop][3];
+ var rt_dep = j_stops[stop][4];
+ if (stop_name == j_dest) {
+ $('.next-stop').html('');
+ break;
+ }
+ if ((rt_arr != 0) && (rt_arr - now > 0)) {
+ $('.next-stop').html(stop_name + '<br/>' + hhmm(rt_arr) + odelay(sched_arr, rt_arr));
+ break;
+ }
+ if ((rt_dep != 0) && (rt_dep - now > 0)) {
+ $('.next-stop').html(stop_name + '<br/>' + hhmm(rt_arr) + ' → ' + hhmm(rt_dep) + odelay(sched_dep, rt_dep));
+ break;
+ }
+ }
setTimeout(tvly_journey_progress, 5000);
}
}