Commit ccfdd800 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

testing a more organized history navigation

parent e3fba3dc
Loading
Loading
Loading
Loading
+86 −5
Original line number Diff line number Diff line
@@ -7,10 +7,16 @@ use Travel::Status::DE::IRIS::Stations;
use strict;
use warnings;
use 5.020;
use utf8;

use DateTime;
use JSON;

my @month_name
  = (
	qw(Januar Februar März April Mai Juni Juli August September Oktober November Dezember)
  );

sub epoch_to_dt {
	my ($epoch) = @_;

@@ -708,11 +714,58 @@ sub get_years {
	return @ret;
}

sub get_months {
sub get_months_for_year {
	my ( $self, %opt ) = @_;

	my $uid  = $opt{uid};
	my $db   = $opt{db} // $self->{pg}->db;
	my $year = $opt{year};

	my $res = $db->select(
		'journeys',
'distinct extract(year from real_departure) as year, extract(month from real_departure) as month',
		{ user_id  => $uid },
		{ order_by => { -asc => 'year' } }
	);

	my @ret;

	for my $month ( 1 .. 12 ) {
		push( @ret,
			[ sprintf( '%d/%02d', $year, $month ), $month_name[ $month - 1 ] ]
		);
	}

	for my $row ( $res->hashes->each ) {
		if ( $row->{year} == $year ) {

			# TODO delegate query to the (not yet present) JourneyStats model
			my $stats = $db->select(
				'journey_stats',
				['data'],
				{
					user_id => $uid,
					year    => $year,
					month   => $row->{month}
				}
			)->expand->hash;
			if ($stats) {
				$ret[ $row->{month} - 1 ][2] = $stats->{data};
			}
		}
	}
	return @ret;
}

sub get_nav_months {
	my ( $self, %opt ) = @_;

	my $uid          = $opt{uid};
	my $db           = $opt{db} // $self->{pg}->db;
	my $filter_year  = $opt{year};
	my $filter_month = $opt{month};

	my $selected_index = undef;

	my $res = $db->select(
		'journeys',
@@ -721,11 +774,39 @@ sub get_months {
		{ order_by => { -asc => 'yearmonth' } }
	);

	my @ret;
	my @months;
	for my $row ( $res->hashes->each ) {
		my ( $year, $month ) = split( qr{[.]}, $row->{yearmonth} );
		push( @ret, [ "${year}/${month}", "${month}.${year}" ] );
		push( @months, [ $year, $month ] );
		if ( $year eq $filter_year and $month eq $filter_month ) {
			$selected_index = $#months;
		}
	}

	# returns (previous entry, current month, next entry). if there is no
	# previous or next entry, the corresponding field is undef. Previous/next
	# entry is usually previous/next month, but may also have a distance of
	# more than one month if there are months without travels
	my @ret = ( undef, undef, undef );

	$ret[1] = [
		"${filter_year}/${filter_month}",
		$month_name[ $filter_month - 1 ] // $filter_month
	];

	if ( not defined $selected_index ) {
		return @ret;
	}

	if ( $selected_index > 0 and $months[ $selected_index - 1 ] ) {
		my ( $year, $month ) = @{ $months[ $selected_index - 1 ] };
		$ret[0] = [ "${year}/${month}", "${month}.${year}" ];
	}
	if ( $selected_index < $#months ) {
		my ( $year, $month ) = @{ $months[ $selected_index + 1 ] };
		$ret[2] = [ "${year}/${month}", "${month}.${year}" ];
	}

	return @ret;
}

+13 −13
Original line number Diff line number Diff line
const CACHE_NAME = 'static-cache-v34';
const CACHE_NAME = 'static-cache-v35';
const FILES_TO_CACHE = [
  '/favicon.ico',
  '/offline.html',
  '/static/v34/css/light.min.css',
  '/static/v34/css/dark.min.css',
  '/static/v34/css/material-icons.css',
  '/static/v34/css/local.css',
  '/static/v34/fonts/MaterialIcons-Regular.woff2',
  '/static/v34/fonts/MaterialIcons-Regular.woff',
  '/static/v34/fonts/MaterialIcons-Regular.ttf',
  '/static/v34/js/jquery-3.4.1.min.js',
  '/static/v34/js/materialize.min.js',
  '/static/v34/js/travelynx-actions.min.js',
  '/static/v34/js/autocomplete.min.js',
  '/static/v34/js/geolocation.min.js',
  '/static/v35/css/light.min.css',
  '/static/v35/css/dark.min.css',
  '/static/v35/css/material-icons.css',
  '/static/v35/css/local.css',
  '/static/v35/fonts/MaterialIcons-Regular.woff2',
  '/static/v35/fonts/MaterialIcons-Regular.woff',
  '/static/v35/fonts/MaterialIcons-Regular.ttf',
  '/static/v35/js/jquery-3.4.1.min.js',
  '/static/v35/js/materialize.min.js',
  '/static/v35/js/travelynx-actions.min.js',
  '/static/v35/js/autocomplete.min.js',
  '/static/v35/js/geolocation.min.js',
];

self.addEventListener('install', (evt) => {
+2 −2

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Diff line number Diff line
@@ -2,12 +2,12 @@
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(/static/v34/fonts/MaterialIcons-Regular.eot); /* For IE6-8 */
  src: url(/static/v35/fonts/MaterialIcons-Regular.eot); /* For IE6-8 */
  src: local('Material Icons'),
       local('MaterialIcons-Regular'),
       url(/static/v34/fonts/MaterialIcons-Regular.woff2) format('woff2'),
       url(/static/v34/fonts/MaterialIcons-Regular.woff) format('woff'),
       url(/static/v34/fonts/MaterialIcons-Regular.ttf) format('truetype');
       url(/static/v35/fonts/MaterialIcons-Regular.woff2) format('woff2'),
       url(/static/v35/fonts/MaterialIcons-Regular.woff) format('woff'),
       url(/static/v35/fonts/MaterialIcons-Regular.ttf) format('truetype');
}

.material-icons {
Loading