aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm292
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm22
-rw-r--r--perllib/FixMyStreet/Cobrand/FiksGataMi.pm15
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm49
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm4
-rw-r--r--t/app/controller/reports.t5
-rwxr-xr-xtemplates/web/default/reports/body.html12
-rwxr-xr-xtemplates/web/default/reports/index.html16
-rwxr-xr-xtemplates/web/emptyhomes/reports/body.html2
-rwxr-xr-xtemplates/web/emptyhomes/reports/index.html14
-rwxr-xr-xtemplates/web/fiksgatami/nn/reports/index.html16
-rwxr-xr-xtemplates/web/fiksgatami/reports/index.html14
-rwxr-xr-xtemplates/web/fixmybarangay/reports/index.html17
14 files changed, 241 insertions, 243 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index ec722fd6f..630409227 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -31,33 +31,9 @@ sub index : Path : Args(0) {
my ( $self, $c ) = @_;
# Fetch all areas of the types we're interested in
- my $areas_info;
- eval {
- my $area_types = $c->cobrand->area_types;
- $areas_info = mySociety::MaPit::call('areas', $area_types,
- min_generation => $c->cobrand->area_min_generation
- );
- };
- if ($@) {
- $c->stash->{message} = _("Unable to look up areas in MaPit. Please try again later.") . ' ' .
- sprintf(_('The error was: %s'), $@);
- $c->stash->{template} = 'errors/generic.html';
- return;
- }
-
- # For each area, add its link and perhaps alter its name if we need to for
- # places with the same name.
- foreach (values %$areas_info) {
- $_->{url} = $c->uri_for( '/reports/' . $c->cobrand->short_name( $_, $areas_info ) );
- if ($_->{parent_area} && $_->{url} =~ /,|%2C/) {
- $_->{name} .= ', ' . $areas_info->{$_->{parent_area}}{name};
- }
- }
-
- $c->stash->{areas_info} = $areas_info;
- my @keys = sort { strcoll($areas_info->{$a}{name}, $areas_info->{$b}{name}) } keys %$areas_info;
- @keys = $c->cobrand->filter_all_council_ids_list( @keys );
- $c->stash->{areas_info_sorted} = [ map { $areas_info->{$_} } @keys ];
+ my @bodies = $c->model('DB::Body')->all;
+ @bodies = sort { strcoll($a->name, $b->name) } @bodies;
+ $c->stash->{bodies} = \@bodies;
eval {
my $data = File::Slurp::read_file(
@@ -99,21 +75,20 @@ Show the summary page for a particular ward.
=cut
sub ward : Path : Args(2) {
- my ( $self, $c, $council, $ward ) = @_;
+ my ( $self, $c, $body, $ward ) = @_;
- $c->forward( 'body_check', [ $council ] );
+ $c->forward( 'body_check', [ $body ] );
$c->forward( 'ward_check', [ $ward ] )
if $ward;
- $c->forward( 'load_parent' );
- $c->forward( 'check_canonical_url', [ $council ] );
+ $c->forward( 'check_canonical_url', [ $body ] );
$c->forward( 'load_and_group_problems' );
- my $council_short = $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} );
- $c->stash->{rss_url} = '/rss/reports/' . $council_short;
+ my $body_short = $c->cobrand->short_name( $c->stash->{body} );
+ $c->stash->{rss_url} = '/rss/reports/' . $body_short;
$c->stash->{rss_url} .= '/' . $c->cobrand->short_name( $c->stash->{ward} )
if $c->stash->{ward};
- $c->stash->{council_url} = '/reports/' . $council_short;
+ $c->stash->{body_url} = '/reports/' . $body_short;
$c->stash->{stats} = $c->cobrand->get_report_stats();
@@ -124,7 +99,7 @@ sub ward : Path : Args(2) {
$c,
latitude => @$pins ? $pins->[0]{latitude} : 0,
longitude => @$pins ? $pins->[0]{longitude} : 0,
- area => $c->stash->{ward} ? $c->stash->{ward}->{id} : $c->stash->{council}->{id},
+ area => $c->stash->{ward} ? $c->stash->{ward}->{id} : $c->stash->{body}->area_id,
pins => $pins,
any_zoom => 1,
);
@@ -132,64 +107,121 @@ sub ward : Path : Args(2) {
$c->cobrand->tweak_all_reports_map( $c );
# List of wards
- # Ignore external_body special council thing
- unless ($c->stash->{ward} || !$c->stash->{council}->{id}) {
- my $children = mySociety::MaPit::call('area/children', [ $c->stash->{council}->{id} ],
+ # Ignore external_body special body thing
+ unless ($c->stash->{ward} || !$c->stash->{body}->id) {
+ my $children = mySociety::MaPit::call('area/children', [ $c->stash->{body}->area_id ],
type => $c->cobrand->area_types_children,
);
- foreach (values %$children) {
- $_->{url} = $c->uri_for( $c->stash->{council_url}
- . '/' . $c->cobrand->short_name( $_ )
- );
+ unless ($children->{error}) {
+ foreach (values %$children) {
+ $_->{url} = $c->uri_for( $c->stash->{body_url}
+ . '/' . $c->cobrand->short_name( $_ )
+ );
+ }
+ $c->stash->{children} = $children;
}
- $c->stash->{children} = $children;
}
}
-sub rss_body : Regex('^rss/(reports|area)$') : Args(1) {
- my ( $self, $c, $body ) = @_;
- $c->detach( 'rss_ward', [ $body ] );
+sub rss_area : Path('/rss/area') : Args(1) {
+ my ( $self, $c, $area ) = @_;
+ $c->detach( 'rss_area_ward', [ $area ] );
}
-sub rss_ward : Regex('^rss/(reports|area)$') : Args(2) {
- my ( $self, $c, $council, $ward ) = @_;
-
- my ( $rss ) = $c->req->captures->[0];
+sub rss_area_ward : Path('/rss/area') : Args(2) {
+ my ( $self, $c, $area, $ward ) = @_;
$c->stash->{rss} = 1;
- $c->forward( 'body_check', [ $council ] );
- $c->forward( 'ward_check', [ $ward ] ) if $ward;
+ # area_check
- if ($rss eq 'area' && $c->stash->{council}{type} ne 'DIS' && $c->stash->{council}{type} ne 'CTY') {
- # Two possibilites are the same for one-tier councils, so redirect one to the other
- $c->detach( 'redirect_area' );
+ $area =~ s/\+/ /g;
+ $area =~ s/\.html//;
+
+ # If we're passed an ID number (don't think this is used anywhere, it
+ # certainly shouldn't be), just look that up on mapit and redirect
+ if ($area =~ /^\d+$/) {
+ my $council = mySociety::MaPit::call('area', $area);
+ $c->detach( 'redirect_index') if $council->{error};
+ $c->stash->{body} = $council;
+ $c->detach( 'redirect_body' );
+ }
+
+ # We must now have a string to check on mapit
+ my $areas = mySociety::MaPit::call( 'areas', $area,
+ type => $c->cobrand->area_types,
+ );
+
+ if (keys %$areas == 1) {
+ ($c->stash->{area}) = values %$areas;
+ } else {
+ foreach (keys %$areas) {
+ if (lc($areas->{$_}->{name}) eq lc($area) || $areas->{$_}->{name} =~ /^\Q$area\E (Borough|City|District|County) Council$/i) {
+ $c->stash->{area} = $areas->{$_};
+ }
+ }
}
- my $url = $c->cobrand->short_name( $c->stash->{council} );
- $url .= '/' . $c->cobrand->short_name( $c->stash->{ward} ) if $c->stash->{ward};
+ $c->forward( 'ward_check', [ $ward ] ) if $ward;
+
+ my $url = $c->cobrand->short_name( $c->stash->{area} );
+ $url .= '/' . $c->cobrand->short_name( $c->stash->{ward} ) if $c->stash->{ward};
$c->stash->{qs} = "/$url";
- if ( $rss eq 'area' && $c->stash->{ward} ) {
+ if ($c->stash->{area}{type} ne 'DIS' && $c->stash->{area}{type} ne 'CTY') {
+ # UK-specific types - two possibilites are the same for one-tier councils, so redirect one to the other
+ # With bodies, this should presumably redirect if only one body covers
+ # the area, and then it will need that body's name (rather than
+ # assuming as now it is the same as the area)
+ $c->stash->{body} = $c->stash->{area};
+ $c->detach( 'redirect_body' );
+ }
+
+ $c->stash->{type} = 'area_problems';
+ if ( $c->stash->{ward} ) {
# All problems within a particular ward
- $c->stash->{type} = 'area_problems';
$c->stash->{title_params} = { NAME => $c->stash->{ward}{name} };
$c->stash->{db_params} = [ $c->stash->{ward}->{id} ];
- } elsif ( $rss eq 'area' ) {
- # Problems within a particular council
- $c->stash->{type} = 'area_problems';
- $c->stash->{title_params} = { NAME => $c->stash->{council}{name} };
- $c->stash->{db_params} = [ $c->stash->{council}->{id} ];
- } elsif ($c->stash->{ward}) {
+ } else {
+ # Problems within a particular area
+ $c->stash->{title_params} = { NAME => $c->stash->{area}->{name} };
+ $c->stash->{db_params} = [ $c->stash->{area}->{id} ];
+ }
+
+ # Send on to the RSS generation
+ $c->forward( '/rss/output' );
+
+}
+
+sub rss_body : Path('/rss/reports') : Args(1) {
+ my ( $self, $c, $body ) = @_;
+ $c->detach( 'rss_ward', [ $body ] );
+}
+
+sub rss_ward : Path('/rss/reports') : Args(2) {
+ my ( $self, $c, $body, $ward ) = @_;
+
+ $c->stash->{rss} = 1;
+
+ $c->forward( 'body_check', [ $body ] );
+ $c->forward( 'ward_check', [ $ward ] ) if $ward;
+
+ my $url = $c->cobrand->short_name( $c->stash->{body} );
+ $url .= '/' . $c->cobrand->short_name( $c->stash->{ward} ) if $c->stash->{ward};
+ $c->stash->{qs} = "/$url";
+
+ if ($c->stash->{ward}) {
# Problems sent to a council, restricted to a ward
$c->stash->{type} = 'ward_problems';
- $c->stash->{title_params} = { COUNCIL => $c->stash->{council}{name}, WARD => $c->stash->{ward}{name} };
- $c->stash->{db_params} = [ $c->stash->{council}->{id}, $c->stash->{ward}->{id} ];
+ $c->stash->{title_params} = { COUNCIL => $c->stash->{body}->name, WARD => $c->stash->{ward}{name} };
+ $c->stash->{db_params} = [ $c->stash->{body}->id, $c->stash->{ward}->{id} ];
} else {
# Problems sent to a council
$c->stash->{type} = 'council_problems';
- $c->stash->{title_params} = { COUNCIL => $c->stash->{council}{name} };
- $c->stash->{db_params} = [ $c->stash->{council}->{id}, $c->stash->{council}->{id} ];
+ $c->stash->{title_params} = { COUNCIL => $c->stash->{body}->name };
+ # XXX This looks up in both bodies_str and areas, but is only using body ID.
+ # This will not work properly in any install where body IDs are not === area IDs.
+ $c->stash->{db_params} = [ $c->stash->{body}->id, $c->stash->{body}->id ];
}
# Send on to the RSS generation
@@ -198,60 +230,56 @@ sub rss_ward : Regex('^rss/(reports|area)$') : Args(2) {
=head2 body_check
-This action checks the council or external_body name (or code) given in a URI
-exists, is valid and so on. If it is, it stores the area or body in the stash,
-otherwise it redirects to the all reports page.
+This action checks the body name (or code) given in a URI exists, is valid and
+so on. If it is, it stores the body in the stash, otherwise it redirects to the
+all reports page.
=cut
sub body_check : Private {
- my ( $self, $c, $q_council ) = @_;
+ my ( $self, $c, $q_body ) = @_;
- $q_council =~ s/\+/ /g;
- $q_council =~ s/\.html//;
+ $q_body =~ s/\+/ /g;
+ $q_body =~ s/\.html//;
# Check cobrand specific incantations - e.g. ONS codes for UK,
# Oslo/ kommunes sharing a name in Norway
- return if $c->cobrand->reports_body_check( $c, $q_council );
+ return if $c->cobrand->reports_body_check( $c, $q_body );
# If we're passed an ID number (don't think this is used anywhere, it
# certainly shouldn't be), just look that up on MaPit and redirect
- if ($q_council =~ /^\d+$/) {
- my $council = mySociety::MaPit::call('area', $q_council);
- $c->detach( 'redirect_index') if $council->{error};
- $c->stash->{council} = $council;
- $c->detach( 'redirect_area' );
+ if ($q_body =~ /^\d+$/) {
+ my $area = mySociety::MaPit::call('area', $q_body);
+ $c->detach( 'redirect_index') if $area->{error};
+ $c->stash->{body} = $area;
+ $c->detach( 'redirect_body' );
}
if ( $c->cobrand->reports_by_body ) {
- my $problem = $c->cobrand->problems->search({ 'lower(me.external_body)' => lc $q_council }, { columns => [ 'external_body' ], rows => 1 })->single;
+ my $problem = $c->cobrand->problems->search({ 'lower(me.external_body)' => lc $q_body }, { columns => [ 'external_body' ], rows => 1 })->single;
if ( $problem ) {
- # If external_body, put as a council with ID 0 for the moment.
- $c->stash->{council} = { id => 0, name => $problem->external_body };
+ # If external_body, put as a body with ID 0 for the moment.
+ $c->stash->{body} = $c->model('DB::Body')->new( { id => 0, name => $problem->external_body } );
return;
}
}
# We must now have a string to check
- my $area_types = $c->cobrand->area_types;
- my $areas = mySociety::MaPit::call( 'areas', $q_council,
- type => $area_types,
- min_generation => $c->cobrand->area_min_generation
- );
+ my @bodies = $c->model('DB::Body')->search( { name => { -like => "$q_body%" } } )->all;
- if (keys %$areas == 1) {
- ($c->stash->{council}) = values %$areas;
+ if (@bodies == 1) {
+ $c->stash->{body} = $bodies[0];
return;
} else {
- foreach (keys %$areas) {
- if (lc($areas->{$_}->{name}) eq lc($q_council) || $areas->{$_}->{name} =~ /^\Q$q_council\E (Borough|City|District|County) Council$/i) {
- $c->stash->{council} = $areas->{$_};
+ foreach (@bodies) {
+ if (lc($_->name) eq lc($q_body) || $_->name =~ /^\Q$q_body\E (Borough|City|District|County) Council$/i) {
+ $c->stash->{body} = $_;
return;
}
}
}
- # No result, bad council name.
+ # No result, bad body name.
$c->detach( 'redirect_index' );
}
@@ -259,7 +287,7 @@ sub body_check : Private {
This action checks the ward name from a URI exists and is part of the right
parent, already found with body_check. It either stores the ward Area if
-okay, or redirects to the council page if bad.
+okay, or redirects to the body page if bad.
=cut
@@ -270,48 +298,41 @@ sub ward_check : Private {
$ward =~ s/\.html//;
$ward =~ s{_}{/}g;
- my $council = $c->stash->{council};
+ # Could be from RSS area, or body...
+ my $parent_id;
+ if ( $c->stash->{body} ) {
+ $parent_id = $c->stash->{body}->area_id;
+ } else {
+ $parent_id = $c->stash->{area}->{id};
+ }
my $qw = mySociety::MaPit::call('areas', $ward,
type => $c->cobrand->area_types_children,
- min_generation => $c->cobrand->area_min_generation
);
foreach my $area (sort { $a->{name} cmp $b->{name} } values %$qw) {
- if ($area->{parent_area} == $council->{id}) {
+ if ($area->{parent_area} == $parent_id) {
$c->stash->{ward} = $area;
return;
}
}
# Given a false ward name
- $c->detach( 'redirect_area' );
-}
-
-sub load_parent : Private {
- my ( $self, $c ) = @_;
-
- my $council = $c->stash->{council};
- my $areas_info;
- if ($council->{parent_area}) {
- $c->stash->{areas_info} = mySociety::MaPit::call('areas', [ $council->{id}, $council->{parent_area} ])
- } else {
- $c->stash->{areas_info} = { $council->{id} => $council };
- }
+ $c->detach( 'redirect_body' );
}
=head2 check_canonical_url
-Given an already found (case-insensitively) council, check what URL
+Given an already found (case-insensitively) body, check what URL
we are at and redirect accordingly if different.
=cut
sub check_canonical_url : Private {
- my ( $self, $c, $q_council ) = @_;
+ my ( $self, $c, $q_body ) = @_;
- my $council_short = $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} );
- my $url_short = URI::Escape::uri_escape_utf8($q_council);
+ my $body_short = $c->cobrand->short_name( $c->stash->{body} );
+ my $url_short = URI::Escape::uri_escape_utf8($q_body);
$url_short =~ s/%2B/+/g;
- $c->detach( 'redirect_area' ) unless $council_short eq $url_short;
+ $c->detach( 'redirect_body' ) unless $body_short eq $url_short;
}
sub load_and_group_problems : Private {
@@ -327,20 +348,20 @@ sub load_and_group_problems : Private {
$where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' };
$where->{bodies_str} = [
undef,
- $c->stash->{council}->{id},
- { 'like', $c->stash->{council}->{id} . ',%' },
- { 'like', '%,' . $c->stash->{council}->{id} },
+ $c->stash->{body}->id,
+ { 'like', $c->stash->{body}->id . ',%' },
+ { 'like', '%,' . $c->stash->{body}->id },
];
- } elsif ($c->stash->{council} && $c->stash->{council}->{id} == 0) {
+ } elsif ($c->stash->{body} && $c->stash->{body}->id == 0) {
# A proxy for an external_body
- $where->{'lower(external_body)'} = lc $c->stash->{council}->{name};
- } elsif ($c->stash->{council}) {
- $where->{areas} = { 'like', '%,' . $c->stash->{council}->{id} . ',%' };
+ $where->{'lower(external_body)'} = lc $c->stash->{body}->name;
+ } elsif ($c->stash->{body}) {
+ $where->{areas} = { 'like', '%,' . $c->stash->{body}->id . ',%' };
$where->{bodies_str} = [
undef,
- $c->stash->{council}->{id},
- { 'like', $c->stash->{council}->{id} . ',%' },
- { 'like', '%,' . $c->stash->{council}->{id} },
+ $c->stash->{body}->id,
+ { 'like', $c->stash->{body}->id . ',%' },
+ { 'like', '%,' . $c->stash->{body}->id },
];
}
my $problems = $c->cobrand->problems->search(
@@ -363,21 +384,20 @@ sub load_and_group_problems : Private {
$problems = $problems->cursor; # Raw DB cursor for speed
my ( %problems, @pins );
- my $re_councils = join('|', keys %{$c->stash->{areas_info}});
my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo' );
while ( my @problem = $problems->next ) {
my %problem = zip @cols, @problem;
$problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}};
$c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker );
- if ( !$c->stash->{council}->{id} ) {
+ if ( !$c->stash->{body}->id ) {
# An external_body entry
add_row( \%problem, 0, \%problems, \@pins );
next;
}
if ( !$problem{bodies_str} ) {
- # Problem was not sent to any body, add to possible councils XXX
+ # Problem was not sent to any body, add to all possible areas XXX
$problem{bodies} = 0;
- while ($problem{areas} =~ /,($re_councils)(?=,)/g) {
+ while ($problem{areas} =~ /,(\d+)(?=,)/g) {
add_row( \%problem, $1, \%problems, \@pins );
}
} else {
@@ -387,7 +407,7 @@ sub load_and_group_problems : Private {
my @bodies = split( /,/, $bodies );
$problem{bodies} = scalar @bodies;
foreach ( @bodies ) {
- next if $_ != $c->stash->{council}->{id};
+ next if $_ != $c->stash->{body}->id;
add_row( \%problem, $_, \%problems, \@pins );
}
}
@@ -407,20 +427,20 @@ sub redirect_index : Private {
$c->res->redirect( $c->uri_for($url) );
}
-sub redirect_area : Private {
+sub redirect_body : Private {
my ( $self, $c ) = @_;
my $url = '';
$url .= "/rss" if $c->stash->{rss};
$url .= '/reports';
- $url .= '/' . $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} );
+ $url .= '/' . $c->cobrand->short_name( $c->stash->{body} );
$url .= '/' . $c->cobrand->short_name( $c->stash->{ward} )
if $c->stash->{ward};
$c->res->redirect( $c->uri_for($url) );
}
sub add_row {
- my ( $problem, $council, $problems, $pins ) = @_;
- push @{$problems->{$council}}, $problem;
+ my ( $problem, $body, $problems, $pins ) = @_;
+ push @{$problems->{$body}}, $problem;
push @$pins, {
latitude => $problem->{latitude},
longitude => $problem->{longitude},
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 2e3fae72d..c3f8b255e 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -518,7 +518,7 @@ Show the problem creation graph in the admin interface
sub admin_show_creation_graph { 1 }
-=head2 area_types, area_min_generation
+=head2 area_types
The MaPit types this site handles
@@ -526,7 +526,6 @@ The MaPit types this site handles
sub area_types { FixMyStreet->config('MAPIT_TYPES') || [ 'ZZZ' ] }
sub area_types_children { FixMyStreet->config('MAPIT_TYPES_CHILDREN') || [] }
-sub area_min_generation { '' }
=head2 contact_name, contact_email
@@ -559,28 +558,17 @@ sub remove_redundant_areas {
my $all_areas = shift;
}
-=item filter_all_council_ids_list
-
-Removes any council IDs that we don't need from an array and returns the
-filtered array
-
-=cut
-
-sub filter_all_council_ids_list {
- my $self = shift;
- return @_;
-}
-
=item short_name
-Remove extra information from council names for tidy URIs
+Remove extra information from body names for tidy URIs
=cut
sub short_name {
my $self = shift;
- my ($area, $info) = @_;
- my $name = $area->{name};
+ my ($area) = @_;
+
+ my $name = $area->{name} || $area->name;
$name = URI::Escape::uri_escape_utf8($name);
$name =~ s/%20/+/g;
return $name;
diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
index 13dded839..5e90db038 100644
--- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
+++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
@@ -109,24 +109,17 @@ sub remove_redundant_areas {
if $all_areas->{3};
}
-sub filter_all_council_ids_list {
- my $self = shift;
- my @all_councils_ids = @_;
-
- # as above we only want to show Oslo once
- return grep { $_ != 301 } @all_councils_ids;
-}
-
sub short_name {
my $self = shift;
my ($area, $info) = @_;
- if ($area->{name} =~ /^(Os|Nes|V\xe5ler|Sande|B\xf8|Her\xf8y)$/) {
+ my $name = $area->{name} || $area->name;
+
+ if ($name =~ /^(Os|Nes|V\xe5ler|Sande|B\xf8|Her\xf8y)$/) {
my $parent = $info->{$area->{parent_area}}->{name};
- return URI::Escape::uri_escape_utf8("$area->{name}, $parent");
+ return URI::Escape::uri_escape_utf8("$name, $parent");
}
- my $name = $area->{name};
$name =~ s/ & / and /;
$name = URI::Escape::uri_escape_utf8($name);
$name =~ s/%20/+/g;
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index 2ed5bffe3..3ad58437e 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -12,7 +12,6 @@ sub path_to_web_templates {
sub country { return 'GB'; }
sub area_types { [ 'DIS', 'LBO', 'MTD', 'UTA', 'CTY', 'COI', 'LGD' ] }
sub area_types_children { $mySociety::VotingArea::council_child_types }
-sub area_min_generation { 10 }
sub enter_postcode_text {
my ( $self ) = @_;
@@ -115,31 +114,23 @@ sub remove_redundant_areas {
if $all_areas->{2391};
}
-sub filter_all_council_ids_list {
+sub short_name {
my $self = shift;
- my @all_councils_ids = @_;
+ my ($area) = @_;
- # Ignore the four council areas introduced because of generation 15
- # (where we put the new boundaries under the old IDs)
- return grep { $_ < 141648 || $_ > 141651 } @all_councils_ids;
-}
+ my $name = $area->{name} || $area->name;
-sub short_name {
- my $self = shift;
- my ($area, $info) = @_;
- # Special case Durham as it's the only place with two councils of the same name
- return 'Durham+County' if $area->{name} eq 'Durham County Council';
- return 'Durham+City' if $area->{name} eq 'Durham City Council';
-
- my $name = $area->{name};
- $name =~ s/ (Borough|City|District|County) Council$//;
- $name =~ s/ Council$//;
- $name =~ s/ & / and /;
- $name =~ s{/}{_}g;
- $name = URI::Escape::uri_escape_utf8($name);
- $name =~ s/%20/+/g;
- return $name;
+ # Special case Durham as it's the only place with two councils of the same name
+ return 'Durham+County' if $name eq 'Durham County Council';
+ return 'Durham+City' if $name eq 'Durham City Council';
+ $name =~ s/ (Borough|City|District|County) Council$//;
+ $name =~ s/ Council$//;
+ $name =~ s/ & / and /;
+ $name =~ s{/}{_}g;
+ $name = URI::Escape::uri_escape_utf8($name);
+ $name =~ s/%20/+/g;
+ return $name;
}
sub find_closest {
@@ -177,11 +168,11 @@ sub reports_body_check {
if (length($code) == 6) {
my $council = mySociety::MaPit::call( 'area', $area->{parent_area} );
$c->stash->{ward} = $area;
- $c->stash->{council} = $council;
+ $c->stash->{body} = $council;
} else {
- $c->stash->{council} = $area;
+ $c->stash->{body} = $area;
}
- $c->detach( 'redirect_area' );
+ $c->detach( 'redirect_body' );
}
# New ONS codes
@@ -191,11 +182,11 @@ sub reports_body_check {
if ($code =~ /^(E05|W05|S13)/) {
my $council = mySociety::MaPit::call( 'area', $area->{parent_area} );
$c->stash->{ward} = $area;
- $c->stash->{council} = $council;
- $c->detach( 'redirect_area' );
+ $c->stash->{body} = $council;
+ $c->detach( 'redirect_body' );
} elsif ($code =~ /^(W06|S12|E0[6-9]|E10)/) {
- $c->stash->{council} = $area;
- $c->detach( 'redirect_area' );
+ $c->stash->{body} = $area;
+ $c->detach( 'redirect_body' );
}
}
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index e4725d141..73d763a6e 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -69,6 +69,10 @@ __PACKAGE__->has_many(
# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 09:23:59
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tvTHtIa0GrtptadZYHEM1Q
+sub url {
+ my ( $self, $c ) = @_;
+ # XXX $areas_info was used here for Norway parent - needs body parents, I guess
+ return $c->uri_for( '/reports/' . $c->cobrand->short_name( $self ) );
+}
-# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 2d65c8789..32bdcbb4f 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -561,9 +561,7 @@ sub body {
map {
my $name = $_->name;
if (mySociety::Config::get('AREA_LINKS_FROM_PROBLEMS')) {
- '<a href="'
- # XXX . $c->uri_for( '/reports/' . $c->cobrand->short_name( $areas_info->{$_} ) )
- . '">' . $name . '</a>';
+ '<a href="' . $_->url($c) . '">' . $name . '</a>';
} else {
$name;
}
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index 74e4e3d71..503950d8a 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -8,6 +8,10 @@ use DateTime;
ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
+$mech->create_body_ok(2514, 'Birmingham City Council');
+$mech->create_body_ok(2651, 'City of Edinburgh Council');
+$mech->create_body_ok(2504, 'Westminster City Council');
+
$mech->delete_problems_for_body( 2504 );
$mech->delete_problems_for_body( 2651 );
@@ -63,6 +67,7 @@ SKIP: {
skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 )
unless FixMyStreet::Cobrand->exists('fiksgatami');
+ $mech->create_body_ok(3, 'Oslo');
mySociety::MaPit::configure('http://mapit.nuug.no/');
ok $mech->host("fiksgatami.no"), 'change host to fiksgatami';
$mech->get_ok('/reports');
diff --git a/templates/web/default/reports/body.html b/templates/web/default/reports/body.html
index 134c9d4fc..8da5b8e7a 100755
--- a/templates/web/default/reports/body.html
+++ b/templates/web/default/reports/body.html
@@ -5,11 +5,11 @@
END;
%]
[% IF ward %]
- [% name = "$ward.name, $council.name"
+ [% name = "$ward.name, $body.name"
thing = loc('ward')
%]
[% ELSE %]
- [% name = council.name
+ [% name = body.name
thing = loc('council')
%]
[% END %]
@@ -38,13 +38,13 @@
<h1 id="reports_heading">
[% IF ward %]
- [% ward.name %]<span>, </span><a href="[% council_url %]">[% council.name %]</a>
+ [% ward.name %]<span>, </span><a href="[% body_url %]">[% body.name %]</a>
[% ELSE %]
- [% council.name %]
+ [% body.name %]
[% END %]
</h1>
-[% IF council.generation_high == 10 AND c.cobrand.country == 'GB' %]
+[% IF NOT body.area_id AND c.cobrand.country == 'GB' %]
<p id="unknown" class="alert">This council no longer exists.
[% IF council.name.match('Penwith|Kerrier|Carrick|Restormel|Caradon|North Cornwall') %]
Its area is now covered by <a href="/reports/Cornwall">Cornwall Council</a>.
@@ -89,7 +89,7 @@
<section class="full-width">
[% INCLUDE column
- problems = problems.${council.id}
+ problems = problems.${body.id}
%]
</section>
diff --git a/templates/web/default/reports/index.html b/templates/web/default/reports/index.html
index 76c2afcd2..12159d741 100755
--- a/templates/web/default/reports/index.html
+++ b/templates/web/default/reports/index.html
@@ -22,17 +22,17 @@
</thead>
<tbody>
-[% FOREACH area IN areas_info_sorted %]
+[% FOREACH body IN bodies %]
<tr align="center"
-[%- IF area.generation_high == 10 %] class="gone"
+[%- IF NOT body.area_id %] class="gone"
[%- ELSIF ! (loop.count % 2) %] class="a"
[%- END %]>
-<td class="title"><a href="[% area.url %]">[% area.name %]</a></td>
-<td class="data">[% open.${area.id}.new or 0 %]</td>
-<td class="data">[% open.${area.id}.older or 0 %]</td>
-<td class="data">[% open.${area.id}.unknown or 0 %]</td>
-<td class="data">[% fixed.${area.id}.new or 0 %]</td>
-<td class="data">[% fixed.${area.id}.old or 0 %]</td>
+<td class="title"><a href="[% body.url(c) %]">[% body.name %]</a></td>
+<td class="data">[% open.${body.id}.new or 0 %]</td>
+<td class="data">[% open.${body.id}.older or 0 %]</td>
+<td class="data">[% open.${body.id}.unknown or 0 %]</td>
+<td class="data">[% fixed.${body.id}.new or 0 %]</td>
+<td class="data">[% fixed.${body.id}.old or 0 %]</td>
</tr>
[% TRY %][% PROCESS "reports/_extras.html" %][% CATCH file %][% END %]
[% END %]
diff --git a/templates/web/emptyhomes/reports/body.html b/templates/web/emptyhomes/reports/body.html
index 8ba9bf1ca..19de81c36 100755
--- a/templates/web/emptyhomes/reports/body.html
+++ b/templates/web/emptyhomes/reports/body.html
@@ -26,7 +26,7 @@
<div id="side">
-[% IF council.generation_high == 10 AND c.cobrand.country == 'GB' %]
+[% IF NOT body.area_id AND c.cobrand.country == 'GB' %]
<p id="unknown">This council no longer exists.
[% IF council.name.match('Penwith|Kerrier|Carrick|Restormel|Caradon|North Cornwall') %]
Its area is now covered by <a href="/reports/Cornwall">Cornwall Council</a>.
diff --git a/templates/web/emptyhomes/reports/index.html b/templates/web/emptyhomes/reports/index.html
index db506679e..28dea49af 100755
--- a/templates/web/emptyhomes/reports/index.html
+++ b/templates/web/emptyhomes/reports/index.html
@@ -14,17 +14,17 @@
<th>[% loc('Older fixed') %]</th>
</tr>
-[% FOREACH area IN areas_info_sorted %]
+[% FOREACH body IN bodies %]
<tr align="center"
-[%- IF area.generation_high == 10 %] class="gone"
+[%- IF NOT body.area_id %] class="gone"
[%- ELSIF loop.count % 2 %] class="a"
[%- END -%]
>
-<td align="left">[% area.name %]</td>
-<td>[% open.${area.id}.new or 0 %]</td>
-<td>[% (open.${area.id}.older or 0) + (open.${area.id}.unknown or 0) %]</td>
-<td>[% fixed.${area.id}.new or 0 %]</td>
-<td>[% fixed.${area.id}.old or 0 %]</td>
+<td align="left">[% body.name %]</td>
+<td>[% open.${body.id}.new or 0 %]</td>
+<td>[% (open.${body.id}.older or 0) + (open.${body.id}.unknown or 0) %]</td>
+<td>[% fixed.${body.id}.new or 0 %]</td>
+<td>[% fixed.${body.id}.old or 0 %]</td>
</tr>
[% END %]
</table>
diff --git a/templates/web/fiksgatami/nn/reports/index.html b/templates/web/fiksgatami/nn/reports/index.html
index 3cbb2bf8d..05296ba76 100755
--- a/templates/web/fiksgatami/nn/reports/index.html
+++ b/templates/web/fiksgatami/nn/reports/index.html
@@ -14,18 +14,18 @@
<th>[% loc('Older fixed') %]</th>
</tr>
-[% FOREACH area IN areas_info_sorted %]
-[% NEXT IF area.id == 301 %]
+[% FOREACH body IN bodies %]
+[% NEXT IF body.id == 301 %]
<tr align="center"
[%- IF loop.count % 2 %] class="a"
[%- END -%]
>
-<td align="left"><a href="[% area.url %]">[% area.name %]</a></td>
-<td>[% open.${area.id}.new or 0 %]</td>
-<td>[% open.${area.id}.older or 0 %]</td>
-<td>[% open.${area.id}.unknown or 0 %]</td>
-<td>[% fixed.${area.id}.new or 0 %]</td>
-<td>[% fixed.${area.id}.old or 0 %]</td>
+<td align="left"><a href="[% body.url(c) %]">[% body.name %]</a></td>
+<td>[% open.${body.id}.new or 0 %]</td>
+<td>[% open.${body.id}.older or 0 %]</td>
+<td>[% open.${body.id}.unknown or 0 %]</td>
+<td>[% fixed.${body.id}.new or 0 %]</td>
+<td>[% fixed.${body.id}.old or 0 %]</td>
</tr>
[% END %]
</table>
diff --git a/templates/web/fiksgatami/reports/index.html b/templates/web/fiksgatami/reports/index.html
index 1ba90ece3..3235b96c4 100755
--- a/templates/web/fiksgatami/reports/index.html
+++ b/templates/web/fiksgatami/reports/index.html
@@ -14,17 +14,17 @@
<th>[% loc('Older fixed') %]</th>
</tr>
-[% FOREACH area IN areas_info_sorted %]
+[% FOREACH body IN bodies %]
<tr align="center"
[%- IF loop.count % 2 %] class="a"
[%- END -%]
>
-<td align="left"><a href="[% area.url %]">[% area.name %]</a></td>
-<td>[% open.${area.id}.new or 0 %]</td>
-<td>[% open.${area.id}.older or 0 %]</td>
-<td>[% open.${area.id}.unknown or 0 %]</td>
-<td>[% fixed.${area.id}.new or 0 %]</td>
-<td>[% fixed.${area.id}.old or 0 %]</td>
+<td align="left"><a href="[% body.url(c) %]">[% body.name %]</a></td>
+<td>[% open.${body.id}.new or 0 %]</td>
+<td>[% open.${body.id}.older or 0 %]</td>
+<td>[% open.${body.id}.unknown or 0 %]</td>
+<td>[% fixed.${body.id}.new or 0 %]</td>
+<td>[% fixed.${body.id}.old or 0 %]</td>
</tr>
[% END %]
</table>
diff --git a/templates/web/fixmybarangay/reports/index.html b/templates/web/fixmybarangay/reports/index.html
index e46d578ec..a99878c27 100755
--- a/templates/web/fixmybarangay/reports/index.html
+++ b/templates/web/fixmybarangay/reports/index.html
@@ -26,17 +26,16 @@
</thead>
<tbody>
-[% FOREACH area IN areas_info_sorted %]
+[% FOREACH body IN bodies %]
<tr align="center"
-[%- IF area.generation_high == 10 %] class="gone"
-[%- ELSIF ! (loop.count % 2) %] class="a"
+[%- IF ! (loop.count % 2) %] class="a"
[%- END %]>
-<td class="title"><a href="[% area.url %]">[% area.name %]</a></td>
-<td class="data">[% open.${area.id}.new or 0 %]</td>
-<td class="data">[% open.${area.id}.older or 0 %]</td>
-<td class="data">[% open.${area.id}.unknown or 0 %]</td>
-<td class="data">[% fixed.${area.id}.new or 0 %]</td>
-<td class="data">[% fixed.${area.id}.old or 0 %]</td>
+<td class="title"><a href="[% body.url(c) %]">[% body.name %]</a></td>
+<td class="data">[% open.${body.id}.new or 0 %]</td>
+<td class="data">[% open.${body.id}.older or 0 %]</td>
+<td class="data">[% open.${body.id}.unknown or 0 %]</td>
+<td class="data">[% fixed.${body.id}.new or 0 %]</td>
+<td class="data">[% fixed.${body.id}.old or 0 %]</td>
</tr>
[% TRY %][% PROCESS "reports/_extras.html" %][% CATCH file %][% END %]
[% END %]