aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Around.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2013-02-01 15:28:08 +0000
committerMatthew Somerville <matthew@mysociety.org>2013-02-04 06:53:02 +0000
commit488a8f21a0c1bc2b9501c9d94d69db56cccd80ae (patch)
tree68becf501e9492466a80015e8ace9a7fb1557cfa /perllib/FixMyStreet/App/Controller/Around.pm
parent3e0d12e8584d132b573f536ab5cd01e24241827b (diff)
parent28aa1dd7fb1c9bc93aa204afae67cf68fe36ee6b (diff)
Merge remote branch 'origin/zurich'
Conflicts: bin/open311-populate-service-list bin/send-comments bin/update-all-reports conf/crontab.ugly db/schema.sql perllib/FixMyStreet/App/Controller/Admin.pm perllib/FixMyStreet/App/Controller/Report/New.pm perllib/FixMyStreet/App/Controller/Reports.pm perllib/FixMyStreet/Cobrand/Default.pm perllib/FixMyStreet/Cobrand/LichfieldDC.pm perllib/FixMyStreet/DB/Result/Open311conf.pm perllib/FixMyStreet/DB/Result/Problem.pm perllib/FixMyStreet/DB/ResultSet/Problem.pm perllib/FixMyStreet/SendReport.pm perllib/FixMyStreet/SendReport/Email.pm perllib/FixMyStreet/SendReport/Open311.pm perllib/Open311/GetServiceRequestUpdates.pm perllib/Open311/PopulateServiceList.pm t/app/controller/report_new.t t/app/controller/rss.t templates/web/bromley/report/display.html templates/web/default/admin/council_contacts.html templates/web/default/common_header_tags.html templates/web/default/dashboard/index.html templates/web/default/front/stats.html templates/web/default/report/_main.html templates/web/default/report/update-form.html templates/web/emptyhomes/index.html templates/web/emptyhomes/report/display.html templates/web/emptyhomes/report/new/councils_text_all.html templates/web/emptyhomes/reports/body.html templates/web/emptyhomes/reports/index.html templates/web/fixmystreet/report/new/fill_in_details_form.html templates/web/fixmystreet/report/update-form.html web/cobrands/fixmystreet/fixmystreet.js web/js/fixmystreet.js
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Around.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm73
1 files changed, 66 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index f2bb23350..9a754f063 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -44,7 +44,7 @@ sub around_index : Path : Args(0) {
unless $c->forward('/location/determine_location_from_coords')
|| $c->forward('/location/determine_location_from_pc');
- # Check to see if the spot is covered by a council - if not show an error.
+ # Check to see if the spot is covered by a area - if not show an error.
return unless $c->cobrand->moniker eq 'fixmybarangay' || $c->forward('check_location_is_acceptable');
# If we have a partial - redirect to /report/new so that it can be
@@ -192,7 +192,7 @@ sub display_location : Private {
longitude => $p->longitude,
colour => $colour,
id => $p->id,
- title => $p->title,
+ title => $p->title_safe,
}
} @$on_map_all, @$around_map;
}
@@ -212,7 +212,7 @@ sub display_location : Private {
=head2 check_location_is_acceptable
-Find the lat and lon in stash and check that they are acceptable to the council,
+Find the lat and lon in stash and check that they are acceptable to the area,
and that they are in UK (if we are in UK).
=cut
@@ -220,10 +220,10 @@ and that they are in UK (if we are in UK).
sub check_location_is_acceptable : Private {
my ( $self, $c ) = @_;
- # check that there are councils that can accept this location
- $c->stash->{council_check_action} = 'submit_problem';
- $c->stash->{remove_redundant_councils} = 1;
- return $c->forward('/council/load_and_check_councils');
+ # check that there are areas that can accept this location
+ $c->stash->{area_check_action} = 'submit_problem';
+ $c->stash->{remove_redundant_areas} = 1;
+ return $c->forward('/council/load_and_check_areas');
}
=head2 /ajax
@@ -281,6 +281,65 @@ sub ajax : Path('/ajax') {
$c->res->body($body);
}
+
+sub location_autocomplete : Path('/ajax/geocode') {
+ my ( $self, $c ) = @_;
+ $c->res->content_type('application/json; charset=utf-8');
+ unless ( $c->req->param('term') ) {
+ $c->res->status(404);
+ $c->res->body('');
+ return;
+ }
+ # we want the match even if there's no ambiguity, so recommendation doesn't
+ # disappear when it's the last choice being offered in the autocomplete.
+ $c->stash->{allow_single_geocode_match_strings} = 1;
+ return $self->_geocode( $c, $c->req->param('term') );
+}
+
+sub location_lookup : Path('/ajax/lookup_location') {
+ my ( $self, $c ) = @_;
+ $c->res->content_type('application/json; charset=utf-8');
+ unless ( $c->req->param('term') ) {
+ $c->res->status(404);
+ $c->res->body('');
+ return;
+ }
+
+ return $self->_geocode( $c, $c->req->param('term') );
+}
+
+sub _geocode : Private {
+ my ( $self, $c, $term ) = @_;
+
+ my ( $lat, $long, $suggestions ) =
+ FixMyStreet::Geocode::lookup( $c->req->param('term'), $c );
+
+ my ($response, @addresses);
+
+ if ( $lat && $long ) {
+ $response = { latitude => $lat, longitude => $long };
+ } else {
+ if ( ref($suggestions) eq 'ARRAY' ) {
+ foreach (@$suggestions) {
+ push @addresses, decode_utf8($_->{address});
+ }
+ $response = { suggestions => \@addresses };
+ } else {
+ $response = { error => $suggestions };
+ }
+ }
+
+ if ( $c->stash->{allow_single_geocode_match_strings} ) {
+ $response = \@addresses;
+ }
+
+ my $body = JSON->new->utf8(1)->encode(
+ $response
+ );
+ $c->res->body($body);
+
+}
+
__PACKAGE__->meta->make_immutable;
1;