aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm136
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm107
-rw-r--r--perllib/FixMyStreet/TestMech.pm18
3 files changed, 152 insertions, 109 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 8df7b880f..6a6e82d02 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -6,6 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; }
use FixMyStreet::Map;
use List::MoreUtils qw(any);
+use Encode;
=head1 NAME
@@ -40,14 +41,139 @@ sub around_index : Path : Args(0) {
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('/') );
- }
-
+ # Try to create a location for whatever we have
+ return
+ unless $c->forward('determine_location_from_coords')
+ || $c->forward('determine_location_from_pc');
+
+ # Check to see if the spot is covered by a council - if not show an error.
+ return unless $c->forward('check_location_is_acceptable');
+
+ # If we have a partial - redirect to /report/new so that it can be
+ # completed.
+ warn "FIXME - implement";
+
+ # Show the nearby reports
+ die "show nearby reports";
}
+=head2 determine_location_from_coords
+
+Use latitude and longitude if provided in parameters.
+
+=cut
+
+sub determine_location_from_coords : Private {
+ my ( $self, $c ) = @_;
+
+ my $latitude = $c->req->param('latitude');
+ my $longitude = $c->req->param('longitude');
+
+ if ( defined $latitude && defined $longitude ) {
+ $c->stash->{latitude} = $latitude;
+ $c->stash->{longitude} = $longitude;
+
+ # Also save the pc if there is one
+ if ( my $pc = $c->req->param('pc') ) {
+ $c->stash->{pc} = $pc;
+ }
+
+ return 1;
+ }
+
+ return;
+}
+
+=head2 determine_location_from_pc
+
+User has searched for a location - try to find it for them.
+
+If one match is found returns true and lat/lng is set.
+
+If several possible matches are found puts an array onto stash so that user can be prompted to pick one and returns false.
+
+If no matches are found returns false.
+
+=cut
+
+sub determine_location_from_pc : Private {
+ my ( $self, $c ) = @_;
+
+ # check for something to search
+ my $pc = $c->req->param('pc') || return;
+ $c->stash->{pc} = $pc; # for template
+
+ my ( $latitude, $longitude, $error ) =
+ eval { FixMyStreet::Geocode::lookup( $pc, $c->req ) };
+
+ # Check that nothing blew up
+ if ($@) {
+ warn "Error: $@";
+ return;
+ }
+
+ # If we got a lat/lng set to stash and return true
+ if ( defined $latitude && defined $longitude ) {
+ $c->stash->{latitude} = $latitude;
+ $c->stash->{longitude} = $longitude;
+ return 1;
+ }
+
+ # $error doubles up to return multiple choices by being an array
+ if ( ref($error) eq 'ARRAY' ) {
+ @$error = map {
+ decode_utf8($_);
+ s/, United Kingdom//;
+ s/, UK//;
+ $_;
+ } @$error;
+ $c->stash->{possible_location_matches} = $error;
+ return;
+ }
+
+ # pass errors back to the template
+ $c->stash->{pc_error} = $error;
+ return;
+}
+
+=head2 check_location_is_acceptable
+
+Find the lat and lon in stash and check that they are acceptable to the council,
+and that they are in UK (if we are in UK).
+
+=cut
+
+sub check_location_is_acceptable : Private {
+ my ( $self, $c ) = @_;
+
+ # These should be set now
+ my $lat = $c->stash->{latitude};
+ my $lon = $c->stash->{longitude};
+
+ # Check this location is okay to be displayed for the cobrand
+ my ( $success, $error_msg ) = $c->cobrand->council_check( #
+ { lat => $lat, lon => $lon },
+ 'submit_problem'
+ );
+
+ # If in UK and we have a lat,lon coocdinate check it is in UK
+ if ( !$error_msg && $lat && $c->config->{COUNTRY} eq 'GB' ) {
+ eval { Utils::convert_latlon_to_en( $lat, $lon ); };
+ $error_msg =
+ _( "We had a problem with the supplied co-ordinates - outside the UK?"
+ ) if $@;
+ }
+
+ # all good
+ return 1 if !$error_msg;
+
+ # show error
+ $c->stash->{pc_error} = $error_msg;
+ return;
+
+}
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 4e077f32b..2dbec4235 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -375,34 +375,12 @@ sub determine_location : Private {
return
unless $c->forward('determine_location_from_tile_click')
- || $c->forward('determine_location_from_coords')
- || $c->forward('determine_location_from_pc')
+ || $c->forward('/around/determine_location_from_coords')
+ || $c->forward('/around/determine_location_from_pc')
|| $c->forward('determine_location_from_report');
- # These should be set now
- my $lat = $c->stash->{latitude};
- my $lon = $c->stash->{longitude};
- # Check this location is okay to be displayed for the cobrand
- my ( $success, $error_msg ) = $c->cobrand->council_check( #
- { lat => $lat, lon => $lon },
- 'submit_problem'
- );
-
- # If in UK and we have a lat,lon coocdinate check it is in UK
- if ( !$error_msg && $lat && $c->config->{COUNTRY} eq 'GB' ) {
- eval { Utils::convert_latlon_to_en( $lat, $lon ); };
- $error_msg =
- _( "We had a problem with the supplied co-ordinates - outside the UK?"
- ) if $@;
- }
-
- # all good
- return 1 if !$error_msg;
-
- # show error
- $c->stash->{pc_error} = $error_msg;
- return;
+ return $c->forward('/around/check_location_is_acceptable');
}
=head2 determine_location_from_tile_click
@@ -456,85 +434,6 @@ sub determine_location_from_tile_click : Private {
return 1;
}
-=head2 determine_location_from_coords
-
-Use latitude and longitude if provided in parameters.
-
-=cut
-
-sub determine_location_from_coords : Private {
- my ( $self, $c ) = @_;
-
- my $latitude = $c->req->param('latitude');
- my $longitude = $c->req->param('longitude');
-
- if ( defined $latitude && defined $longitude ) {
- $c->stash->{latitude} = $latitude;
- $c->stash->{longitude} = $longitude;
-
- # Also save the pc if there is one
- if ( my $pc = $c->req->param('pc') ) {
- $c->stash->{pc} = $pc;
- }
-
- return 1;
- }
-
- return;
-}
-
-=head2 determine_location_from_pc
-
-User has searched for a location - try to find it for them.
-
-If one match is found returns true and lat/lng is set.
-
-If several possible matches are found puts an array onto stash so that user can be prompted to pick one and returns false.
-
-If no matches are found returns false.
-
-=cut
-
-sub determine_location_from_pc : Private {
- my ( $self, $c ) = @_;
-
- # check for something to search
- my $pc = $c->req->param('pc') || return;
- $c->stash->{pc} = $pc; # for template
-
- my ( $latitude, $longitude, $error ) =
- eval { FixMyStreet::Geocode::lookup( $pc, $c->req ) };
-
- # Check that nothing blew up
- if ($@) {
- warn "Error: $@";
- return;
- }
-
- # If we got a lat/lng set to stash and return true
- if ( defined $latitude && defined $longitude ) {
- $c->stash->{latitude} = $latitude;
- $c->stash->{longitude} = $longitude;
- return 1;
- }
-
- # $error doubles up to return multiple choices by being an array
- if ( ref($error) eq 'ARRAY' ) {
- @$error = map {
- decode_utf8($_);
- s/, United Kingdom//;
- s/, UK//;
- $_;
- } @$error;
- $c->stash->{possible_location_matches} = $error;
- return;
- }
-
- # pass errors back to the template
- $c->stash->{pc_error} = $error;
- return;
-}
-
=head2 determine_location_from_report
Use latitude and longitude stored in the report - this is probably result of a
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 26738556d..6a4382c3d 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -204,6 +204,24 @@ sub form_errors {
return $result->{errors} || [];
}
+=head2 page_errors
+
+ my $arrayref = $mech->page_errors;
+
+Find all the form errors on the current page and return them in page order as an
+arrayref of TEXTs. If none found return empty arrayref.
+
+=cut
+
+sub page_errors {
+ my $mech = shift;
+ my $result = scraper {
+ process 'p.error', 'errors[]', 'TEXT';
+ }
+ ->scrape( $mech->response );
+ return $result->{errors} || [];
+}
+
=head2 import_errors
my $arrayref = $mech->import_errors;