Skip to content

Commit

Permalink
add timeline / current checkins
Browse files Browse the repository at this point in the history
  • Loading branch information
derf committed Jul 15, 2023
1 parent bee67f0 commit 1cca278
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/Travelynx.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,7 @@ sub startup {
$authed_r->post('/delete')->to('account#delete');
$authed_r->post('/logout')->to('account#do_logout');
$authed_r->post('/set_token')->to('api#set_token');
$authed_r->get('/timeline/in-transit')->to('profile#checked_in');

}

Expand Down
24 changes: 24 additions & 0 deletions lib/Travelynx/Controller/Profile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,28 @@ sub status_card {
);
}

sub checked_in {
my ($self) = @_;

my $uid = $self->current_user->{id};
my @journeys = $self->in_transit->get_timeline(
uid => $uid,
with_data => 1
);

if ( $self->param('ajax') ) {
delete $self->stash->{layout};
$self->render(
'_timeline-checked-in',
journeys => [@journeys],
);
}
else {
$self->render(
'timeline-checked-in',
journeys => [@journeys],
);
}
}

1;
14 changes: 13 additions & 1 deletion lib/Travelynx/Controller/Traveling.pm
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,13 @@ sub compute_effective_visibility {
sub homepage {
my ($self) = @_;
if ( $self->is_user_authenticated ) {
my $status = $self->get_user_status;
my $uid = $self->current_user->{id};
my $status = $self->get_user_status;
my @timeline = $self->in_transit->get_timeline(
uid => $uid,
short => 1
);
$self->stash( timeline => [@timeline] );
my @recent_targets;
if ( $status->{checked_in} ) {
my $journey_visibility
Expand Down Expand Up @@ -457,6 +463,12 @@ sub status_card {

delete $self->stash->{layout};

my @timeline = $self->in_transit->get_timeline(
uid => $self->current_user->{id},
short => 1
);
$self->stash( timeline => [@timeline] );

if ( $status->{checked_in} ) {
my $journey_visibility
= $self->compute_effective_visibility(
Expand Down
3 changes: 3 additions & 0 deletions templates/_checked_in.html.ep
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
% my $user = current_user();
% if (@{stash('timeline') // []}) {
%= include '_timeline_link', timeline => stash('timeline')
% }
<div class="autorefresh">
<div class="card">
<div class="card-content">
Expand Down
5 changes: 4 additions & 1 deletion templates/_public_status_card.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
% if (stash('from_profile')) {
Unterwegs mit <%= include '_format_train', journey => $journey %>
% }
% elsif (stash('from_timeline')) {
<a href="/p/<%= $name %>"><%= $name %></a>: <%= include '_format_train', journey => $journey %>
% }
% else {
<a href="/p/<%= $name %>"><%= $name %></a> ist unterwegs
% }
Expand All @@ -16,7 +19,7 @@
<p>„<%= $journey->{comment} %>“</p>
% }
<p>
% if (not stash('from_profile')) {
% if (not stash('from_profile') and not stash('from_timeline')) {
<div class="center-align">
%= include '_format_train', journey => $journey
</div>
Expand Down
7 changes: 7 additions & 0 deletions templates/_timeline-checked-in.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
% for my $journey (@{$journeys}) {
<div class="row">
<div class="col s12 autorefresh">
%= include '_public_status_card', name => $journey->{followee_name}, privacy => {}, journey => $journey, from_timeline => 1
</div>
</div>
% }
16 changes: 16 additions & 0 deletions templates/_timeline_link.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div>
<a href="/timeline/in-transit">
% if (@{$timeline} <= 2) {
<strong><%= $timeline->[0]->{followee_name} %></strong>
% }
% if (@{$timeline} == 1) {
ist gerade unterwegs
% }
% elsif (@{$timeline} == 2) {
und <strong><%= $timeline->[1]->{followee_name} %></strong> sind gerade unterwegs
% }
% else {
<strong><%= scalar @{$timeline} %></strong> Accounts sind gerade unterwegs
% }
</a>
</div>
6 changes: 6 additions & 0 deletions templates/landingpage.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
%= include '_checked_in', journey => $status, journey_visibility => stash('journey_visibility');
% }
% elsif ($status->{cancelled}) {
% if ( @{stash('timeline') // [] } ) {
%= include '_timeline_link', timeline => stash('timeline')
% }
<div class="card info-color">
<div class="card-content">
<span class="card-title">Zugausfall dokumentieren</span>
Expand Down Expand Up @@ -45,6 +48,9 @@
</div>
% }
% else {
% if ( @{stash('timeline') // [] } ) {
%= include '_timeline_link', timeline => stash('timeline')
% }
<div class="card">
<div class="card-content">
<span class="card-title">Hallo, <%= current_user->{name} %>!</span>
Expand Down
3 changes: 3 additions & 0 deletions templates/timeline-checked-in.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="timeline-in-transit">
%= include '_timeline-checked-in', journeys => $journeys
</div>

0 comments on commit 1cca278

Please sign in to comment.