diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/Catalyst/Plugin/Session/State/Cookie.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/My.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 35 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/LichfieldDC.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Reading.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Southampton.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode/Bing.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/MapQuest.pm | 33 | ||||
-rw-r--r-- | perllib/Utils.pm | 2 |
14 files changed, 136 insertions, 20 deletions
diff --git a/perllib/Catalyst/Plugin/Session/State/Cookie.pm b/perllib/Catalyst/Plugin/Session/State/Cookie.pm index c4b61123b..ead8be38d 100644 --- a/perllib/Catalyst/Plugin/Session/State/Cookie.pm +++ b/perllib/Catalyst/Plugin/Session/State/Cookie.pm @@ -50,6 +50,9 @@ sub update_session_cookie { sub cookie_is_rejecting { my ( $c, $cookie ) = @_; + # Don't output cookie for JS files. mySociety addition + return 1 if substr($c->request->path, -3) eq '.js'; + if ( $cookie->{path} ) { return 1 if index '/'.$c->request->path, $cookie->{path}; } diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index 60e9dd09f..3de83b265 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -30,9 +30,16 @@ sub my : Path : Args(0) { my $pins = []; my $problems = {}; - my $rs = $c->user->problems->search( { + + my $params = { state => [ FixMyStreet::DB::Result::Problem->visible_states() ], - }, { + }; + $params = { + %{ $c->cobrand->problems_clause }, + %$params + } if $c->cobrand->problems_clause; + + my $rs = $c->user->problems->search( $params, { order_by => { -desc => 'confirmed' }, rows => 50 } )->page( $p_page ); diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 59e3a4410..afe180c29 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -51,7 +51,7 @@ sub display : Path('') : Args(1) { return $c->res->redirect( $c->uri_for($1), 301 ); } - $c->forward('load_problem_or_display_error', [ $id ] ); + $c->forward( 'load_problem_or_display_error', [ $id ] ); $c->forward( 'load_updates' ); $c->forward( 'format_problem_for_display' ); } @@ -88,7 +88,24 @@ sub load_updates : Private { { order_by => 'confirmed' } ); - $c->stash->{updates} = $updates; + my $questionnaires = $c->model('DB::Questionnaire')->search( + { + problem_id => $c->stash->{problem}->id, + whenanswered => { '!=', undef }, + old_state => 'confirmed', new_state => 'confirmed', + }, + { order_by => 'whenanswered' } + ); + + my @combined; + while (my $update = $updates->next) { + push @combined, [ $update->confirmed, $update ]; + } + while (my $update = $questionnaires->next) { + push @combined, [ $update->whenanswered, $update ]; + } + @combined = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @combined; + $c->stash->{updates} = \@combined; return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index e7620f755..9fb72121e 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -341,9 +341,11 @@ sub load_and_group_problems : Private { { columns => [ 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', - { duration => { extract => "epoch from current_timestamp-lastupdate" } }, - { age => { extract => "epoch from current_timestamp-confirmed" } }, - { confirmed => { extract => 'epoch from confirmed' } }, + #{ duration => { extract => "epoch from current_timestamp-lastupdate" } }, + #{ age => { extract => "epoch from current_timestamp-confirmed" } }, + { confirmed => { extract => 'epoch from confirmed' } }, + { whensent => { extract => 'epoch from whensent' } }, + { lastupdate => { extract => 'epoch from lastupdate' } }, { photo => 'photo is not null' }, ], order_by => { -desc => 'lastupdate' }, @@ -355,9 +357,10 @@ sub load_and_group_problems : Private { my ( %problems, @pins ); my $re_councils = join('|', keys %{$c->stash->{areas_info}}); - my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'duration', 'age', 'confirmed', 'photo' ); + my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; + $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}}; $c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker ); if ( !$problem{council} ) { # Problem was not sent to any council, add to possible councils diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 755f1e405..092e362f9 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -75,6 +75,7 @@ sprintf (different name to avoid clash) sub tprintf { my ( $self, $c, $format, @args ) = @_; + @args = @{$args[0]} if ref $args[0] eq 'ARRAY'; return sprintf $format, @args; } diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index 9791b071a..6f115ec63 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -10,7 +10,9 @@ sub council_name { return 'Barnet Council'; } sub council_url { return 'barnet'; } sub disambiguate_location { + my $self = shift; return { + %{ $self->SUPER::disambiguate_location() }, centre => '51.612832,-0.218169', span => '0.0563,0.09', bounds => [ '51.584682,-0.263169', '51.640982,-0.173169' ], diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm new file mode 100644 index 000000000..75174b638 --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -0,0 +1,35 @@ +package FixMyStreet::Cobrand::Bromley; +use base 'FixMyStreet::Cobrand::UKCouncils'; + +use strict; +use warnings; + +sub council_id { return 2482; } +sub council_area { return 'Bromley'; } +sub council_name { return 'Bromley Council'; } +sub council_url { return 'bromley'; } + +sub path_to_web_templates { + my $self = shift; + return [ + FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify, + FixMyStreet->path_to( 'templates/web/fixmystreet' )->stringify + ]; +} + +sub disambiguate_location { + my $self = shift; + return { + %{ $self->SUPER::disambiguate_location() }, + centre => '51.366836,0.040623', + span => '0.154963,0.24347', + bounds => [ '51.289355,-0.081112', '51.444318,0.162358' ], + }; +} + +sub example_places { + return ( 'BR1 3UH', 'Glebe Rd, Bromley' ); +} + +1; + diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index aacfb5e2b..c45c36b0b 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -239,6 +239,8 @@ Returns disambiguating information available sub disambiguate_location { return { country => 'uk', + bing_culture => 'en-GB', + bing_country => 'United Kingdom' }; } @@ -457,7 +459,7 @@ sub find_closest { my ( $self, $latitude, $longitude, $problem ) = @_; my $str = ''; - if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude ) ) { + if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture} ) ) { # cache the bing results for use in alerts if ( $problem ) { $problem->geocode( $j ); @@ -504,7 +506,7 @@ sub find_closest_address_for_rss { # if we've not cached it then we don't want to look it up in order to avoid # hammering the bing api # if ( !$j ) { - # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 ); + # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture}, 1 ); # $problem->geocode( $j ); # $problem->update; @@ -914,5 +916,9 @@ Get stats to display on the council reports page sub get_report_stats { return 0; } +sub example_places { + return [ 'B2 4QA', 'Tib St, Manchester' ]; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index 91c5e10ec..4d93aaf76 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -21,7 +21,9 @@ sub problems_clause { # FIXME - need to double check this is all correct sub disambiguate_location { + my $self = shift; return { + %{ $self->SUPER::disambiguate_location() }, centre => '52.688198,-1.804966', span => '0.1196,0.218675', bounds => [ '52.807793,-1.586291', '52.584891,-1.963232' ], diff --git a/perllib/FixMyStreet/Cobrand/Reading.pm b/perllib/FixMyStreet/Cobrand/Reading.pm index afc2b6ac6..c8591924e 100644 --- a/perllib/FixMyStreet/Cobrand/Reading.pm +++ b/perllib/FixMyStreet/Cobrand/Reading.pm @@ -12,11 +12,13 @@ sub council_name { return 'Reading City Council'; } sub council_url { return 'reading'; } sub disambiguate_location { + my $self = shift; return { + %{ $self->SUPER::disambiguate_location() }, town => 'Reading', - centre => '51.452983169803964,-0.98382678731985973', - span => '0.0833543573028663,0.124500468843446', - bounds => [ '51.409779668156361,-1.0529948144525243', '51.493134025459227,-0.92849434560907829' ], + centre => '51.452983,-0.983827', + span => '0.083355,0.1245', + bounds => [ '51.409779,-1.052994', '51.493134,-0.928494' ], }; } diff --git a/perllib/FixMyStreet/Cobrand/Southampton.pm b/perllib/FixMyStreet/Cobrand/Southampton.pm index 5bb7df3b6..b57091bef 100644 --- a/perllib/FixMyStreet/Cobrand/Southampton.pm +++ b/perllib/FixMyStreet/Cobrand/Southampton.pm @@ -10,7 +10,9 @@ sub council_name { return 'Southampton City Council'; } sub council_url { return 'southampton'; } sub disambiguate_location { + my $self = shift; return { + %{ $self->SUPER::disambiguate_location() }, town => 'Southampton', centre => '50.913822,-1.400493', span => '0.084628,0.15701', diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 856d7061e..f00cf9671 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -23,10 +23,11 @@ use Digest::MD5 qw(md5_hex); sub string { my ( $s, $c, $params ) = @_; $s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i; - my $url = "http://dev.virtualearth.net/REST/v1/Locations?q=$s&c=en-GB"; # FIXME nb-NO for Norway - $url .= '&mapView=' . $params->{bounds}[0] . ',' . $params->{bounds}[1] + my $url = "http://dev.virtualearth.net/REST/v1/Locations?q=$s"; + $url .= '&userMapView=' . $params->{bounds}[0] . ',' . $params->{bounds}[1] if $params->{bounds}; $url .= '&userLocation=' . $params->{centre} if $params->{centre}; + $url .= '&c=' . $params->{bing_culture} if $params->{bing_culture}; my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; my $cache_file = $cache_dir . md5_hex($url); @@ -43,7 +44,7 @@ sub string { if (!$js) { return { error => _('Sorry, we could not parse that location. Please try again.') }; - } elsif ($js =~ /BT\d/) { + } elsif ($js =~ /BT\d/ && $params->{bing_country} eq 'United Kingdom') { return { error => _("We do not currently cover Northern Ireland, I'm afraid.") }; } @@ -54,9 +55,10 @@ sub string { my $results = $js->{resourceSets}->[0]->{resources}; my ( $error, @valid_locations, $latitude, $longitude ); + foreach (@$results) { my $address = $_->{name}; - next unless $_->{address}->{countryRegion} eq 'United Kingdom'; # FIXME This is UK only + next unless $_->{address}->{countryRegion} eq $params->{bing_country}; ( $latitude, $longitude ) = @{ $_->{point}->{coordinates} }; push (@$error, { address => $address, latitude => $latitude, longitude => $longitude }); push (@valid_locations, $_); @@ -66,12 +68,13 @@ sub string { } sub reverse { - my ( $latitude, $longitude, $cache ) = @_; + my ( $latitude, $longitude, $bing_culture, $cache ) = @_; # Get nearest road-type thing from Bing my $key = mySociety::Config::get('BING_MAPS_API_KEY', ''); if ($key) { - my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?c=en-GB&key=$key"; + my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?key=$key"; + $url .= '&c=' . $bing_culture if $bing_culture; my $j; if ( $cache ) { my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; diff --git a/perllib/FixMyStreet/Map/OSM/MapQuest.pm b/perllib/FixMyStreet/Map/OSM/MapQuest.pm new file mode 100644 index 000000000..9cf6de01f --- /dev/null +++ b/perllib/FixMyStreet/Map/OSM/MapQuest.pm @@ -0,0 +1,33 @@ +#!/usr/bin/perl +# +# FixMyStreet:Map::OSM::CycleMap +# OSM CycleMap maps on FixMyStreet. +# +# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ + +package FixMyStreet::Map::OSM::MapQuest; +use base 'FixMyStreet::Map::OSM'; + +use strict; + +sub map_type { + return 'OpenLayers.Layer.OSM.MapQuestOpen'; +} + +sub map_tiles { + my ($self, $x, $y, $z) = @_; + my $tile_url = $self->base_tile_url(); + return [ + "http://otile1.$tile_url/$z/" . ($x - 1) . "/" . ($y - 1) . ".png", + "http://otile2.$tile_url/$z/$x/" . ($y - 1) . ".png", + "http://otile3.$tile_url/$z/" . ($x - 1) . "/$y.png", + "http://otile4.$tile_url/$z/$x/$y.png", + ]; +} + +sub base_tile_url { + return 'mqcdn.com/tiles/1.0.0/osm/'; +} + +1; diff --git a/perllib/Utils.pm b/perllib/Utils.pm index 954561a08..4e64836c6 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -190,7 +190,7 @@ sub cleanup_text { for ($input) { # shit -> poo - s{\bdog\s*shit\b}{dog poo}ig; + s{\bdog\s*shite*?\b}{dog poo}ig; # 'portakabin' to '[portable cabin]' (and variations) s{\b(porta)\s*([ck]abin|loo)\b}{[$1ble $2]}ig; |