History: Only show months and years with logged journeys
This commit is contained in:
parent
8c1888263b
commit
d6e6c9992e
6 changed files with 55 additions and 24 deletions
|
@ -1068,6 +1068,47 @@ sub startup {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$self->helper(
|
||||||
|
'history_years' => sub {
|
||||||
|
my ( $self, $uid ) = @_;
|
||||||
|
$uid //= $self->current_user->{id},
|
||||||
|
|
||||||
|
my $res = $self->pg->db->select(
|
||||||
|
'journeys',
|
||||||
|
'distinct extract(year from real_departure) as year',
|
||||||
|
{ user_id => $uid },
|
||||||
|
{ order_by => { -asc => 'year' } }
|
||||||
|
);
|
||||||
|
|
||||||
|
my @ret;
|
||||||
|
for my $row ( $res->hashes->each ) {
|
||||||
|
push( @ret, [ $row->{year}, $row->{year} ] );
|
||||||
|
}
|
||||||
|
return @ret;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$self->helper(
|
||||||
|
'history_months' => sub {
|
||||||
|
my ( $self, $uid ) = @_;
|
||||||
|
$uid //= $self->current_user->{id},
|
||||||
|
|
||||||
|
my $res = $self->pg->db->select(
|
||||||
|
'journeys',
|
||||||
|
"distinct to_char(real_departure, 'YYYY.MM') as yearmonth",
|
||||||
|
{ user_id => $uid },
|
||||||
|
{ order_by => { -asc => 'yearmonth' } }
|
||||||
|
);
|
||||||
|
|
||||||
|
my @ret;
|
||||||
|
for my $row ( $res->hashes->each ) {
|
||||||
|
my ( $year, $month ) = split( qr{[.]}, $row->{yearmonth} );
|
||||||
|
push( @ret, [ "${year}/${month}", "${month}.${year}" ] );
|
||||||
|
}
|
||||||
|
return @ret;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$self->helper(
|
$self->helper(
|
||||||
'get_oldest_journey_ts' => sub {
|
'get_oldest_journey_ts' => sub {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
% while ($since < $now) {
|
% for my $month (history_months()) {
|
||||||
% my $link_to = $since->strftime('%Y/%m');
|
% my $link_to = $month->[0];
|
||||||
|
% my $text = $month->[1];
|
||||||
% my $class = $link_to eq $current ? 'active' : 'waves-effect';
|
% my $class = $link_to eq $current ? 'active' : 'waves-effect';
|
||||||
<li class="<%= $class %>"><a href="/history/<%= $link_to %>"><%= $since->strftime('%m.%Y') %></a></li>
|
<li class="<%= $class %>"><a href="/history/<%= $link_to %>"><%= $text %></a></li>
|
||||||
% $since->add(months => 1)->set(day => 1, hour => 0, minute => 0, second => 0);
|
|
||||||
% }
|
% }
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
% while ($since < $now) {
|
% for my $year (history_years()) {
|
||||||
% my $link_to = $since->strftime('%Y');
|
% my $link_to = $year->[0];
|
||||||
|
% my $text = $year->[1];
|
||||||
% my $class = $link_to eq $current ? 'active' : 'waves-effect';
|
% my $class = $link_to eq $current ? 'active' : 'waves-effect';
|
||||||
<li class="<%= $class %>"><a href="/history/<%= $link_to %>"><%= $since->strftime('%Y') %></a></li>
|
<li class="<%= $class %>"><a href="/history/<%= $link_to %>"><%= $text %></a></li>
|
||||||
% $since->add(years => 1)->set(month => 1, day => 1, hour => 0, minute => 0, second => 0);
|
|
||||||
% }
|
% }
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,12 +22,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Nach Jahr</h2>
|
<h2>Nach Jahr</h2>
|
||||||
% my $since = get_oldest_journey_ts();
|
%= include '_history_years', current => '';
|
||||||
% my $now = DateTime->now(time_zone => 'Europe/Berlin');
|
% if(0) {
|
||||||
% if ($since) {
|
|
||||||
%= include '_history_years', current => '', since => $since->clone, now => $now;
|
|
||||||
% }
|
|
||||||
% else {
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
Noch keine Fahrten.
|
Noch keine Fahrten.
|
||||||
|
@ -36,10 +32,8 @@
|
||||||
% }
|
% }
|
||||||
|
|
||||||
<h2>Nach Monat</h2>
|
<h2>Nach Monat</h2>
|
||||||
% if ($since) {
|
%= include '_history_months', current => '';
|
||||||
%= include '_history_months', current => '', since => $since->clone, now => $now;
|
% if(0) {
|
||||||
% }
|
|
||||||
% else {
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
Noch keine Fahrten.
|
Noch keine Fahrten.
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
% my $since = get_oldest_journey_ts();
|
%= include '_history_months', current => "${year}/${month}";
|
||||||
% my $now = DateTime->now(time_zone => 'Europe/Berlin');
|
|
||||||
%= include '_history_months', current => "${year}/${month}", since => $since, now => $now;
|
|
||||||
|
|
||||||
<h1><%= stash('month_name') %> <%= stash('year') %></h1>
|
<h1><%= stash('month_name') %> <%= stash('year') %></h1>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
% my $since = get_oldest_journey_ts();
|
%= include '_history_years', current => $year;
|
||||||
% my $now = DateTime->now(time_zone => 'Europe/Berlin');
|
|
||||||
%= include '_history_years', current => $year, since => $since, now => $now;
|
|
||||||
|
|
||||||
<h1>Jahresrückblick <%= $year %></h1>
|
<h1>Jahresrückblick <%= $year %></h1>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue