summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-04-27 09:11:42 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-04-27 09:11:42 +0200
commitd6e6c9992e85151ee12b9104bca647ce0e11782b (patch)
tree4bddfc005f4694aff7724f3479cac2e0bd4f5032
parent8c1888263ba1b79c86c677b8f7f665b7342b04c2 (diff)
History: Only show months and years with logged journeys
-rwxr-xr-xlib/Travelynx.pm41
-rw-r--r--templates/_history_months.html.ep8
-rw-r--r--templates/_history_years.html.ep8
-rw-r--r--templates/history.html.ep14
-rw-r--r--templates/history_by_month.html.ep4
-rw-r--r--templates/history_by_year.html.ep4
6 files changed, 55 insertions, 24 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index f5fdb47..6434e00 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -1069,6 +1069,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(
'get_oldest_journey_ts' => sub {
my ($self) = @_;
diff --git a/templates/_history_months.html.ep b/templates/_history_months.html.ep
index 465a159..6a83d74 100644
--- a/templates/_history_months.html.ep
+++ b/templates/_history_months.html.ep
@@ -1,11 +1,11 @@
<div class="row">
<div class="col s12">
<ul class="pagination">
- % while ($since < $now) {
- % my $link_to = $since->strftime('%Y/%m');
+ % for my $month (history_months()) {
+ % my $link_to = $month->[0];
+ % my $text = $month->[1];
% my $class = $link_to eq $current ? 'active' : 'waves-effect';
- <li class="<%= $class %>"><a href="/history/<%= $link_to %>"><%= $since->strftime('%m.%Y') %></a></li>
- % $since->add(months => 1)->set(day => 1, hour => 0, minute => 0, second => 0);
+ <li class="<%= $class %>"><a href="/history/<%= $link_to %>"><%= $text %></a></li>
% }
</ul>
</div>
diff --git a/templates/_history_years.html.ep b/templates/_history_years.html.ep
index 02bb70d..768c438 100644
--- a/templates/_history_years.html.ep
+++ b/templates/_history_years.html.ep
@@ -1,11 +1,11 @@
<div class="row">
<div class="col s12">
<ul class="pagination">
- % while ($since < $now) {
- % my $link_to = $since->strftime('%Y');
+ % for my $year (history_years()) {
+ % my $link_to = $year->[0];
+ % my $text = $year->[1];
% my $class = $link_to eq $current ? 'active' : 'waves-effect';
- <li class="<%= $class %>"><a href="/history/<%= $link_to %>"><%= $since->strftime('%Y') %></a></li>
- % $since->add(years => 1)->set(month => 1, day => 1, hour => 0, minute => 0, second => 0);
+ <li class="<%= $class %>"><a href="/history/<%= $link_to %>"><%= $text %></a></li>
% }
</ul>
</div>
diff --git a/templates/history.html.ep b/templates/history.html.ep
index 246d6af..a2f607a 100644
--- a/templates/history.html.ep
+++ b/templates/history.html.ep
@@ -22,12 +22,8 @@
</div>
<h2>Nach Jahr</h2>
-% my $since = get_oldest_journey_ts();
-% my $now = DateTime->now(time_zone => 'Europe/Berlin');
-% if ($since) {
- %= include '_history_years', current => '', since => $since->clone, now => $now;
-% }
-% else {
+%= include '_history_years', current => '';
+% if(0) {
<div class="row">
<div class="col s12">
Noch keine Fahrten.
@@ -36,10 +32,8 @@
% }
<h2>Nach Monat</h2>
-% if ($since) {
- %= include '_history_months', current => '', since => $since->clone, now => $now;
-% }
-% else {
+%= include '_history_months', current => '';
+% if(0) {
<div class="row">
<div class="col s12">
Noch keine Fahrten.
diff --git a/templates/history_by_month.html.ep b/templates/history_by_month.html.ep
index 64d42c6..7aae59d 100644
--- a/templates/history_by_month.html.ep
+++ b/templates/history_by_month.html.ep
@@ -1,6 +1,4 @@
-% my $since = get_oldest_journey_ts();
-% my $now = DateTime->now(time_zone => 'Europe/Berlin');
-%= include '_history_months', current => "${year}/${month}", since => $since, now => $now;
+%= include '_history_months', current => "${year}/${month}";
<h1><%= stash('month_name') %> <%= stash('year') %></h1>
diff --git a/templates/history_by_year.html.ep b/templates/history_by_year.html.ep
index f73d7ec..c5cffa0 100644
--- a/templates/history_by_year.html.ep
+++ b/templates/history_by_year.html.ep
@@ -1,6 +1,4 @@
-% my $since = get_oldest_journey_ts();
-% my $now = DateTime->now(time_zone => 'Europe/Berlin');
-%= include '_history_years', current => $year, since => $since, now => $now;
+%= include '_history_years', current => $year;
<h1>Jahresrückblick <%= $year %></h1>