From 7f6e0a5fef9d072135cb08b710e9dc6d06d6cac7 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Tue, 12 Apr 2011 15:13:59 +0100 Subject: Create Around controller and implement the easy bits --- .gitignore | 1 + perllib/FixMyStreet/App/Controller/Around.pm | 53 ++++++++++++++++++++++++++ t/app/controller/around.t | 31 +++++++++++++++ t/app/controller/index.t | 7 ++-- templates/web/default/around/around_index.html | 5 +++ 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 perllib/FixMyStreet/App/Controller/Around.pm create mode 100644 t/app/controller/around.t create mode 100644 templates/web/default/around/around_index.html diff --git a/.gitignore b/.gitignore index 0768f83cd..f41cdf212 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ blib/ inc/ .sass-cache _Inline/ +lib diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm new file mode 100644 index 000000000..8df7b880f --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -0,0 +1,53 @@ +package FixMyStreet::App::Controller::Around; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller'; } + +use FixMyStreet::Map; +use List::MoreUtils qw(any); + +=head1 NAME + +FixMyStreet::App::Controller::Around - Catalyst Controller + +=head1 DESCRIPTION + +Allow the user to search for reports around a particular location. + +=head1 METHODS + +=head2 around + +Find the location search and display nearby reports (for pc or lat,lon). + +For x,y searches convert to lat,lon and 301 redirect to them. + +If no search redirect back to the homepage. + +=cut + +sub around_index : Path : Args(0) { + my ( $self, $c ) = @_; + + # check for x,y requests and redirect them to lat,lon + my $x = $c->req->param('x'); + my $y = $c->req->param('y'); + if ( $x || $y ) { + my ( $lat, $lon ) = FixMyStreet::Map::tile_xy_to_wgs84( $x, $y ); + my $ll_uri = $c->uri_for( '/around', { lat => $lat, lon => $lon } ); + $c->res->redirect( $ll_uri, 301 ); + return; + } + + # if there was no search then redirect to the homepage + if ( !any { $c->req->param($_) } qw(pc lat lon) ) { + return $c->res->redirect( $c->uri_for('/') ); + } + + +} + +__PACKAGE__->meta->make_immutable; + +1; diff --git a/t/app/controller/around.t b/t/app/controller/around.t new file mode 100644 index 000000000..021cf8f7d --- /dev/null +++ b/t/app/controller/around.t @@ -0,0 +1,31 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +subtest "check that if no query we get sent back to the homepage" => sub { + $mech->get_ok('/around'); + is $mech->uri->path, '/', "sent back to '/'"; +}; + +# x,y requests were generated by the old map code. We keep the behavior for +# historic links +subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub { + + $mech->get_ok('/around?x=3281&y=1113'); + + # did we redirect to lat,lon? + is $mech->uri->path, '/around', "still on /around"; + is_deeply { $mech->uri->query_form }, + { lat => 51.4998246332569, lon => -0.140137309739907, }, + "lat,lon correctly set"; + + # was it a 301? + is $mech->res->code, 200, "got 200 for final destination"; + is $mech->res->previous->code, 301, "got 301 for redirect"; + +}; + +done_testing(); diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 91f01c943..11c59d289 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -21,10 +21,9 @@ subtest "check that the form goes to /around" => sub { }; subtest "check that requests with pc, x,y or lat,lon go to /around" => sub { - foreach my $test ( - { pc => 'SW1A 1AA', }, - { x => 3281, y => 1113, }, - { lat => 51.50100, lon => -0.14158, }, + foreach my $test ( # + { pc => 'SW1A 1AA' }, # + { lat => 51.50100, lon => -0.14158 }, ) { my $uri = URI->new('http://localhost/'); diff --git a/templates/web/default/around/around_index.html b/templates/web/default/around/around_index.html new file mode 100644 index 000000000..a132be440 --- /dev/null +++ b/templates/web/default/around/around_index.html @@ -0,0 +1,5 @@ +[% INCLUDE 'header.html', title => loc('') %] + + + +[% INCLUDE 'footer.html' %] \ No newline at end of file -- cgit v1.2.3