aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2017-10-04 18:01:41 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-10-06 13:34:16 +0100
commit32ed127efd57bbb5888a3e35637796852168b319 (patch)
tree206c57b55e3d49a16456596a37a0b98c01502780
parent70ddda2c5e851c012b2bb98ec74c87490be6dad0 (diff)
Allow ward page to show multiple wards.
URLs have to be manually constructed, but specifying multiple ward names separated by "|" will show all those wards and their reports on the map.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm46
-rw-r--r--t/Mock/MapIt.pm16
-rw-r--r--t/app/controller/reports.t12
-rwxr-xr-xtemplates/web/base/reports/body.html7
5 files changed, 59 insertions, 23 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a36271bf7..65c832c55 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
using confirmation by phone text.
- Improved email/phone management in your profile.
- Area summary statistics page in admin #1834
+ - Allow multiple wards to be shown on reports page
- Bugfixes
- Shortlist menu item always remains a link #1855
- Fix encoded entities in RSS output. #1859
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 8f8205719..187dfb299 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -131,9 +131,10 @@ sub ward : Path : Args(2) {
$c->forward('/auth/get_csrf_token');
+ my @wards = split /\|/, $ward || "";
$c->forward( 'body_check', [ $body ] );
- $c->forward( 'ward_check', [ $ward ] )
- if $ward;
+ $c->forward( 'ward_check', [ @wards ] )
+ if @wards;
$c->forward( 'check_canonical_url', [ $body ] );
$c->forward( 'stash_report_filter_status' );
$c->forward( 'load_and_group_problems' );
@@ -166,7 +167,7 @@ sub ward : Path : Args(2) {
my %map_params = (
latitude => @$pins ? $pins->[0]{latitude} : 0,
longitude => @$pins ? $pins->[0]{longitude} : 0,
- area => $c->stash->{ward} ? $c->stash->{ward}->{id} : [ keys %{$c->stash->{body}->areas} ],
+ area => [ $c->stash->{wards} ? map { $_->{id} } @{$c->stash->{wards}} : keys %{$c->stash->{body}->areas} ],
any_zoom => 1,
);
FixMyStreet::Map::display_map(
@@ -176,7 +177,7 @@ sub ward : Path : Args(2) {
$c->cobrand->tweak_all_reports_map( $c );
# List of wards
- if ( !$c->stash->{ward} && $c->stash->{body}->id && $c->stash->{body}->body_areas->first ) {
+ if ( !$c->stash->{wards} && $c->stash->{body}->id && $c->stash->{body}->body_areas->first ) {
my $children = mySociety::MaPit::call('area/children', [ $c->stash->{body}->body_areas->first->area_id ],
type => $c->cobrand->area_types_children,
);
@@ -343,18 +344,20 @@ sub body_check : Private {
=head2 ward_check
-This action checks the ward name from a URI exists and is part of the right
+This action checks the ward names from a URI exists and are part of the right
parent, already found with body_check. It either stores the ward Area if
okay, or redirects to the body page if bad.
=cut
sub ward_check : Private {
- my ( $self, $c, $ward ) = @_;
+ my ( $self, $c, @wards ) = @_;
- $ward =~ s/\+/ /g;
- $ward =~ s/\.html//;
- $ward =~ s{_}{/}g;
+ foreach (@wards) {
+ s/\+/ /g;
+ s/\.html//;
+ s{_}{/}g;
+ }
# Could be from RSS area, or body...
my $parent_id;
@@ -366,15 +369,20 @@ sub ward_check : Private {
$parent_id = $c->stash->{area}->{id};
}
- my $qw = mySociety::MaPit::call('areas', $ward,
+ my $qw = mySociety::MaPit::call('area/children', [ $parent_id ],
type => $c->cobrand->area_types_children,
);
+ my %names = map { $_ => 1 } @wards;
+ my @areas;
foreach my $area (sort { $a->{name} cmp $b->{name} } values %$qw) {
- if ($area->{parent_area} == $parent_id) {
- $c->stash->{ward} = $area;
- return;
- }
+ push @areas, $area if $names{$area->{name}};
+ }
+ if (@areas) {
+ $c->stash->{ward} = $areas[0] if @areas == 1;
+ $c->stash->{wards} = \@areas;
+ return;
}
+
# Given a false ward name
$c->stash->{body} = $c->stash->{area}
unless $c->stash->{body};
@@ -448,8 +456,10 @@ sub load_and_group_problems : Private {
my $problems = $c->cobrand->problems;
- if ($c->stash->{ward}) {
- $where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' };
+ if ($c->stash->{wards}) {
+ $where->{areas} = [
+ map { { 'like', '%,' . $_->{id} . ',%' } } @{$c->stash->{wards}}
+ ];
$problems = $problems->to_body($c->stash->{body});
} elsif ($c->stash->{body}) {
$problems = $problems->to_body($c->stash->{body});
@@ -510,8 +520,8 @@ sub redirect_body : Private {
$url .= "/rss" if $c->stash->{rss};
$url .= '/reports';
$url .= '/' . $c->cobrand->short_name( $c->stash->{body} );
- $url .= '/' . $c->cobrand->short_name( $c->stash->{ward} )
- if $c->stash->{ward};
+ $url .= '/' . join('|', map { $c->cobrand->short_name($_) } @{$c->stash->{wards}})
+ if $c->stash->{wards};
$c->res->redirect( $c->uri_for($url, $c->req->params ) );
}
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm
index 6e3c5d673..8dd10c53d 100644
--- a/t/Mock/MapIt.pm
+++ b/t/Mock/MapIt.pm
@@ -81,10 +81,6 @@ sub dispatch_request {
$self->output({2226 => {parent_area => undef, id => 2226, name => "Gloucestershire County Council", type => "CTY"}});
} elsif ($areas eq 'Cheltenham') {
$self->output({2326 => {parent_area => undef, id => 2326, name => "Cheltenham Borough Council", type => "DIS"}});
- } elsif ($areas eq 'Lansdown and Park') {
- $self->output({22261 => {parent_area => 2226, id => 22261, name => "Lansdown and Park", type => "CED"}});
- } elsif ($areas eq 'Lansdown') {
- $self->output({23261 => {parent_area => 2326, id => 23261, name => "Lansdown", type => "DIW"}});
} elsif ($areas eq 'UTA') {
$self->output({2650 => {parent_area => undef, id => 2650, name => "Aberdeen Council", type => "UTA"}});
}
@@ -104,6 +100,18 @@ sub dispatch_request {
sub (GET + /area/*/children) {
my ($self, $area) = @_;
+ if ($area eq '2514') {
+ return $self->output({
+ 8794 => {parent_area => 2514, id => 8794, name => "Aston", type => "MTW"},
+ 8773 => {parent_area => 2514, id => 8773, name => "Bournville", type => "MTW"},
+ });
+ }
+ if ($area eq '2326') {
+ return $self->output({23261 => {parent_area => 2326, id => 23261, name => "Lansdown", type => "DIW"}});
+ }
+ if ($area eq '2226') {
+ return $self->output({22261 => {parent_area => 2226, id => 22261, name => "Lansdown and Park", type => "CED"}});
+ }
my $response = {
"60705" => { "parent_area" => 2245, "generation_high" => 25, "all_names" => { }, "id" => 60705, "codes" => { "ons" => "00HY226", "gss" => "E04011842", "unit_id" => "17101" }, "name" => "Trowbridge", "country" => "E", "type_name" => "Civil parish/community", "generation_low" => 12, "country_name" => "England", "type" => "CPC" },
"62883" => { "parent_area" => 2245, "generation_high" => 25, "all_names" => { }, "id" => 62883, "codes" => { "ons" => "00HY026", "gss" => "E04011642", "unit_id" => "17205" }, "name" => "Bradford-on-Avon", "country" => "E", "type_name" => "Civil parish/community", "generation_low" => 12, "country_name" => "England", "type" => "CPC" },
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index f3958a0a5..7773223dd 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -114,6 +114,18 @@ FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { body => $body_edin_id } }, 'Submitted dropdown okay' );
+ is $mech->uri->path, '/reports/City+of+Edinburgh+Council';
+
+ subtest "test ward pages" => sub {
+ $mech->get_ok('/reports/Birmingham/Bad-Ward');
+ is $mech->uri->path, '/reports/Birmingham+City+Council';
+ $mech->get_ok('/reports/Birmingham/Aston');
+ is $mech->uri->path, '/reports/Birmingham+City+Council/Aston';
+ $mech->get_ok('/reports/Birmingham/Aston|Bournville');
+ is $mech->uri->path, '/reports/Birmingham+City+Council/Aston%7CBournville';
+ $mech->content_contains('Aston, Bournville');
+ };
+
$mech->get_ok('/reports/Westminster');
};
diff --git a/templates/web/base/reports/body.html b/templates/web/base/reports/body.html
index b6e6df73b..7931ae691 100755
--- a/templates/web/base/reports/body.html
+++ b/templates/web/base/reports/body.html
@@ -42,7 +42,12 @@
[% ward.name %]
</h1>
<a href="[% body_url %]">[% body.name %]</a>
- [% ELSE %]
+ [% ELSIF wards %]
+ <h1 id="reports_heading">
+ [% FOREACH w IN wards %][% w.name %][% IF NOT loop.last %], [% END %][% END %]
+ </h1>
+ <a href="[% body_url %]">[% body.name %]</a>
+ [% ELSE %]
<h1 id="reports_heading">
[% body.name %]
</h1>