diff options
author | Dave Arter <davea@mysociety.org> | 2015-06-30 11:03:20 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2015-06-30 11:03:20 +0100 |
commit | bff57817b0a8d9d2ab8ceeecbcba17f259d4ac1a (patch) | |
tree | a2a755e57e92c3991c3681ae13d74347ddf0fb9c /perllib/FixMyStreet/App/Controller/Reports.pm | |
parent | 1df64a30dd0939d8d9b8b1854f7f7e421d9b20ab (diff) | |
parent | b2c41d9b9ac0444565cdc8b6dbbaeedf759185ba (diff) |
Merge branch 'report-filtering-on-map'
This branch allows the map pages to be filtered by report category and
status with the 'filter_category' and 'status' GET parameters.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 352c47da8..5a044c9af 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -109,6 +109,7 @@ sub ward : Path : Args(2) { $c->forward( 'ward_check', [ $ward ] ) if $ward; $c->forward( 'check_canonical_url', [ $body ] ); + $c->forward( 'stash_report_filter_status' ); $c->forward( 'load_and_group_problems' ); my $body_short = $c->cobrand->short_name( $c->stash->{body} ); @@ -120,6 +121,15 @@ sub ward : Path : Args(2) { $c->stash->{stats} = $c->cobrand->get_report_stats(); + my @categories = $c->stash->{body}->contacts->search( undef, { + columns => [ 'category' ], + distinct => 1, + order_by => [ 'category' ], + } )->all; + @categories = map { $_->category } @categories; + $c->stash->{filter_categories} = \@categories; + $c->stash->{filter_category} = $c->req->param('filter_category'); + my $pins = $c->stash->{pins}; $c->stash->{page} = 'reports'; # So the map knows to make clickable pins @@ -374,12 +384,14 @@ sub load_and_group_problems : Private { my ( $self, $c ) = @_; my $page = $c->req->params->{p} || 1; + # NB: If 't' is specified, it will override 'status'. my $type = $c->req->params->{t} || 'all'; - my $category = $c->req->params->{c} || ''; + my $category = $c->req->params->{c} || $c->req->params->{filter_category} || ''; + my $states = $c->stash->{filter_problem_states}; my $where = { non_public => 0, - state => [ FixMyStreet::DB::Result::Problem->visible_states() ] + state => [ keys %$states ] }; my $not_open = [ FixMyStreet::DB::Result::Problem::fixed_states(), FixMyStreet::DB::Result::Problem::closed_states() ]; @@ -430,7 +442,7 @@ sub load_and_group_problems : Private { my $problems = $c->cobrand->problems->search( $where, { - order_by => { -desc => 'lastupdate' }, + order_by => $c->cobrand->reports_ordering, rows => $c->cobrand->reports_per_page, } )->page( $page ); @@ -485,6 +497,26 @@ sub redirect_body : Private { $c->res->redirect( $c->uri_for($url, $c->req->params ) ); } +sub stash_report_filter_status : Private { + my ( $self, $c ) = @_; + + my $status = $c->req->param('status') || $c->cobrand->on_map_default_status; + if ( $status eq 'all' ) { + $c->stash->{filter_status} = 'all'; + $c->stash->{filter_problem_states} = FixMyStreet::DB::Result::Problem->visible_states(); + } elsif ( $status eq 'open' ) { + $c->stash->{filter_status} = 'open'; + $c->stash->{filter_problem_states} = FixMyStreet::DB::Result::Problem->open_states(); + } elsif ( $status eq 'fixed' ) { + $c->stash->{filter_status} = 'fixed'; + $c->stash->{filter_problem_states} = FixMyStreet::DB::Result::Problem->fixed_states(); + } else { + $c->stash->{filter_status} = $c->cobrand->on_map_default_status; + } + + return 1; +} + sub add_row { my ( $c, $problem, $body, $problems, $pins ) = @_; push @{$problems->{$body}}, $problem; |