From 81b642a59ec389399131880f4850148157787c38 Mon Sep 17 00:00:00 2001 From: pezholio Date: Thu, 2 Feb 2017 15:25:27 +0000 Subject: Add shortlist filters --- perllib/FixMyStreet/App/Controller/Reports.pm | 39 +++++++++++++++++--- t/app/controller/reports.t | 51 ++++++++++++++++++++++++++- templates/web/base/reports/_list-filters.html | 4 +++ 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 2635b7b7a..69a2ddb0f 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -378,6 +378,25 @@ sub load_and_group_problems : Private { non_public => 0, state => [ keys %$states ] }; + my $filter = { + order_by => $c->stash->{sort_order}, + rows => $c->cobrand->reports_per_page, + }; + + if (defined $c->stash->{filter_status}{shortlisted}) { + $where->{'me.id'} = { '=', \"user_planned_reports.report_id"}; + $where->{'user_planned_reports.removed'} = undef; + $filter->{join} = 'user_planned_reports'; + } elsif (defined $c->stash->{filter_status}{unshortlisted}) { + my $shortlisted_ids = $c->cobrand->problems->search({ + 'me.id' => { '=', \"user_planned_reports.report_id"}, + 'user_planned_reports.removed' => undef, + }, { + join => 'user_planned_reports', + columns => ['me.id'], + })->as_query; + $where->{'me.id'} = { -not_in => $shortlisted_ids }; + } my $not_open = [ FixMyStreet::DB::Result::Problem::fixed_states(), FixMyStreet::DB::Result::Problem::closed_states() ]; if ( $type eq 'new' ) { @@ -413,11 +432,9 @@ sub load_and_group_problems : Private { $problems = $problems->search( $where, - { - order_by => $c->stash->{sort_order}, - rows => $c->cobrand->reports_per_page, - } + $filter )->include_comment_counts->page( $page ); + $c->stash->{pager} = $problems->pager; my ( %problems, @pins ); @@ -500,6 +517,19 @@ sub stash_report_filter_status : Private { %filter_problem_states = %$s; } + if ($status{shortlisted}) { + $filter_status{shortlisted} = 1; + } + + if ($status{unshortlisted}) { + $filter_status{unshortlisted} = 1; + } + + if (keys %filter_problem_states == 0) { + my $s = FixMyStreet::DB::Result::Problem->open_states(); + %filter_problem_states = (%filter_problem_states, %$s); + } + $c->stash->{filter_problem_states} = \%filter_problem_states; $c->stash->{filter_status} = \%filter_status; return 1; @@ -577,4 +607,3 @@ Licensed under the Affero GPL. __PACKAGE__->meta->make_immutable; 1; - diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 141269cd8..8fa03897b 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -233,5 +233,54 @@ subtest "test greenwich all reports page" => sub { } }; -done_testing(); +subtest "it lists shortlisted reports" => sub { + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/' + }, sub { + my $body = FixMyStreet::App->model('DB::Body')->find( $body_edin_id ); + my $user = $mech->log_in_ok( 'test@example.com' ); + $user->update({ from_body => $body }); + $user->user_body_permissions->find_or_create({ + body => $body, + permission_type => 'planned_reports', + }); + + my ($shortlisted_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Shortlisted report'); + my ($unshortlisted_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Unshortlisted report'); + my ($removed_from_shortlist_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Removed from shortlist report'); + + $user->add_to_planned_reports($shortlisted_problem); + $user->add_to_planned_reports($removed_from_shortlist_problem); + $user->remove_from_planned_reports($removed_from_shortlist_problem); + + $mech->get_ok('/reports/City+of+Edinburgh+Council'); + $mech->content_contains(''); + $mech->content_contains(''); + + $mech->get_ok('/reports/City+of+Edinburgh+Council?status=shortlisted'); + + $mech->content_contains('Shortlisted report'); + $mech->content_lacks('Unshortlisted report'); + $mech->content_lacks('Removed from shortlist report'); + $mech->get_ok('/reports/City+of+Edinburgh+Council?status=shortlisted,open'); + + $mech->content_contains('Shortlisted report'); + $mech->content_lacks('Unshortlisted report'); + $mech->content_lacks('Removed from shortlist report'); + + $mech->get_ok('/reports/City+of+Edinburgh+Council?status=unshortlisted,open'); + + $mech->content_contains('Unshortlisted report'); + $mech->content_contains('Removed from shortlist report'); + $mech->content_lacks('Shortlisted report'); + + $user->admin_user_body_permissions->delete; + + $mech->get_ok('/reports/City+of+Edinburgh+Council'); + $mech->content_lacks(''); + $mech->content_lacks(''); + }; +}; + +done_testing(); diff --git a/templates/web/base/reports/_list-filters.html b/templates/web/base/reports/_list-filters.html index 05fe6123b..58be5cd50 100644 --- a/templates/web/base/reports/_list-filters.html +++ b/templates/web/base/reports/_list-filters.html @@ -1,5 +1,9 @@ [% select_status = BLOCK %]