aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm46
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm20
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm38
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm18
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm8
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Nearby.pm9
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm9
-rw-r--r--perllib/FixMyStreet/Map.pm23
-rw-r--r--perllib/FixMyStreet/TestMech.pm1
9 files changed, 150 insertions, 22 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 413af814f..5bfe1ada2 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -165,10 +165,15 @@ sub display_location : Private {
$c->stash->{all_pins} = $all_pins;
my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age;
+ $c->forward( '/reports/stash_report_filter_status' );
+
+ # Check the category to filter by, if any, is valid
+ $c->forward('check_and_stash_category');
+
# get the map features
my ( $on_map_all, $on_map, $around_map, $distance ) =
FixMyStreet::Map::map_features( $c, $latitude, $longitude,
- $interval );
+ $interval, $c->stash->{filter_category}, $c->stash->{filter_problem_states} );
# copy the found reports to the stash
$c->stash->{on_map} = $on_map;
@@ -221,6 +226,45 @@ sub check_location_is_acceptable : Private {
return $c->forward('/council/load_and_check_areas');
}
+=head2 check_and_stash_category
+
+Check that the 'filter_category' query param is valid, if it's present. Stores
+the validated string in the stash as filter_category.
+Puts all the valid categories in filter_categories on the stash.
+
+=cut
+
+sub check_and_stash_category : Private {
+ my ( $self, $c ) = @_;
+
+ my $all_areas = $c->stash->{all_areas};
+ my @bodies = $c->model('DB::Body')->search(
+ { 'body_areas.area_id' => [ keys %$all_areas ], deleted => 0 },
+ { join => 'body_areas' }
+ )->all;
+ my %bodies = map { $_->id => $_ } @bodies;
+
+ my @contacts = $c->model('DB::Contact')->not_deleted->search(
+ {
+ body_id => [ keys %bodies ],
+ },
+ {
+ columns => [ 'category' ],
+ order_by => [ 'category' ],
+ distinct => 1
+ }
+ )->all;
+ my @categories = map { $_->category } @contacts;
+ $c->stash->{filter_categories} = \@categories;
+
+
+ my $category = $c->req->param('filter_category');
+ my %categories_mapped = map { $_ => 1 } @categories;
+ if ( defined $category && $categories_mapped{$category} ) {
+ $c->stash->{filter_category} = $category;
+ }
+}
+
=head2 /ajax
Handle the ajax calls that the map makes when it is dragged. The info returned
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index bbef1f8d8..b3d341a68 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -28,17 +28,26 @@ sub my : Path : Args(0) {
my $p_page = $c->req->params->{p} || 1;
my $u_page = $c->req->params->{u} || 1;
+ $c->forward( '/reports/stash_report_filter_status' );
+
my $pins = [];
my $problems = {};
+ my $states = $c->stash->{filter_problem_states};
my $params = {
- state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
+ state => [ keys %$states ],
};
$params = {
%{ $c->cobrand->problems_clause },
%$params
} if $c->cobrand->problems_clause;
+ my $category = $c->req->param('filter_category');
+ if ( $category ) {
+ $params->{category} = $category;
+ $c->stash->{filter_category} = $category;
+ }
+
my $rs = $c->user->problems->search( $params, {
order_by => { -desc => 'confirmed' },
rows => 50
@@ -55,6 +64,7 @@ sub my : Path : Args(0) {
};
my $state = $problem->is_fixed ? 'fixed' : $problem->is_closed ? 'closed' : 'confirmed';
push @{ $problems->{$state} }, $problem;
+ push @{ $problems->{all} }, $problem;
}
$c->stash->{problems_pager} = $rs->pager;
$c->stash->{problems} = $problems;
@@ -71,6 +81,14 @@ sub my : Path : Args(0) {
$c->stash->{updates} = \@updates;
$c->stash->{updates_pager} = $rs->pager;
+ my @categories = $c->user->problems->search( undef, {
+ columns => [ 'category' ],
+ distinct => 1,
+ order_by => [ 'category' ],
+ } )->all;
+ @categories = map { $_->category } @categories;
+ $c->stash->{filter_categories} = \@categories;
+
$c->stash->{page} = 'my';
FixMyStreet::Map::display_map(
$c,
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;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index abf5d4fb5..9f44ca758 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -340,6 +340,16 @@ sub reports_per_page {
return FixMyStreet->config('ALL_REPORTS_PER_PAGE') || 100;
}
+=head2 reports_ordering
+
+The order_by clause to use for reports on all reports page
+
+=cut
+
+sub reports_ordering {
+ return { -desc => 'lastupdate' };
+}
+
=head2 on_map_list_limit
Return the maximum number of items to be given in the list of reports on the map
@@ -356,6 +366,14 @@ Return the default maximum age for pins.
sub on_map_default_max_pin_age { return '6 months'; }
+=head2 on_map_default_status
+
+Return the default ?status= query parameter to use for filter on map page.
+
+=cut
+
+sub on_map_default_status { return 'all'; }
+
=head2 allow_photo_upload
Return a boolean indicating whether the cobrand allows photo uploads
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index bee2e9bce..e55c26cd8 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -687,14 +687,14 @@ sub processed_summary_string {
}
if ($problem->can_display_external_id) {
if ($duration_clause) {
- $external_ref_clause = sprintf(_('council ref: %s'), $problem->external_id);
+ $external_ref_clause = '<strong>' . sprintf(_('Council ref:&nbsp;%s'), $problem->external_id) . '.</strong>';
} else {
- $external_ref_clause = sprintf(_('%s ref:&nbsp;%s'), $problem->external_body, $problem->external_id);
+ $external_ref_clause = '<strong>' . sprintf(_('%s ref:&nbsp;%s'), $problem->external_body, $problem->external_id) . '.</strong>';
}
}
if ($duration_clause and $external_ref_clause) {
- return "$duration_clause, $external_ref_clause"
- } else {
+ return "$duration_clause. $external_ref_clause"
+ } else {
return $duration_clause || $external_ref_clause
}
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
index 91c44d5f4..a0ccb8a6d 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
@@ -5,11 +5,15 @@ use strict;
use warnings;
sub nearby {
- my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval ) = @_;
+ my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval, $category, $states ) = @_;
+
+ unless ( $states ) {
+ $states = FixMyStreet::DB::Result::Problem->visible_states();
+ }
my $params = {
non_public => 0,
- state => [ FixMyStreet::DB::Result::Problem::visible_states() ],
+ state => [ keys %$states ],
};
$params->{'current_timestamp-lastupdate'} = { '<', \"'$interval'::interval" }
if $interval;
@@ -19,6 +23,7 @@ sub nearby {
%{ $c->cobrand->problems_clause },
%$params
} if $c->cobrand->problems_clause;
+ $params->{category} = $category if $category;
my $attrs = {
prefetch => 'problem',
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 7a50a3146..7885c28b3 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -131,20 +131,25 @@ sub _recent {
# Problems around a location
sub around_map {
- my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit ) = @_;
+ my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit, $category, $states ) = @_;
my $attr = {
order_by => { -desc => 'created' },
};
$attr->{rows} = $limit if $limit;
+ unless ( $states ) {
+ $states = FixMyStreet::DB::Result::Problem->visible_states();
+ }
+
my $q = {
non_public => 0,
- state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
+ state => [ keys %$states ],
latitude => { '>=', $min_lat, '<', $max_lat },
longitude => { '>=', $min_lon, '<', $max_lon },
};
$q->{'current_timestamp - lastupdate'} = { '<', \"'$interval'::interval" }
if $interval;
+ $q->{category} = $category if $category;
my @problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->all };
return \@problems;
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm
index 7d490fde3..0fa23d081 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -55,7 +55,7 @@ sub display_map {
}
sub map_features {
- my ( $c, $lat, $lon, $interval ) = @_;
+ my ( $c, $lat, $lon, $interval, $category, $states ) = @_;
# TODO - be smarter about calculating the surrounding square
# use deltas that are roughly 500m in the UK - so we get a 1 sq km search box
@@ -65,12 +65,12 @@ sub map_features {
$c, $lat, $lon,
$lon - $lon_delta, $lat - $lat_delta,
$lon + $lon_delta, $lat + $lat_delta,
- $interval
+ $interval, $category, $states
);
}
sub map_features_bounds {
- my ( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval ) = @_;
+ my ( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category, $states ) = @_;
my $lat = ( $max_lat + $min_lat ) / 2;
my $lon = ( $max_lon + $min_lon ) / 2;
@@ -78,20 +78,21 @@ sub map_features_bounds {
$c, $lat, $lon,
$min_lon, $min_lat,
$max_lon, $max_lat,
- $interval
+ $interval, $category,
+ $states
);
}
sub _map_features {
- my ( $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, $interval ) = @_;
+ my ( $c, $lat, $lon, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category, $states ) = @_;
# list of problems around map can be limited, but should show all pins
my $around_limit = $c->cobrand->on_map_list_limit || undef;
my @around_args = ( $min_lat, $max_lat, $min_lon, $max_lon, $interval );
- my $around_map = $c->cobrand->problems->around_map( @around_args, undef );
+ my $around_map = $c->cobrand->problems->around_map( @around_args, undef, $category, $states );
my $around_map_list = $around_limit
- ? $c->cobrand->problems->around_map( @around_args, $around_limit )
+ ? $c->cobrand->problems->around_map( @around_args, $around_limit, $category, $states )
: $around_map;
my $dist;
@@ -105,7 +106,7 @@ sub _map_features {
my $limit = 20;
my @ids = map { $_->id } @$around_map_list;
my $nearby = $c->model('DB::Nearby')->nearby(
- $c, $dist, \@ids, $limit, $lat, $lon, $interval
+ $c, $dist, \@ids, $limit, $lat, $lon, $interval, $category, $states
);
return ( $around_map, $around_map_list, $nearby, $dist );
@@ -116,9 +117,13 @@ sub map_pins {
my $bbox = $c->req->param('bbox');
my ( $min_lon, $min_lat, $max_lon, $max_lat ) = split /,/, $bbox;
+ my $category = $c->req->param('filter_category');
+
+ $c->forward( '/reports/stash_report_filter_status' );
+ my $states = $c->stash->{filter_problem_states};
my ( $around_map, $around_map_list, $nearby, $dist ) =
- FixMyStreet::Map::map_features_bounds( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval );
+ FixMyStreet::Map::map_features_bounds( $c, $min_lon, $min_lat, $max_lon, $max_lat, $interval, $category, $states );
# create a list of all the pins
my @pins = map {
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index cd846dcd8..bd2ca4096 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -320,6 +320,7 @@ sub extract_problem_meta {
my $result = scraper {
process 'div#side p em', 'meta', 'TEXT';
process '.problem-header p em', 'meta', 'TEXT';
+ process '.problem-header p.report_meta_info', 'meta', 'TEXT';
}
->scrape( $mech->response );