diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 59 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FiksGataMi.pm | 83 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode.pm | 16 | ||||
-rwxr-xr-x | t/Page.t | 4 | ||||
-rw-r--r-- | t/app/controller/around.t | 13 | ||||
-rw-r--r-- | templates/web/default/alert/list.html | 2 |
6 files changed, 109 insertions, 68 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 701485676..aa51f1ba3 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -318,11 +318,8 @@ This will canonicalise and prettify the postcode and stick a pretty_pc and prett sub prettify_pc : Private { my ( $self, $c ) = @_; -# FIXME previously this had been run through ent so need to do similar here or in template my $pretty_pc = $c->req->params->{'pc'}; - # my $pretty_pc = $input_h{pc}; - # my $pretty_pc_text;# This one isnt't getting the nbsp. if ( mySociety::PostcodeUtil::is_valid_postcode( $c->req->params->{'pc'} ) ) { $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode( @@ -340,60 +337,6 @@ sub prettify_pc : Private { return 1; } -sub council_options : Private { - my ( $self, $c ) = @_; - - if ( $c->config->{COUNTRY} eq 'NO' ) { - -# my ($options, $options_start, $options_end); -# if (mySociety::Config::get('COUNTRY') eq 'NO') { -# -# my (@options, $fylke, $kommune); -# foreach (values %$areas) { -# if ($_->{type} eq 'NKO') { -# $kommune = $_; -# } else { -# $fylke = $_; -# } -# } -# my $kommune_name = $kommune->{name}; -# my $fylke_name = $fylke->{name}; -# -# if ($fylke->{id} == 3) { # Oslo -# -# push @options, [ 'council', $fylke->{id}, Page::short_name($fylke), -# sprintf(_("Problems within %s"), $fylke_name) ]; -# -# $options_start = "<div><ul id='rss_feed'>"; -# $options = alert_list_options($q, @options); -# $options_end = "</ul>"; -# -# } else { -# -# push @options, -# [ 'area', $kommune->{id}, Page::short_name($kommune), $kommune_name ], -# [ 'area', $fylke->{id}, Page::short_name($fylke), $fylke_name ]; -# $options_start = '<div id="rss_list">'; -# $options = $q->p($q->strong(_('Problems within the boundary of:'))) . -# $q->ul(alert_list_options($q, @options)); -# @options = (); -# push @options, -# [ 'council', $kommune->{id}, Page::short_name($kommune), $kommune_name ], -# [ 'council', $fylke->{id}, Page::short_name($fylke), $fylke_name ]; -# $options .= $q->p($q->strong(_('Or problems reported to:'))) . -# $q->ul(alert_list_options($q, @options)); -# $options_end = $q->p($q->small(_('FixMyStreet sends different categories of problem -#to the appropriate council, so problems within the boundary of a particular council -#might not match the problems sent to that council. For example, a graffiti report -#will be sent to the district council, so will appear in both of the district -#council’s alerts, but will only appear in the "Within the boundary" alert -#for the county council.'))) . '</div><div id="rss_buttons">'; -# -# } -# - } -} - sub process_user : Private { my ( $self, $c ) = @_; @@ -457,7 +400,7 @@ sub setup_council_rss_feeds : Private { } ( $c->stash->{options}, $c->stash->{reported_to_options} ) = - $c->cobrand->council_rss_alert_options( $c->stash->{all_councils} ); + $c->cobrand->council_rss_alert_options( $c->stash->{all_councils}, $c ); return 1; } diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm index aaa5f281b..9516cf0f6 100644 --- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm +++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm @@ -40,6 +40,7 @@ sub area_min_generation { sub uri { my ( $self, $uri ) = @_; + $uri = URI->new( $uri ); $uri->query_param( zoom => 2 ) if $uri->query_param('lat') && !$uri->query_param('zoom'); @@ -78,6 +79,88 @@ sub short_name { } +sub council_rss_alert_options { + my $self = shift; + my $all_councils = shift; + my $c = shift; + + my ( @options, @reported_to_options, $fylke, $kommune ); + + foreach ( values %$all_councils ) { + if ( $_->{type} eq 'NKO' ) { + $kommune = $_; + } + else { + $fylke = $_; + } + } + + if ( $fylke->{id} == 3 ) { # Oslo + my $short_name = $self->short_name($fylke, $all_councils); + ( my $id_name = $short_name ) =~ tr/+/_/; + + push @options, + { + type => 'council', + id => sprintf( 'council:%s:%s', $fylke->{id}, $id_name ), + rss_text => + sprintf( _('RSS feed of problems within %s'), $fylke->{name} ), + text => sprintf( _('Problems within %s'), $fylke->{name} ), + uri => $c->uri_for( '/rss/reports', $short_name ), + }; + } + else { + my $short_kommune_name = $self->short_name($kommune, $all_councils); + ( my $id_kommune_name = $short_kommune_name ) =~ tr/+/_/; + + my $short_fylke_name = $self->short_name($fylke, $all_councils); + ( my $id_fylke_name = $short_fylke_name ) =~ tr/+/_/; + + push @options, + { + type => 'area', + id => sprintf( 'area:%s:%s', $kommune->{id}, $id_kommune_name ), + rss_text => + sprintf( _('RSS feed of %s'), $kommune->{name} ), + text => $kommune->{name}, + uri => $c->uri_for( '/rss/area', $short_kommune_name ), + }, + { + type => 'area', + id => sprintf( 'area:%s:%s', $fylke->{id}, $id_fylke_name ), + rss_text => + sprintf( _('RSS feed of %s'), $fylke->{name} ), + text => $fylke->{name}, + uri => $c->uri_for( '/rss/area', $short_fylke_name ), + }; + + push @reported_to_options, + { + type => 'council', + id => sprintf( 'council:%s:%s', $kommune->{id}, $id_kommune_name ), + rss_text => + sprintf( _('RSS feed of %s'), $kommune->{name} ), + text => $kommune->{name}, + uri => $c->uri_for( '/rss/reports', $short_kommune_name ), + }, + { + type => 'council', + id => sprintf( 'council:%s:%s', $fylke->{id}, $id_fylke_name ), + rss_text => + sprintf( _('RSS feed of %s'), $fylke->{name} ), + text => $fylke->{name}, + uri => $c->uri_for( '/rss/reports/', $short_fylke_name ), + }; + } + + return ( + \@options, @reported_to_options + ? \@reported_to_options + : undef + ); + +} + sub reports_council_check { my ( $self, $c, $council ) = @_; diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index c06c3bb55..cbfa3c4e7 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -126,8 +126,20 @@ sub string { if (-s $cache_file) { $js = File::Slurp::read_file($cache_file); } else { - $url .= ',+UK' unless $url =~ /united\++kingdom$/ || $url =~ /uk$/i - || mySociety::Config::get('COUNTRY') ne 'GB'; + # For some reason adding gl=uk is no longer sufficient to make google + # think we are in the UK for some locations so we explictly add UK to + # the address. We do it here so as not to invalidate existing cache + # entries + if ( mySociety::Config::get('COUNTRY') eq 'GB' + && $url !~ /,\+UK/ + && $url !~ /united\++kingdom$/ ) + { + if ( $url =~ /&/ ) { + $url =~ s/&/,+UK&/; + } else { + $url .= ',+UK'; + } + } $url .= '&sensor=false&key=' . mySociety::Config::get('GOOGLE_MAPS_API_KEY'); $js = LWP::Simple::get($url); $js = encode_utf8($js) if utf8::is_utf8($js); @@ -43,8 +43,8 @@ sub test_geocode_string() { # geocode a straightforward string, expect success my ( $latitude, $longitude, $error ) = FixMyStreet::Geocode::string( 'Buckingham Palace', $q ); - is( $latitude, 51.5013639, 'example easting generated' ); - is( $longitude, -0.1418898, 'example northing generated' ); + is( $latitude, 51.4949261, 'example easting generated' ); + is( $longitude, -0.1461924, 'example northing generated' ); is( $error, undef, 'should not generate error for simple example' ); # expect a failure message for Northern Ireland diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 76f504d7e..33c959b48 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -43,19 +43,22 @@ foreach my $test ( { pc => 'glenthorpe', errors => [], - pc_alternatives => [ # TODO - should filter out these non-UK addresses + pc_alternatives => [ 'Glenthorpe Crescent, Leeds LS9 7', 'Glenthorpe Rd, Merton, Greater London SM4 4', - 'Glenthorpe Ln, Katy, TX 77494, USA', - 'Glenthorpe Dr, Walnut, CA 91789, USA', 'Glenthorpe Ave, Leeds LS9 7', - 'Glenthorpe Ct, Katy, TX 77494, USA', + 'Glenthorne Rd, Hammersmith, Greater London W6 0', + 'Glenthorne Ave, Yeovil, Somerset BA21 4', + 'Glenthorne Rd, Kenwyn, Cornwall TR3 6', + 'Glenthorne Dr, Cheslyn Hay, Staffordshire WS6 7', + 'Glenthorne Gardens, Ilford, Greater London IG5 0', + 'Glenthorne Ave, Croydon, Greater London CR0 7', ], }, { pc => 'Glenthorpe Ct, Katy, TX 77494, USA', errors => - ['We had a problem with the supplied co-ordinates - outside the UK?'], + ['Sorry, we could not find that location.'], pc_alternatives => [], }, ) diff --git a/templates/web/default/alert/list.html b/templates/web/default/alert/list.html index 40b94e9c0..3eb28788a 100644 --- a/templates/web/default/alert/list.html +++ b/templates/web/default/alert/list.html @@ -24,7 +24,7 @@ <p> [% IF pretty_pc %] - [% tprintf( loc('Here are the types of local problem alerts for %s.'), pretty_pc ) %] + [% tprintf( loc('Here are the types of local problem alerts for %s.'), pretty_pc ) | html %] [% END %] [% loc('Select which type of alert you\'d like and click the button for an RSS feed, or enter your email address to subscribe to an email alert') %] </p> |