aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Reports.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm42
1 files changed, 37 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 352c47da8..6b0d516a6 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->get_param('filter_category');
+
my $pins = $c->stash->{pins};
$c->stash->{page} = 'reports'; # So the map knows to make clickable pins
@@ -373,13 +383,15 @@ sub check_canonical_url : Private {
sub load_and_group_problems : Private {
my ( $self, $c ) = @_;
- my $page = $c->req->params->{p} || 1;
- my $type = $c->req->params->{t} || 'all';
- my $category = $c->req->params->{c} || '';
+ my $page = $c->get_param('p') || 1;
+ # NB: If 't' is specified, it will override 'status'.
+ my $type = $c->get_param('t') || 'all';
+ my $category = $c->get_param('c') || $c->get_param('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->get_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;