aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
authorZarino Zappia <mail@zarino.co.uk>2016-09-30 16:34:00 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-10-13 19:22:11 +0100
commita5ef113e2cc3105da41cf5449b505db6fa336c59 (patch)
treec60d906c0b5dd6fc974a35f8e921ae728dab080c /perllib/FixMyStreet
parent3872c39f5426165c3abfe397d15dd2a63f731e26 (diff)
Allow multiple selections in report list filter.
This lets people filter by multiple categories or states. It uses our jQuery multi-select plugin to turn the <select multiple>s into little overlay lists of checkboxes. HTML5 history is also supported.
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App.pm10
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm14
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm8
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm5
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm46
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Nearby.pm4
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm4
-rw-r--r--perllib/FixMyStreet/Map.pm6
8 files changed, 57 insertions, 40 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index 40a99b6d3..ab5e62233 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -447,11 +447,13 @@ a list, with an empty list if no parameter is present.
=cut
sub get_param_list {
- my ($c, $param) = @_;
+ my ($c, $param, $allow_commas) = @_;
+ die unless wantarray;
my $value = $c->req->params->{$param};
- return @$value if ref $value;
- return ($value) if defined $value;
- return ();
+ return () unless defined $value;
+ my @value = ref $value ? @$value : ($value);
+ return map { split /,/, $_ } @value if $allow_commas;
+ return @value;
}
=head2 set_param
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index ec84ca09a..1f45f8029 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -181,7 +181,7 @@ sub display_location : Private {
my ( $on_map_all, $on_map, $nearby, $distance ) =
FixMyStreet::Map::map_features( $c,
latitude => $latitude, longitude => $longitude,
- interval => $interval, category => $c->stash->{filter_category},
+ interval => $interval, categories => $c->stash->{filter_category},
states => $c->stash->{filter_problem_states} );
# copy the found reports to the stash
@@ -258,13 +258,11 @@ sub check_and_stash_category : Private {
)->all;
my @categories = map { $_->category } @contacts;
$c->stash->{filter_categories} = \@categories;
-
-
- my $category = $c->get_param('filter_category');
my %categories_mapped = map { $_ => 1 } @categories;
- if ( defined $category && $categories_mapped{$category} ) {
- $c->stash->{filter_category} = $category;
- }
+
+ my $categories = [ $c->get_param_list('filter_category', 1) ];
+ my @valid_categories = grep { $_ && $categories_mapped{$_} } @$categories;
+ $c->stash->{filter_category} = \@valid_categories;
}
=head2 /ajax
@@ -303,7 +301,7 @@ sub ajax : Path('/ajax') {
my ( $on_map_all, $on_map_list, $nearby, $dist ) =
FixMyStreet::Map::map_features($c,
bbox => $bbox, interval => $interval,
- category => $c->get_param('filter_category'),
+ categories => [ $c->get_param_list('filter_category', 1) ],
states => $c->stash->{filter_problem_states} );
# create a list of all the pins
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index b7fabcf4c..573c41446 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -63,10 +63,10 @@ sub get_problems : Private {
state => [ keys %$states ],
};
- my $category = $c->get_param('filter_category');
- if ( $category ) {
- $params->{category} = $category;
- $c->stash->{filter_category} = $category;
+ my $categories = [ $c->get_param_list('filter_category', 1) ];
+ if ( @$categories ) {
+ $params->{category} = $categories;
+ $c->stash->{filter_category} = $categories;
}
my $rs = $c->stash->{problems_rs}->search( $params, {
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 75f54facf..b3b5d00fd 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -1242,9 +1242,12 @@ sub redirect_to_around : Private {
lat => $c->stash->{latitude},
lon => $c->stash->{longitude},
};
- foreach (qw(pc zoom status filter_category)) {
+ foreach (qw(pc zoom)) {
$params->{$_} = $c->get_param($_);
}
+ foreach (qw(status filter_category)) {
+ $params->{$_} = join(',', $c->get_param_list($_, 1));
+ }
# delete empty values
for ( keys %$params ) {
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 49f477fec..60a7d1726 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -132,7 +132,7 @@ sub ward : Path : Args(2) {
} )->all;
@categories = map { $_->category } @categories;
$c->stash->{filter_categories} = \@categories;
- $c->stash->{filter_category} = $c->get_param('filter_category');
+ $c->stash->{filter_category} = [ $c->get_param_list('filter_category', 1) ];
my $pins = $c->stash->{pins};
@@ -464,23 +464,37 @@ sub redirect_body : Private {
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 'closed' ) {
- $c->stash->{filter_status} = 'closed';
- $c->stash->{filter_problem_states} = FixMyStreet::DB::Result::Problem->closed_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;
+ my @status = $c->get_param_list('status', 1);
+ @status = ($c->cobrand->on_map_default_status) unless @status;
+ my %status = map { $_ => 1 } @status;
+
+ my %filter_problem_states;
+ my %filter_status;
+
+ if ($status{open}) {
+ my $s = FixMyStreet::DB::Result::Problem->open_states();
+ %filter_problem_states = (%filter_problem_states, %$s);
+ $filter_status{open} = 1;
+ }
+ if ($status{closed}) {
+ my $s = FixMyStreet::DB::Result::Problem->closed_states();
+ %filter_problem_states = (%filter_problem_states, %$s);
+ $filter_status{closed} = 1;
+ }
+ if ($status{fixed}) {
+ my $s = FixMyStreet::DB::Result::Problem->fixed_states();
+ %filter_problem_states = (%filter_problem_states, %$s);
+ $filter_status{fixed} = 1;
+ }
+
+ if ($status{all}) {
+ my $s = FixMyStreet::DB::Result::Problem->visible_states();
+ # %filter_status = ();
+ %filter_problem_states = %$s;
}
+ $c->stash->{filter_problem_states} = \%filter_problem_states;
+ $c->stash->{filter_status} = \%filter_status;
return 1;
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
index 9db1c6525..8b8951007 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
@@ -10,7 +10,7 @@ sub to_body {
}
sub nearby {
- my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval, $category, $states ) = @_;
+ my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval, $categories, $states ) = @_;
unless ( $states ) {
$states = FixMyStreet::DB::Result::Problem->visible_states();
@@ -24,7 +24,7 @@ sub nearby {
if $interval;
$params->{id} = { -not_in => $ids }
if $ids;
- $params->{category} = $category if $category;
+ $params->{category} = $categories if $categories && @$categories;
$rs = $c->cobrand->problems_restriction($rs);
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 9ce7da1c0..723a6e7c2 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -140,7 +140,7 @@ sub _recent {
# Problems around a location
sub around_map {
- my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit, $category, $states ) = @_;
+ my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit, $categories, $states ) = @_;
my $attr = {
order_by => { -desc => 'created' },
};
@@ -158,7 +158,7 @@ sub around_map {
};
$q->{'current_timestamp - lastupdate'} = { '<', \"'$interval'::interval" }
if $interval;
- $q->{category} = $category if $category;
+ $q->{category} = $categories if $categories && @$categories;
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 5272e3932..f7caf51d7 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -92,9 +92,9 @@ sub map_features {
my $around_limit = $c->cobrand->on_map_list_limit || undef;
my @around_args = @p{"min_lat", "max_lat", "min_lon", "max_lon", "interval"};
- my $on_map_all = $c->cobrand->problems_on_map->around_map( @around_args, undef, $p{category}, $p{states} );
+ my $on_map_all = $c->cobrand->problems_on_map->around_map( @around_args, undef, $p{categories}, $p{states} );
my $on_map_list = $around_limit
- ? $c->cobrand->problems_on_map->around_map( @around_args, $around_limit, $p{category}, $p{states} )
+ ? $c->cobrand->problems_on_map->around_map( @around_args, $around_limit, $p{categories}, $p{states} )
: $on_map_all;
my $dist = FixMyStreet::Gaze::get_radius_containing_population( $p{latitude}, $p{longitude} );
@@ -102,7 +102,7 @@ sub map_features {
my $limit = 20;
my @ids = map { $_->id } @$on_map_list;
my $nearby = $c->model('DB::Nearby')->nearby(
- $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "interval", "category", "states"}
+ $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "interval", "categories", "states"}
);
return ( $on_map_all, $on_map_list, $nearby, $dist );