From 020769f403ef4cf1880bd061b6db6b4f4028d3e4 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 1 Dec 2016 18:23:54 +0000 Subject: Return 400/500 for some client/server errors. --- perllib/FixMyStreet/App/Controller/Reports.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm') diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 813c2052d..f2c43b5ee 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -76,13 +76,12 @@ sub index : Path : Args(0) { $c->stash->{open} = $j->{open}; }; if ($@) { - $c->stash->{message} = _("There was a problem showing the All Reports page. Please try again later."); + my $message = _("There was a problem showing the All Reports page. Please try again later."); if ($c->config->{STAGING_SITE}) { - $c->stash->{message} .= '

Perhaps the bin/update-all-reports script needs running. Use: bin/update-all-reports

' + $message .= '

Perhaps the bin/update-all-reports script needs running. Use: bin/update-all-reports

' . sprintf(_('The error was: %s'), $@); } - $c->stash->{template} = 'errors/generic.html'; - return; + $c->detach('/page_error_500_internal_error', [ $message ]); } # Down here so that error pages aren't cached. -- cgit v1.2.3 From 21877e063f8ab9c5914adbc88c8210d2393671ae Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 22 Nov 2016 15:38:07 +0000 Subject: Add shortlist buttons to report lists. This includes adding/removing reports from a user's shortlist, and manual reordering of a shortlist with up/down buttons. The backend code can cope with an item moving to any point in the list. --- perllib/FixMyStreet/App/Controller/Reports.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm') diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index f2c43b5ee..2635b7b7a 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -108,6 +108,8 @@ Show the summary page for a particular ward. sub ward : Path : Args(2) { my ( $self, $c, $body, $ward ) = @_; + $c->forward('/auth/get_csrf_token'); + $c->forward( 'body_check', [ $body ] ); $c->forward( 'ward_check', [ $ward ] ) if $ward; @@ -513,13 +515,17 @@ sub stash_report_sort : Private { ); my $sort = $c->get_param('sort') || $default; - $sort = $default unless $sort =~ /^((updated|created)-(desc|asc)|comments-desc)$/; + $sort = $default unless $sort =~ /^((updated|created)-(desc|asc)|comments-desc|shortlist)$/; + $c->stash->{sort_key} = $sort; + + # Going to do this sorting code-side + $sort = 'created-desc' if $sort eq 'shortlist'; + $sort =~ /^(updated|created|comments)-(desc|asc)$/; my $order_by = $types{$1} || $1; my $dir = $2; $order_by = { -desc => $order_by } if $dir eq 'desc'; - $c->stash->{sort_key} = $sort; $c->stash->{sort_order} = $order_by; return 1; } -- cgit v1.2.3 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 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm') 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; - -- cgit v1.2.3 From 112ab20142f7f79d4ffff557b95c53406ad79bd9 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 13 Apr 2017 14:29:56 +0100 Subject: Fix issue with categories with regex characters. As the templates were using `grep`, they failed to match on a category such as "Footpaths (right of way)". Changing the stash variables to be hashes instead of lists makes checking for a key simpler. Fixes #1688. --- perllib/FixMyStreet/App/Controller/Reports.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm') diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 69a2ddb0f..bb5b13b61 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -137,7 +137,7 @@ sub ward : Path : Args(2) { } )->all; @categories = map { $_->category } @categories; $c->stash->{filter_categories} = \@categories; - $c->stash->{filter_category} = [ $c->get_param_list('filter_category', 1) ]; + $c->stash->{filter_category} = { map { $_ => 1 } $c->get_param_list('filter_category', 1) }; my $pins = $c->stash->{pins}; -- cgit v1.2.3 From ef6ffbdbfa562dca1825a0abc06afb0e52509737 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 13 Apr 2017 16:48:57 +0100 Subject: On /reports maps, only include reports in view. Update the reports with a bounding box, similar to on around pages. This is made slightly trickier because we don't want to do anything on page load (we already have the pins), we need to reload when the zoom changes, and we don't want the strategy to get confused by its first redraw, e.g. on pin hover, We also need to turn off the zoom- to-bounds if we've got a bounding box in the URL. --- perllib/FixMyStreet/App/Controller/Reports.pm | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm') diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index bb5b13b61..ed851f71f 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -430,6 +430,12 @@ sub load_and_group_problems : Private { $problems = $problems->to_body($c->stash->{body}); } + if (my $bbox = $c->get_param('bbox')) { + my ($min_lon, $min_lat, $max_lon, $max_lat) = split /,/, $bbox; + $where->{latitude} = { '>=', $min_lat, '<', $max_lat }; + $where->{longitude} = { '>=', $min_lon, '<', $max_lon }; + } + $problems = $problems->search( $where, $filter -- cgit v1.2.3