From 7614dc8ff0318e14e1cd7a590ee817ce5050923e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 6 Mar 2015 19:48:47 +0100 Subject: barform: add optional filters (TODO: Lol Encoding) --- index.pl | 42 ++++++++++++++++++++++++++++++++++++++++- public/css/default.css | 16 ++++++++++++++++ templates/barform.html.ep | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/index.pl b/index.pl index 108539c..a44c0bd 100644 --- a/index.pl +++ b/index.pl @@ -91,6 +91,46 @@ helper barplot_args => sub { }; }; +helper barplot_filters => sub { + my ($self) = @_; + my $dbh = $self->app->dbh; + + my $ret = { + lines => [ + map { $_->[0] } @{ + $dbh->selectall_arrayref( +"select distinct train_type || ' ' || line_no as line from $table order by line" + ) + } + ], + train_types => [ + q{}, + map { $_->[0] } @{ + $dbh->selectall_arrayref( + "select distinct train_type from $table order by train_type" + ) + } + ], + stations => [ + q{}, + map { $_->[0] } @{ + $dbh->selectall_arrayref( + "select distinct station from $table order by station") + } + ], + destinations => [ + q{}, + map { $_->[0] } @{ + $dbh->selectall_arrayref( +"select distinct destination from $table order by destination" + ) + } + ], + }; + + return $ret; +}; + helper count_unique_column => sub { my ( $self, $column ) = @_; my $dbh = $self->app->dbh; @@ -294,7 +334,7 @@ get '/2ddata.tsv' => sub { get '/' => sub { my $self = shift; - $self->render('intro', version => $VERSION); + $self->render( 'intro', version => $VERSION ); return; }; diff --git a/public/css/default.css b/public/css/default.css index 7b37068..dec73f2 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -10,6 +10,22 @@ input.dimension { width: 4em; } +input.delay { + width: 3em; +} + +div.field { + width: 100%; + clear: both; +} + +div.field div.desc { + float: left; + width: 12em; + text-align: right; + padding-right: 0.5em; +} + svg { font: 10px sans-serif; } diff --git a/templates/barform.html.ep b/templates/barform.html.ep index 62c8bda..6b23fe2 100644 --- a/templates/barform.html.ep +++ b/templates/barform.html.ep @@ -1,3 +1,4 @@ +
% if (not defined param('want_msg')) { % param(want_msg => 0); % } @@ -25,4 +26,51 @@ x %= text_field 'height' => 500, class => 'dimension' Pixel. %= submit_button 'Go' +
+% my $filter_opts = $self->barplot_filters; +Optionale Einschränkungen: +
+
+ Linie: +
+
+ %= select_field filter_line => [map {[$_, $_]} @{$filter_opts->{lines}} ] +
+
+
+
+ Zugtyp: +
+
+ %= select_field filter_train_type => [map {[$_, $_]} @{$filter_opts->{train_types}} ] +
+
+
+
+ Bahnhof: +
+
+ %= select_field filter_station => [map {[$_, $_]} @{$filter_opts->{stations}} ] +
+
+
+
+ Zielbahnhof: +
+
+ %= select_field filter_destination => [map {[$_, $_]} @{$filter_opts->{destinations}} ] +
+
+
+
+ Verspätung zwischen +
+
+ %= text_field 'filter_delay_min', class => 'delay', placeholder => '-∞' + und + %= text_field 'filter_delay_max', class => 'delay', placeholder => '+∞' + Minuten (inklusive). +
+
% end +
-- cgit v1.2.3