From 1cca278baac0f50012e524eac7c441c998f4d8c3 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sat, 15 Jul 2023 19:20:37 +0200 Subject: [PATCH] add timeline / current checkins --- lib/Travelynx.pm | 1 + lib/Travelynx/Controller/Profile.pm | 24 ++++++++++++++++++++++++ lib/Travelynx/Controller/Traveling.pm | 14 +++++++++++++- templates/_checked_in.html.ep | 3 +++ templates/_public_status_card.html.ep | 5 ++++- templates/_timeline-checked-in.html.ep | 7 +++++++ templates/_timeline_link.html.ep | 16 ++++++++++++++++ templates/landingpage.html.ep | 6 ++++++ templates/timeline-checked-in.html.ep | 3 +++ 9 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 templates/_timeline-checked-in.html.ep create mode 100644 templates/_timeline_link.html.ep create mode 100644 templates/timeline-checked-in.html.ep diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 5b8680e..c529cb7 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -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'); } diff --git a/lib/Travelynx/Controller/Profile.pm b/lib/Travelynx/Controller/Profile.pm index b8812f8..03f3b0d 100755 --- a/lib/Travelynx/Controller/Profile.pm +++ b/lib/Travelynx/Controller/Profile.pm @@ -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; diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index f283762..fe9b4f5 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -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 @@ -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( diff --git a/templates/_checked_in.html.ep b/templates/_checked_in.html.ep index df5472b..2382ac4 100644 --- a/templates/_checked_in.html.ep +++ b/templates/_checked_in.html.ep @@ -1,4 +1,7 @@ % my $user = current_user(); +% if (@{stash('timeline') // []}) { + %= include '_timeline_link', timeline => stash('timeline') +% }
diff --git a/templates/_public_status_card.html.ep b/templates/_public_status_card.html.ep index acbae0d..cbdc878 100644 --- a/templates/_public_status_card.html.ep +++ b/templates/_public_status_card.html.ep @@ -7,6 +7,9 @@ % if (stash('from_profile')) { Unterwegs mit <%= include '_format_train', journey => $journey %> % } + % elsif (stash('from_timeline')) { + <%= $name %>: <%= include '_format_train', journey => $journey %> + % } % else { <%= $name %> ist unterwegs % } @@ -16,7 +19,7 @@

„<%= $journey->{comment} %>“

% }

- % if (not stash('from_profile')) { + % if (not stash('from_profile') and not stash('from_timeline')) {

%= include '_format_train', journey => $journey
diff --git a/templates/_timeline-checked-in.html.ep b/templates/_timeline-checked-in.html.ep new file mode 100644 index 0000000..b1d37ce --- /dev/null +++ b/templates/_timeline-checked-in.html.ep @@ -0,0 +1,7 @@ +% for my $journey (@{$journeys}) { +
+
+ %= include '_public_status_card', name => $journey->{followee_name}, privacy => {}, journey => $journey, from_timeline => 1 +
+
+% } diff --git a/templates/_timeline_link.html.ep b/templates/_timeline_link.html.ep new file mode 100644 index 0000000..782906e --- /dev/null +++ b/templates/_timeline_link.html.ep @@ -0,0 +1,16 @@ +
+ + % if (@{$timeline} <= 2) { + <%= $timeline->[0]->{followee_name} %> + % } + % if (@{$timeline} == 1) { + ist gerade unterwegs + % } + % elsif (@{$timeline} == 2) { + und <%= $timeline->[1]->{followee_name} %> sind gerade unterwegs + % } + % else { + <%= scalar @{$timeline} %> Accounts sind gerade unterwegs + % } + +
diff --git a/templates/landingpage.html.ep b/templates/landingpage.html.ep index b91cd89..d3b514f 100644 --- a/templates/landingpage.html.ep +++ b/templates/landingpage.html.ep @@ -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') + % }
Zugausfall dokumentieren @@ -45,6 +48,9 @@
% } % else { + % if ( @{stash('timeline') // [] } ) { + %= include '_timeline_link', timeline => stash('timeline') + % }
Hallo, <%= current_user->{name} %>! diff --git a/templates/timeline-checked-in.html.ep b/templates/timeline-checked-in.html.ep new file mode 100644 index 0000000..0ed492e --- /dev/null +++ b/templates/timeline-checked-in.html.ep @@ -0,0 +1,3 @@ +
+ %= include '_timeline-checked-in', journeys => $journeys +