aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpezholio <pezholio@gmail.com>2017-02-02 15:25:27 +0000
committerpezholio <pezholio@gmail.com>2017-02-07 09:53:21 +0000
commit81b642a59ec389399131880f4850148157787c38 (patch)
tree5357b048d5e9fdc6551e638e073441aa7d4efd66
parent263ba94fe4ba91ef08cfada386900669ff289a2b (diff)
Add shortlist filters
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm39
-rw-r--r--t/app/controller/reports.t51
-rw-r--r--templates/web/base/reports/_list-filters.html4
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('<option value="shortlisted">Shortlisted</option>');
+ $mech->content_contains('<option value="unshortlisted">Unshortlisted</option>');
+
+ $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('<option value="shortlisted">Shortlisted</option>');
+ $mech->content_lacks('<option value="unshortlisted">Unshortlisted</option>');
+ };
+};
+
+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 %]
<select class="form-control js-multiple" name="status" id="statuses" multiple data-all="[% loc('All reports') %]">
+ [% IF c.user_exists AND c.user.has_body_permission_to('planned_reports') AND !shortlist %]
+ <option value="shortlisted"[% ' selected' IF filter_status.shortlisted %]>[% loc('Shortlisted') %]</option>
+ <option value="unshortlisted"[% ' selected' IF filter_status.unshortlisted %]>[% loc('Unshortlisted') %]</option>
+ [% END %]
<option value="open"[% ' selected' IF filter_status.open %]>[% loc('Unfixed reports') %]</option>
<option value="closed"[% ' selected' IF filter_status.closed %]>[% loc('Closed reports') %]</option>
<option value="fixed"[% ' selected' IF filter_status.fixed %]>[% loc('Fixed reports') %]</option>