Finish public-facing exposed user status (opt-in)

This commit is contained in:
Daniel Friesel 2019-05-02 10:05:15 +02:00
parent 1bf128936d
commit 3de5de7db2
11 changed files with 71 additions and 49 deletions

View file

@ -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');

View file

@ -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} );
}
}
sub change_mail {

View file

@ -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(

View file

@ -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);
}
});

View file

@ -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)});

View file

@ -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} %>.

View file

@ -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>

View file

@ -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"

View file

@ -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

View file

@ -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>