summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-05-02 10:05:15 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-05-02 10:05:15 +0200
commit3de5de7db2b7eebe000c6534bfd020405921ccdc (patch)
treec57f9ea7cddbd99f21dd1a16760ddeabdc0079ce
parent1bf128936d1af615bcbbf6aeb6d6ce5ab8179975 (diff)
Finish public-facing exposed user status (opt-in)
-rwxr-xr-xlib/Travelynx.pm1
-rw-r--r--lib/Travelynx/Controller/Account.pm4
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm2
-rw-r--r--public/static/js/travelynx-actions.js25
-rw-r--r--public/static/js/travelynx-actions.min.js2
l---------public/static/v9 (renamed from public/static/v7)0
-rw-r--r--templates/_public_status_card.html.ep71
-rw-r--r--templates/account.html.ep9
-rw-r--r--templates/layouts/default.html.ep2
-rw-r--r--templates/privacy.html.ep2
-rw-r--r--templates/user_status.html.ep2
11 files changed, 71 insertions, 49 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 8760135..8e10896 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -1729,6 +1729,7 @@ sub startup {
$r->get('/register')->to('account#registration_form');
$r->get('/reg/:id/:token')->to('account#verify');
$r->get('/status/:name')->to('traveling#user_status');
+ $r->get('/ajax/status/:name')->to('traveling#public_status_card');
$r->post('/action')->to('traveling#log_action');
$r->post('/geolocation')->to('traveling#geolocation');
$r->post('/list_departures')->to('traveling#redirect_to_station');
diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm
index 44babfa..f7d3a75 100644
--- a/lib/Travelynx/Controller/Account.pm
+++ b/lib/Travelynx/Controller/Account.pm
@@ -222,12 +222,12 @@ sub privacy {
$public_level &= ~0x02;
}
$self->set_privacy( $user->{id}, $public_level );
+ $self->redirect_to('account');
}
else {
$self->param( public_status => $public_level & 0x02 ? 1 : 0 );
+ $self->render( 'privacy', name => $user->{name} );
}
-
- $self->render( 'privacy', name => $user->{name} );
}
sub change_mail {
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index cf704ec..ee94913 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -50,6 +50,8 @@ sub public_status_card {
my $name = $self->stash('name');
my $user = $self->get_privacy_by_name($name);
+ delete $self->stash->{layout};
+
if ( $user and ( $user->{public_level} & 0x02 ) ) {
my $status = $self->get_user_status( $user->{id} );
$self->render(
diff --git a/public/static/js/travelynx-actions.js b/public/static/js/travelynx-actions.js
index 015a35d..cb4f975 100644
--- a/public/static/js/travelynx-actions.js
+++ b/public/static/js/travelynx-actions.js
@@ -21,10 +21,23 @@ function tvly_update() {
$.get('/ajax/status_card.html', function(data) {
$('.statuscol').html(data);
tvly_reg_handlers();
- setTimeout(tvly_update, 15000);
+ setTimeout(tvly_update, 20000);
}).fail(function() {
$('.sync-failed-marker').css('display', 'block');
- setTimeout(tvly_update, 15000);
+ setTimeout(tvly_update, 20000);
+ });
+}
+function tvly_update_public() {
+ var user_name;
+ $('.publicstatuscol').each(function() {
+ user_name = $(this).data('user');
+ });
+ $.get('/ajax/status/' + user_name + '.html', function(data) {
+ $('.publicstatuscol').html(data);
+ setTimeout(tvly_update_public, 20000);
+ }).fail(function() {
+ $('.sync-failed-marker').css('display', 'block');
+ setTimeout(tvly_update_public, 20000);
});
}
function tvly_reg_handlers() {
@@ -92,6 +105,12 @@ function tvly_reg_handlers() {
$(document).ready(function() {
tvly_reg_handlers();
if ($('.statuscol .autorefresh').length) {
- setTimeout(tvly_update, 15000);
+ setTimeout(tvly_update, 20000);
+ }
+});
+$(document).ready(function() {
+ tvly_reg_handlers();
+ if ($('.publicstatuscol .autorefresh').length) {
+ setTimeout(tvly_update_public, 20000);
}
});
diff --git a/public/static/js/travelynx-actions.min.js b/public/static/js/travelynx-actions.min.js
index 7bf9922..1276162 100644
--- a/public/static/js/travelynx-actions.min.js
+++ b/public/static/js/travelynx-actions.min.js
@@ -1 +1 @@
-function tvly_run(t,a,e){var n='<i class="material-icons">error</i>',c=$('<div class="progress"><div class="indeterminate"></div></div>');t.hide(),t.after(c),$.post("/action",a,function(a){a.success?$(location).attr("href",a.redirect_to):(M.toast({html:n+" "+a.error}),c.remove(),e&&e(),t.append(" "+n),t.show())})}function tvly_update(){$.get("/ajax/status_card.html",function(t){$(".statuscol").html(t),tvly_reg_handlers(),setTimeout(tvly_update,15e3)}).fail(function(){$(".sync-failed-marker").css("display","block"),setTimeout(tvly_update,15e3)})}function tvly_reg_handlers(){$(".action-checkin").click(function(){var t=$(this);tvly_run(t,{action:"checkin",station:t.data("station"),train:t.data("train")})}),$(".action-checkout").click(function(){var t=$(this),a={action:"checkout",station:t.data("station"),force:t.data("force")};tvly_run(t,a,function(){t.append(" – Ohne Echtzeitdaten auschecken?"),t.data("force",!0)})}),$(".action-undo").click(function(){var t=$(this);tvly_run(t,{action:"undo",undo_id:t.data("id")})}),$(".action-cancelled-from").click(function(){var t=$(this);tvly_run(t,{action:"cancelled_from",station:t.data("station"),train:t.data("train")})}),$(".action-cancelled-to").click(function(){var t=$(this);tvly_run(t,{action:"cancelled_to",station:t.data("station"),force:!0})}),$(".action-delete").click(function(){var t=$(this),a={action:"delete",id:t.data("id"),checkin:t.data("checkin"),checkout:t.data("checkout")};really_delete=confirm("Diese Zugfahrt wirklich löschen? Der Eintrag wird sofort aus der Datenbank entfernt und kann nicht wiederhergestellt werden."),really_delete&&tvly_run(t,a)})}$(document).ready(function(){tvly_reg_handlers(),$(".statuscol .autorefresh").length&&setTimeout(tvly_update,15e3)});
+function tvly_run(t,e,a){var n='<i class="material-icons">error</i>',c=$('<div class="progress"><div class="indeterminate"></div></div>');t.hide(),t.after(c),$.post("/action",e,function(e){e.success?$(location).attr("href",e.redirect_to):(M.toast({html:n+" "+e.error}),c.remove(),a&&a(),t.append(" "+n),t.show())})}function tvly_update(){$.get("/ajax/status_card.html",function(t){$(".statuscol").html(t),tvly_reg_handlers(),setTimeout(tvly_update,2e4)}).fail(function(){$(".sync-failed-marker").css("display","block"),setTimeout(tvly_update,2e4)})}function tvly_update_public(){var t;$(".publicstatuscol").each(function(){t=$(this).data("user")}),$.get("/ajax/status/"+t+".html",function(t){$(".publicstatuscol").html(t),setTimeout(tvly_update_public,2e4)}).fail(function(){$(".sync-failed-marker").css("display","block"),setTimeout(tvly_update_public,2e4)})}function tvly_reg_handlers(){$(".action-checkin").click(function(){var t=$(this);tvly_run(t,{action:"checkin",station:t.data("station"),train:t.data("train")})}),$(".action-checkout").click(function(){var t=$(this),e={action:"checkout",station:t.data("station"),force:t.data("force")};tvly_run(t,e,function(){t.append(" – Ohne Echtzeitdaten auschecken?"),t.data("force",!0)})}),$(".action-undo").click(function(){var t=$(this);tvly_run(t,{action:"undo",undo_id:t.data("id")})}),$(".action-cancelled-from").click(function(){var t=$(this);tvly_run(t,{action:"cancelled_from",station:t.data("station"),train:t.data("train")})}),$(".action-cancelled-to").click(function(){var t=$(this);tvly_run(t,{action:"cancelled_to",station:t.data("station"),force:!0})}),$(".action-delete").click(function(){var t=$(this),e={action:"delete",id:t.data("id"),checkin:t.data("checkin"),checkout:t.data("checkout")};really_delete=confirm("Diese Zugfahrt wirklich löschen? Der Eintrag wird sofort aus der Datenbank entfernt und kann nicht wiederhergestellt werden."),really_delete&&tvly_run(t,e)})}$(document).ready(function(){tvly_reg_handlers(),$(".statuscol .autorefresh").length&&setTimeout(tvly_update,2e4)}),$(document).ready(function(){tvly_reg_handlers(),$(".publicstatuscol .autorefresh").length&&setTimeout(tvly_update_public,2e4)});
diff --git a/public/static/v7 b/public/static/v9
index 945c9b4..945c9b4 120000
--- a/public/static/v7
+++ b/public/static/v9
diff --git a/templates/_public_status_card.html.ep b/templates/_public_status_card.html.ep
index 1b33c18..e357015 100644
--- a/templates/_public_status_card.html.ep
+++ b/templates/_public_status_card.html.ep
@@ -1,37 +1,11 @@
% if ($journey->{checked_in}) {
- <div class="card green darken-4">
- <div class="card-content white-text">
+ <div class="card white autorefresh">
+ <div class="card-content">
+ <i class="material-icons small right sync-failed-marker grey-text" style="display: none;">sync_problem</i>
<span class="card-title"><%= $name %> ist unterwegs</span>
<p>
- In <b><%= $journey->{train_type} %> <%= $journey->{train_no} %></b>
- % if ($journey->{arr_name}) {
- von <b><%= $journey->{dep_name} %></b> nach <b><%= $journey->{arr_name} %></b>.
- % }
- % else {
- ab <b><%= $journey->{dep_name} %></b>.
- % }
- </p>
- <p>
- <b><%= $journey->{real_departure}->strftime('%H:%M') %></b>
- % if ($journey->{real_departure}->epoch != $journey->{sched_departure}->epoch) {
- (<%= sprintf('%+d', ($journey->{real_departure}->epoch - $journey->{sched_departure}->epoch)/60) %>)
- % }
- →
- % if ($journey->{real_arrival}->epoch) {
- <b><%= $journey->{real_arrival}->strftime('%H:%M') %></b>
- % if ($journey->{real_arrival}->epoch != $journey->{sched_arrival}->epoch) {
- (<%= sprintf('%+d', ($journey->{real_arrival}->epoch - $journey->{sched_arrival}->epoch)/60) %>)
- % }
- % }
- % elsif ($journey->{arr_name}) {
- noch nicht bekannt
- % }
- % else {
- unbekannt
- % }
- </p>
- <p>
- <div class="center">
+ <div class="center-align">
+ <b><%= $journey->{train_type} %> <%= $journey->{train_no} %></b><br/>
% if ($journey->{departure_countdown} > 120) {
Abfahrt in <%= sprintf('%.f', $journey->{departure_countdown} / 60) %> Minuten
% }
@@ -57,8 +31,36 @@
Ankunft in mehr als zwei Stunden
% }
</div>
- <div class="progress green darken-3" style="height: 1ex;">
- <div class="determinate white" style="width: <%= sprintf('%.2f', 100 * ($journey->{journey_completion} // 0)); %>%;"></div>
+ <div class="progress grey lighten-3" style="height: 1ex;">
+ <div class="determinate blue" style="width: <%= sprintf('%.2f', 100 * ($journey->{journey_completion} // 0)); %>%;"></div>
+ </div>
+ </p>
+ <p>
+ <div style="float: left;">
+ <b><%= $journey->{dep_name} %></b><br/>
+ <b><%= $journey->{real_departure}->strftime('%H:%M') %></b>
+ % if ($journey->{real_departure}->epoch != $journey->{sched_departure}->epoch) {
+ (<%= sprintf('%+d', ($journey->{real_departure}->epoch - $journey->{sched_departure}->epoch)/60) %>)
+ % }
+ </div>
+ <div style="float: right;">
+ % if ($journey->{arr_name}) {
+ <b><%= $journey->{arr_name} %></b><br/>
+ % }
+ % else {
+ Fahrt ins Blaue<br/>
+ % }
+ % if ($journey->{real_arrival}->epoch) {
+ <b><%= $journey->{real_arrival}->strftime('%H:%M') %></b>
+ % if ($journey->{real_arrival}->epoch != $journey->{sched_arrival}->epoch) {
+ (<%= sprintf('%+d', ($journey->{real_arrival}->epoch - $journey->{sched_arrival}->epoch)/60) %>)
+ % }
+ % }
+ % elsif ($journey->{arr_name}) {
+ noch nicht bekannt
+ % }
+ </div>
+ <div style="clear: both;">
</div>
</p>
% if (@{$journey->{messages} // []} > 0 and $journey->{messages}[0]) {
@@ -76,8 +78,9 @@
</div>
% }
% else {
- <div class="card grey darken-4">
+ <div class="card grey darken-4 autorefresh">
<div class="card-content white-text">
+ <i class="material-icons small right sync-failed-marker grey-text" style="display: none;">sync_problem</i>
<span class="card-title"><%= $name %> ist gerade nicht eingecheckt</span>
<p>
Zuletzt gesehen in <%= $journey->{arr_name} %>.
diff --git a/templates/account.html.ep b/templates/account.html.ep
index fe1280f..fc4387d 100644
--- a/templates/account.html.ep
+++ b/templates/account.html.ep
@@ -37,17 +37,14 @@
<td><a href="/change_password"><i class="material-icons">edit</i></a></td>
</tr>
<tr>
- <th scope="row">Privatsphäre</th>
+ <th scope="row">Öffentliche Daten</th>
<td>
<a href="/account/privacy"><i class="material-icons">edit</i></a>
% if ($acc->{is_public} == 0) {
- Keine öffentlichen Daten
- % }
- % else {
- Öffentliche Daten:
+ Keine
% }
% if ($acc->{is_public} & 0x02) {
- Status
+ Aktueller Status
% }
</td>
</tr>
diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep
index 9dfd741..d80ac3d 100644
--- a/templates/layouts/default.html.ep
+++ b/templates/layouts/default.html.ep
@@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#673ab7">
- % my $av = 'v8'; # asset version
+ % my $av = 'v9'; # asset version
%= stylesheet "/static/${av}/css/materialize.min.css"
%= stylesheet "/static/${av}/css/material-icons.css"
%= stylesheet "/static/${av}/css/local.css"
diff --git a/templates/privacy.html.ep b/templates/privacy.html.ep
index bf509ce..9fa2048 100644
--- a/templates/privacy.html.ep
+++ b/templates/privacy.html.ep
@@ -1,4 +1,4 @@
-<h1>Privatsphäre</h1>
+<h1>Öffentliche Daten</h1>
<div class="row">
<div class="col s12">
Hier kannst du auswählen, welche Aspekte deines Accounts bzw. deiner
diff --git a/templates/user_status.html.ep b/templates/user_status.html.ep
index 7691258..2a6be03 100644
--- a/templates/user_status.html.ep
+++ b/templates/user_status.html.ep
@@ -1,5 +1,5 @@
<div class="row">
- <div class="col s12">
+ <div class="col s12 publicstatuscol" data-user="<%= $name %>">
%= include '_public_status_card', name => $name, journey => $journey
</div>
</div>