summaryrefslogtreecommitdiff
path: root/public/static/js/travelynx-actions.js
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-05-10 17:58:13 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-05-10 17:58:13 +0200
commitf6800c86683df31c3a2080ba2b0657a97315a980 (patch)
tree2a4035627195f608b1a8edbf92eb09512fe27266 /public/static/js/travelynx-actions.js
parent374da8718236a3a1ad624ffbd63813b9cc8fd9fb (diff)
javascript-based refresh of journey progress and countdown
Diffstat (limited to 'public/static/js/travelynx-actions.js')
-rw-r--r--public/static/js/travelynx-actions.js51
1 files changed, 45 insertions, 6 deletions
diff --git a/public/static/js/travelynx-actions.js b/public/static/js/travelynx-actions.js
index d3e2a7d..fd5df02 100644
--- a/public/static/js/travelynx-actions.js
+++ b/public/static/js/travelynx-actions.js
@@ -1,3 +1,21 @@
+var j_duration = 0;
+var j_arrival = 0;
+function upd_journey_data() {
+ $('.countdown').each(function() {
+ j_duration = $(this).data('duration');
+ j_arrival = $(this).data('arrival');
+ });
+}
+function upd_countdown() {
+ var now = Date.now() / 1000;
+ if (j_arrival > 0) {
+ if (j_arrival > now) {
+ $('.countdown').text('Ankunft in ' + Math.round((j_arrival - now)/60) + ' Minuten');
+ } else {
+ $('.countdown').text('Ziel erreicht');
+ }
+ }
+}
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>');
@@ -21,10 +39,11 @@ function tvly_update() {
$.get('/ajax/status_card.html', function(data) {
$('.statuscol').html(data);
tvly_reg_handlers();
- setTimeout(tvly_update, 20000);
+ upd_journey_data();
+ setTimeout(tvly_update, 40000);
}).fail(function() {
$('.sync-failed-marker').css('display', 'block');
- $('.countdown').html('&nbsp;');
+ upd_countdown();
setTimeout(tvly_update, 5000);
});
}
@@ -35,13 +54,29 @@ function tvly_update_public() {
});
$.get('/ajax/status/' + user_name + '.html', function(data) {
$('.publicstatuscol').html(data);
- setTimeout(tvly_update_public, 20000);
+ upd_journey_data();
+ setTimeout(tvly_update_public, 40000);
}).fail(function() {
$('.sync-failed-marker').css('display', 'block');
- $('.countdown').html('&nbsp;');
+ upd_countdown();
setTimeout(tvly_update_public, 5000);
});
}
+function tvly_journey_progress() {
+ var now = Date.now() / 1000;
+ var progress = 0;
+ if (j_duration > 0) {
+ progress = 1 - ((j_arrival - now) / j_duration);
+ if (progress < 0) {
+ progress = 0;
+ }
+ if (progress > 1) {
+ progress = 1;
+ }
+ $('.progress .determinate').css('width', (progress * 100) + '%');
+ setTimeout(tvly_journey_progress, 5000);
+ }
+}
function tvly_reg_handlers() {
$('.action-checkin').click(function() {
var link = $(this);
@@ -107,10 +142,14 @@ function tvly_reg_handlers() {
$(document).ready(function() {
tvly_reg_handlers();
if ($('.statuscol .autorefresh').length) {
- setTimeout(tvly_update, 20000);
+ upd_journey_data();
+ setTimeout(tvly_update, 40000);
+ setTimeout(tvly_journey_progress, 5000);
}
if ($('.publicstatuscol .autorefresh').length) {
- setTimeout(tvly_update_public, 20000);
+ upd_journey_data();
+ setTimeout(tvly_update_public, 40000);
+ setTimeout(tvly_journey_progress, 5000);
}
$('a[href]').click(function() {
$('nav .preloader-wrapper').addClass('active');