aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-05-06 11:24:28 +0100
committerStruan Donald <struan@exo.org.uk>2011-05-06 11:24:28 +0100
commitaaf60ba622748d8f5a5c4eb16fe663ff9fec5a0d (patch)
tree08d466614a35d5e438c797cb9ae7868aafdcd00b
parent9787559f918a136da3096d05abbb7430731ecaa9 (diff)
created council controller and use that for load and check councils
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm16
-rw-r--r--perllib/FixMyStreet/App/Controller/Council.pm104
-rw-r--r--t/app/controller/alert.t7
-rw-r--r--t/app/controller/council.t9
-rw-r--r--templates/web/default/alert/index.html4
5 files changed, 125 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index b62f8df2a..c18ba657f 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -94,18 +94,10 @@ sub list :Path('list') :Args(0) {
# my $errors = '';
# $errors = '<ul class="error"><li>' . join('</li><li>', @errors) . '</li></ul>' if @errors;
#
-# my $cobrand = Page::get_cobrand($q);
-# my @types = (Cobrand::area_types($cobrand), @$mySociety::VotingArea::council_child_types);
-# my %councils = map { $_ => 1 } Cobrand::area_types($cobrand);
-#
-# my $areas = mySociety::MaPit::call('point', "4326/$lon,$lat", type => \@types);
-# my ($success, $error_msg) = Cobrand::council_check($cobrand, { all_councils => $areas }, $q, 'alert');
-# if (!$success) {
-# return alert_front_page($q, $error_msg);
-# }
-#
-# return alert_front_page($q, _('That location does not appear to be covered by a council, perhaps it is offshore - please try somewhere more specific.')) if keys %$areas == 0;
-#
+ unless ( $c->forward( '/council/load_and_check_councils', 'alert' ) ) {
+ $c->go( 'index' );
+ }
+
# my ($options, $options_start, $options_end);
# if (mySociety::Config::get('COUNTRY') eq 'NO') {
#
diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm
new file mode 100644
index 000000000..61692f17a
--- /dev/null
+++ b/perllib/FixMyStreet/App/Controller/Council.pm
@@ -0,0 +1,104 @@
+package FixMyStreet::App::Controller::Council;
+use Moose;
+use namespace::autoclean;
+
+BEGIN {extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+FixMyStreet::App::Controller::Council - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=head2 load_and_check_councils
+
+Try to load councils for this location and check that we have at least one. If
+there are no councils then return false.
+
+=cut
+
+sub load_and_check_councils : Private {
+ my ( $self, $c, $action ) = @_;
+ my $latitude = $c->stash->{latitude};
+ my $longitude = $c->stash->{longitude};
+
+ # Look up councils and do checks for the point we've got
+ my @area_types = $c->cobrand->area_types();
+
+ # TODO: I think we want in_gb_locale around the next line, needs testing
+ my $all_councils =
+ mySociety::MaPit::call( 'point', "4326/$longitude,$latitude",
+ type => \@area_types );
+
+ # Let cobrand do a check
+ my ( $success, $error_msg ) =
+ $c->cobrand->council_check( { all_councils => $all_councils },
+ $action );
+ if ( !$success ) {
+ $c->stash->{location_error} = $error_msg;
+ return;
+ }
+
+ # edit hash in-place
+ _remove_redundant_councils($all_councils);
+
+ # If we don't have any councils we can't accept the report
+ if ( !scalar keys %$all_councils ) {
+ $c->stash->{location_offshore} = 1;
+ return;
+ }
+
+ # all good if we have some councils left
+ $c->stash->{all_councils} = $all_councils;
+ $c->stash->{all_council_names} =
+ [ map { $_->{name} } values %$all_councils ];
+ return 1;
+}
+
+# TODO - should not be here.
+# These are country specific tweaks that should be in the cobrands
+sub _remove_redundant_councils {
+ my $all_councils = shift;
+
+ # UK specific tweaks
+ if ( FixMyStreet->config('COUNTRY') eq 'GB' ) {
+
+ # Ipswich & St Edmundsbury are responsible for everything in their
+ # areas, not Suffolk
+ delete $all_councils->{2241}
+ if $all_councils->{2446} #
+ || $all_councils->{2443};
+
+ # Norwich is responsible for everything in its areas, not Norfolk
+ delete $all_councils->{2233} #
+ if $all_councils->{2391};
+ }
+
+ # Norway specific tweaks
+ if ( FixMyStreet->config('COUNTRY') eq 'NO' ) {
+
+ # Oslo is both a kommune and a fylke, we only want to show it once
+ delete $all_councils->{301} #
+ if $all_councils->{3};
+ }
+
+}
+
+=head1 AUTHOR
+
+Struan Donald
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t
index 80037fafe..31b5fb3cf 100644
--- a/t/app/controller/alert.t
+++ b/t/app/controller/alert.t
@@ -20,11 +20,14 @@ $mech->title_like(qr/^Local RSS feeds and email alerts/);
$mech->content_contains('Local RSS feeds and email alerts');
$mech->content_contains('html lang="en-gb"');
-$mech->get_ok('/alert/list?pc=ZZ99ZY');
+$mech->get_ok('/alert/list?pc=EH99 1SP');
$mech->title_like(qr/^Local RSS feeds and email alerts/);
-$mech->content_contains('Local RSS feeds and email alerts for ZZ9&nbsp;9ZY');
+$mech->content_contains('Local RSS feeds and email alerts for EH99&nbsp;1SP');
$mech->content_contains('html lang="en-gb"');
$mech->get_ok('/alert/list?pc=High Street');
$mech->content_contains('We found more than one match for that location');
+
+$mech->get_ok('/alert/list?pc=');
+$mech->content_contains('hat location does not appear to be covered by a council');
done_testing();
diff --git a/t/app/controller/council.t b/t/app/controller/council.t
new file mode 100644
index 000000000..d01b3ccd7
--- /dev/null
+++ b/t/app/controller/council.t
@@ -0,0 +1,9 @@
+use strict;
+use warnings;
+use Test::More;
+
+
+use Catalyst::Test 'FixMyStreet::App';
+use FixMyStreet::App::Controller::Council;
+
+done_testing();
diff --git a/templates/web/default/alert/index.html b/templates/web/default/alert/index.html
index fa38d8b7d..908b1b120 100644
--- a/templates/web/default/alert/index.html
+++ b/templates/web/default/alert/index.html
@@ -8,7 +8,9 @@ alerts for all problems within a particular ward or council, or all problems
within a certain distance of a particular location.') %]
</p>
-[% IF location_error %]
+[% IF location_offshore %]
+ <ul class="error"><li>[% loc('That location does not appear to be covered by a council, perhaps it is offshore - please try somewhere more specific.') %]</li></ul>
+[% ELSIF location_error %]
<ul class="error"><li>[% location_error | html %]</li></ul>
[% END %]