allow showing past journeys on shared status page
This commit is contained in:
parent
2652ea6bab
commit
57f686b688
5 changed files with 143 additions and 88 deletions
|
@ -33,53 +33,98 @@ sub user_status {
|
|||
my ($self) = @_;
|
||||
|
||||
my $name = $self->stash('name');
|
||||
my $ts = $self->stash('ts');
|
||||
my $ts = $self->stash('ts') // 0;
|
||||
my $user = $self->get_privacy_by_name($name);
|
||||
|
||||
if ( not $user or not $user->{public_level} & 0x03 ) {
|
||||
$self->render('not_found');
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $user->{public_level} & 0x01 and not $self->is_user_authenticated ) {
|
||||
$self->render( 'login', redirect_to => $self->req->url );
|
||||
return;
|
||||
}
|
||||
|
||||
my $status = $self->get_user_status( $user->{id} );
|
||||
my $journey;
|
||||
|
||||
if (
|
||||
$user
|
||||
and ( $user->{public_level} & 0x02
|
||||
$ts
|
||||
and ( not $status->{checked_in}
|
||||
or $status->{sched_departure}->epoch != $ts )
|
||||
and ( $user->{public_level} & 0x20
|
||||
or
|
||||
( $user->{public_level} & 0x01 and $self->is_user_authenticated ) )
|
||||
( $user->{public_level} & 0x10 and $self->is_user_authenticated ) )
|
||||
)
|
||||
{
|
||||
my $status = $self->get_user_status( $user->{id} );
|
||||
|
||||
my %tw_data = (
|
||||
card => 'summary',
|
||||
site => '@derfnull',
|
||||
image => $self->url_for('/static/icons/icon-512x512.png')
|
||||
->to_abs->scheme('https'),
|
||||
);
|
||||
|
||||
if (
|
||||
$ts
|
||||
and ( not $status->{checked_in}
|
||||
or $status->{sched_departure}->epoch != $ts )
|
||||
for my $candidate (
|
||||
$self->get_user_travels(
|
||||
uid => $user->{id},
|
||||
limit => 10,
|
||||
verbose => 1,
|
||||
with_datetime => 1
|
||||
)
|
||||
)
|
||||
{
|
||||
$tw_data{title} = "Bahnfahrt beendet";
|
||||
$tw_data{description} = "${name} hat das Ziel erreicht";
|
||||
}
|
||||
elsif ( $status->{checked_in} ) {
|
||||
$tw_data{title} = "${name} ist unterwegs";
|
||||
$tw_data{description} = sprintf(
|
||||
'%s %s von %s nach %s',
|
||||
$status->{train_type},
|
||||
$status->{train_line} // $status->{train_no},
|
||||
$status->{dep_name},
|
||||
$status->{arr_name} // 'irgendwo'
|
||||
);
|
||||
if ( $status->{real_arrival}->epoch ) {
|
||||
$tw_data{description} .= $status->{real_arrival}
|
||||
->strftime(' – Ankunft gegen %H:%M Uhr');
|
||||
if ( $candidate->{sched_departure}->epoch eq $ts ) {
|
||||
$journey = $candidate;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tw_data{title} = "${name} ist gerade nicht eingecheckt";
|
||||
$tw_data{description} = "Letztes Fahrtziel: $status->{arr_name}";
|
||||
}
|
||||
}
|
||||
|
||||
my %tw_data = (
|
||||
card => 'summary',
|
||||
site => '@derfnull',
|
||||
image => $self->url_for('/static/icons/icon-512x512.png')
|
||||
->to_abs->scheme('https'),
|
||||
);
|
||||
|
||||
if ($journey) {
|
||||
$tw_data{title} = sprintf( 'Fahrt von %s nach %s',
|
||||
$journey->{from_name}, $journey->{to_name} );
|
||||
$tw_data{description}
|
||||
= $journey->{rt_arrival}->strftime('Ankunft am %d.%m.%Y um %H:%M');
|
||||
}
|
||||
elsif (
|
||||
$ts
|
||||
and ( not $status->{checked_in}
|
||||
or $status->{sched_departure}->epoch != $ts )
|
||||
)
|
||||
{
|
||||
$tw_data{title} = "Bahnfahrt beendet";
|
||||
$tw_data{description} = "${name} hat das Ziel erreicht";
|
||||
}
|
||||
elsif ( $status->{checked_in} ) {
|
||||
$tw_data{title} = "${name} ist unterwegs";
|
||||
$tw_data{description} = sprintf(
|
||||
'%s %s von %s nach %s',
|
||||
$status->{train_type}, $status->{train_line} // $status->{train_no},
|
||||
$status->{dep_name}, $status->{arr_name} // 'irgendwo'
|
||||
);
|
||||
if ( $status->{real_arrival}->epoch ) {
|
||||
$tw_data{description} .= $status->{real_arrival}
|
||||
->strftime(' – Ankunft gegen %H:%M Uhr');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tw_data{title} = "${name} ist gerade nicht eingecheckt";
|
||||
$tw_data{description} = "Letztes Fahrtziel: $status->{arr_name}";
|
||||
}
|
||||
|
||||
if ($journey) {
|
||||
if ( not $user->{public_level} & 0x04 ) {
|
||||
delete $journey->{user_data}{comment};
|
||||
}
|
||||
$self->render(
|
||||
'journey',
|
||||
error => undef,
|
||||
readonly => 1,
|
||||
journey => $journey,
|
||||
twitter => \%tw_data,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$self->render(
|
||||
'user_status',
|
||||
name => $name,
|
||||
|
@ -88,12 +133,6 @@ sub user_status {
|
|||
twitter => \%tw_data,
|
||||
);
|
||||
}
|
||||
elsif ( $user->{public_level} & 0x01 ) {
|
||||
$self->render( 'login', redirect_to => $self->req->url );
|
||||
}
|
||||
else {
|
||||
$self->render('not_found');
|
||||
}
|
||||
}
|
||||
|
||||
sub public_status_card {
|
||||
|
|
|
@ -164,13 +164,14 @@
|
|||
<p>
|
||||
% if ($journey->{arr_name}) {
|
||||
Zuletzt gesehen
|
||||
% if ($public_level & 0x30 and $journey->{real_arrival}->epoch) {
|
||||
% if ($journey->{real_arrival}->epoch and ($public_level & 0x20 or ($public_level & 0x10 and is_user_authenticated()))) {
|
||||
%= $journey->{real_arrival}->strftime('am %d.%m.%Y')
|
||||
% }
|
||||
in <b><%= $journey->{arr_name} %></b>
|
||||
% if ($public_level & 0x30 and $journey->{real_arrival}->epoch) {
|
||||
in <b><%= $journey->{arr_name} %></b>
|
||||
%= $journey->{real_arrival}->strftime('(Ankunft um %H:%M Uhr)')
|
||||
% }
|
||||
% else {
|
||||
in <b><%= $journey->{arr_name} %></b>
|
||||
% }
|
||||
% }
|
||||
% else {
|
||||
Noch keine Zugfahrten geloggt.
|
||||
|
|
|
@ -75,6 +75,15 @@
|
|||
% if ($acc->{is_public} & 0x04) {
|
||||
mit Kommentar
|
||||
% }
|
||||
% if ($acc->{is_public} & 0x0f and $acc->{is_public} & 0xf0) {
|
||||
<br/>
|
||||
% }
|
||||
% if ($acc->{is_public} & 0x10) {
|
||||
Letzte zehn Fahrten (nur für angemeldete Accounts)
|
||||
% }
|
||||
% elsif ($acc->{is_public} & 0x20) {
|
||||
Letzte zehn Fahrten
|
||||
% }
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
@ -223,44 +223,46 @@
|
|||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row hide-on-small-only">
|
||||
<div class="col s12 m6 l6 center-align">
|
||||
<a class="waves-effect waves-light red btn action-delete"
|
||||
data-id="<%= $journey->{id} %>"
|
||||
data-checkin="<%= $journey->{checkin}->epoch %>"
|
||||
data-checkout="<%= $journey->{checkout}->epoch %>">
|
||||
<i class="material-icons left">delete_forever</i>
|
||||
Löschen
|
||||
</a>
|
||||
% if (not stash('readonly')) {
|
||||
<div class="row hide-on-small-only">
|
||||
<div class="col s12 m6 l6 center-align">
|
||||
<a class="waves-effect waves-light red btn action-delete"
|
||||
data-id="<%= $journey->{id} %>"
|
||||
data-checkin="<%= $journey->{checkin}->epoch %>"
|
||||
data-checkout="<%= $journey->{checkout}->epoch %>">
|
||||
<i class="material-icons left">delete_forever</i>
|
||||
Löschen
|
||||
</a>
|
||||
</div>
|
||||
<div class="col s12 m6 l6 center-align">
|
||||
%= form_for '/journey/edit' => (method => 'POST') => begin
|
||||
%= hidden_field 'journey_id' => param('journey_id')
|
||||
<button class="btn waves-effect waves-light" type="submit" name="action" value="edit">
|
||||
<i class="material-icons left" aria-hidden="true">edit</i>
|
||||
Bearbeiten
|
||||
</button>
|
||||
%= end
|
||||
</div>
|
||||
</div>
|
||||
<div class="col s12 m6 l6 center-align">
|
||||
%= form_for '/journey/edit' => (method => 'POST') => begin
|
||||
%= hidden_field 'journey_id' => param('journey_id')
|
||||
<button class="btn waves-effect waves-light" type="submit" name="action" value="edit">
|
||||
<i class="material-icons left" aria-hidden="true">edit</i>
|
||||
Bearbeiten
|
||||
</button>
|
||||
%= end
|
||||
<div class="row hide-on-med-and-up">
|
||||
<div class="col s12 m6 l6 center-align">
|
||||
%= form_for '/journey/edit' => (method => 'POST') => begin
|
||||
%= hidden_field 'journey_id' => param('journey_id')
|
||||
<button class="btn waves-effect waves-light" type="submit" name="action" value="edit">
|
||||
<i class="material-icons left" aria-hidden="true">edit</i>
|
||||
Bearbeiten
|
||||
</button>
|
||||
%= end
|
||||
</div>
|
||||
<div class="col s12 m6 l6 center-align" style="margin-top: 1em;">
|
||||
<a class="waves-effect waves-light red btn action-delete"
|
||||
data-id="<%= $journey->{id} %>"
|
||||
data-checkin="<%= $journey->{checkin}->epoch %>"
|
||||
data-checkout="<%= $journey->{checkout}->epoch %>">
|
||||
<i class="material-icons left" aria-hidden="true">delete_forever</i>
|
||||
Löschen
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row hide-on-med-and-up">
|
||||
<div class="col s12 m6 l6 center-align">
|
||||
%= form_for '/journey/edit' => (method => 'POST') => begin
|
||||
%= hidden_field 'journey_id' => param('journey_id')
|
||||
<button class="btn waves-effect waves-light" type="submit" name="action" value="edit">
|
||||
<i class="material-icons left" aria-hidden="true">edit</i>
|
||||
Bearbeiten
|
||||
</button>
|
||||
%= end
|
||||
</div>
|
||||
<div class="col s12 m6 l6 center-align" style="margin-top: 1em;">
|
||||
<a class="waves-effect waves-light red btn action-delete"
|
||||
data-id="<%= $journey->{id} %>"
|
||||
data-checkin="<%= $journey->{checkin}->epoch %>"
|
||||
data-checkout="<%= $journey->{checkout}->epoch %>">
|
||||
<i class="material-icons left" aria-hidden="true">delete_forever</i>
|
||||
Löschen
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
% }
|
||||
% }
|
||||
|
|
|
@ -41,7 +41,8 @@
|
|||
Wenn du eingecheckt bist, werden dort Zug, Start- und Zielstation,
|
||||
Abfahrts- und Ankunftszeit gezeigt; andernfalls lediglich der
|
||||
Zielbahnhof der letzten Reise. Wann die letzte Reise beendet wurde,
|
||||
wird bewusst nicht angegeben.
|
||||
wird nur angegeben, wenn deine vergangenen Zugfahrten sichtbar sind
|
||||
(siehe unten).
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -89,9 +90,12 @@
|
|||
<div class="col s12">
|
||||
Diese Einstellung bestimmt die Sichtbarkeit deiner letzten
|
||||
zehn Zugfahrten mit allen dazu bekannten Details (Abfahrt, Ankunft,
|
||||
Wagenreihung u.a.). Dies umfasst Angaben auf
|
||||
<a href="/status/<%= $name %>">/status/<%= $name %></a> sowie
|
||||
eine Liste deiner letzten Fahrten. Die Implementierung folgt noch...
|
||||
Wagenreihung u.a.). Derzeit sind diese nur mit einem von dir
|
||||
geteilten (oder korrekt erratenen) Link zu
|
||||
<a href="/status/<%= $name %>">/status/<%= $name %>/ID</a> abrufbar.
|
||||
In Zukunft kann eine auf deiner Statusseite eingebundene Liste
|
||||
deiner letzten Zugfahrten folgen, deren Sichtbarkeit ebenfalls von
|
||||
dieser Einstellung bestimmt wird.
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
|
Loading…
Reference in a new issue