diff options
author | Struan Donald <struan@exo.org.uk> | 2011-09-21 11:41:23 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-09-21 11:41:23 +0100 |
commit | d941a8c26e943c941f8e37ecbd9a9982dd41cb70 (patch) | |
tree | 75ea20fb18e984912ba60e4e499114c83cf431fe /perllib | |
parent | 9da2d7b0e806407e3ed5e5418a53fca64757a39a (diff) | |
parent | 77f31e8c96c727ea5ab9cf217cfd924074e8f3ed (diff) |
Merge branch 'master' of ssh://git.mysociety.org/data/git/public/fixmystreet into js-validation
Conflicts:
templates/web/default/report/display.html
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 76 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Open311.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 12 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/FMS.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/StreetView.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 2 | ||||
-rw-r--r-- | perllib/Utils.pm | 14 |
14 files changed, 99 insertions, 35 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 467f29d26..2aaa488d6 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -171,11 +171,16 @@ sub questionnaire : Path('questionnaire') : Args(0) { $c->forward('check_page_allowed'); my $questionnaires = $c->model('DB::Questionnaire')->search( - { whenanswered => \'is not null' }, { group_by => [ 'ever_reported' ], select => [ 'ever_reported', { count => 'me.id' } ], as => [qw/reported questionnaire_count/] } + { whenanswered => { '!=', undef } }, + { group_by => [ 'ever_reported' ], + select => [ 'ever_reported', { count => 'me.id' } ], + as => [ qw/reported questionnaire_count/ ] } ); - - my %questionnaire_counts = map { ( $_->get_column( 'reported' ) || -1 ) => $_->get_column( 'questionnaire_count' ) } $questionnaires->all; + my %questionnaire_counts = map { + ( defined $_->get_column( 'reported' ) ? $_->get_column( 'reported' ) : -1 ) + => $_->get_column( 'questionnaire_count' ) + } $questionnaires->all; $questionnaire_counts{1} ||= 0; $questionnaire_counts{0} ||= 0; $questionnaire_counts{total} = $questionnaire_counts{0} + $questionnaire_counts{1}; @@ -204,6 +209,7 @@ sub council_list : Path('council_list') : Args(0) { undef, { select => [ 'editor', { count => 'contacts_history_id', -as => 'c' } ], + as => [ 'editor', 'c' ], group_by => ['editor'], order_by => { -desc => 'c' } } @@ -778,14 +784,7 @@ sub user_edit : Path('user_edit') : Args(1) { my $user = $c->model('DB::User')->find( { id => $id } ); $c->stash->{user} = $user; - my @area_types = $c->cobrand->area_types; - my $areas = mySociety::MaPit::call('areas', \@area_types); - - my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; - @councils_ids = $c->cobrand->filter_all_council_ids_list( @councils_ids ); - - $c->stash->{council_ids} = \@councils_ids; - $c->stash->{council_details} = $areas; + $c->forward('set_up_council_details'); if ( $c->req->param('submit') ) { $c->forward('check_token'); @@ -838,6 +837,8 @@ sub stats : Path('stats') : Args(0) { $c->forward('check_page_allowed'); + $c->forward('set_up_council_details'); + if ( $c->req->param('getcounts') ) { my ( $start_date, $end_date, @errors ); @@ -870,25 +871,51 @@ sub stats : Path('stats') : Args(0) { return 1 if @errors; + my $bymonth = $c->req->param('bymonth'); + $c->stash->{bymonth} = $bymonth; + my ( %council, %dates ); + $council{council} = { like => $c->req->param('council') } + if $c->req->param('council'); + + $c->stash->{selected_council} = $c->req->param('council'); + my $field = 'confirmed'; $field = 'created' if $c->req->param('unconfirmed'); my $one_day = DateTime::Duration->new( days => 1 ); + + my %select = ( + select => [ 'state', { 'count' => 'me.id' } ], + as => [qw/state count/], + group_by => [ 'state' ], + order_by => [ 'state' ], + ); + + if ( $c->req->param('bymonth') ) { + %select = ( + select => [ + { extract => \"year from $field", -as => 'c_year' }, + { extract => \"month from $field", -as => 'c_month' }, + { 'count' => 'me.id' } + ], + as => [qw/c_year c_month count/], + group_by => [qw/c_year c_month/], + order_by => [qw/c_year c_month/], + ); + } + my $p = $c->model('DB::Problem')->search( { -AND => [ $field => { '>=', $start_date}, $field => { '<=', $end_date + $one_day }, ], + %council, + %dates, }, - { - select => [ 'state', { 'count' => 'me.id' } ], - as => [qw/state count/], - group_by => [ 'state' ], - order_by => [ 'state' ], - } + \%select, ); # in case the total_report count is 0 @@ -1122,6 +1149,21 @@ sub check_page_allowed : Private { return 1; } +sub set_up_council_details : Private { + my ($self, $c ) = @_; + + my @area_types = $c->cobrand->area_types; + my $areas = mySociety::MaPit::call('areas', \@area_types); + + my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; + @councils_ids = $c->cobrand->filter_all_council_ids_list( @councils_ids ); + + $c->stash->{council_ids} = \@councils_ids; + $c->stash->{council_details} = $areas; + + return 1; +} + sub trim { my $self = shift; my $e = shift; diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index d3a4500c6..72d6ac62b 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -235,7 +235,7 @@ the map. sub ajax : Path('/ajax') { my ( $self, $c ) = @_; - $c->res->content_type('text/javascript; charset=utf-8'); + $c->res->content_type('application/json; charset=utf-8'); unless ( $c->req->param('bbox') ) { $c->res->status(404); diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index 46d7801f6..fe1494b95 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -55,7 +55,7 @@ sub index : Path : Args(0) { sub old_uri : Regex('^open311\.cgi') : Args(0) { my ( $self, $c ) = @_; ( my $new = $c->req->path ) =~ s/open311.cgi/open311/; - $c->res->redirect( "/$new", 301); + $c->res->redirect( $c->uri_for("/$new", $c->req->query_params), 301); } =head2 discovery diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index c70a74146..f16bd5393 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -666,7 +666,7 @@ sub process_report : Private { $report->detail( $detail ); # set these straight from the params - $report->category( _ $params{category} ); + $report->category( _ $params{category} ) if $params{category}; my $areas = $c->stash->{all_areas}; $report->areas( ',' . join( ',', sort keys %$areas ) . ',' ); diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index f7fb5dec5..93af3393c 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -319,8 +319,20 @@ sub load_and_group_problems : Private { }; if ($c->stash->{ward}) { $where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' }; + $where->{council} = [ + undef, + $c->stash->{council}->{id}, + { 'like', $c->stash->{council}->{id} . ',%' }, + { 'like', '%,' . $c->stash->{council}->{id} }, + ]; } elsif ($c->stash->{council}) { $where->{areas} = { 'like', '%,' . $c->stash->{council}->{id} . ',%' }; + $where->{council} = [ + undef, + $c->stash->{council}->{id}, + { 'like', $c->stash->{council}->{id} . ',%' }, + { 'like', '%,' . $c->stash->{council}->{id} }, + ]; } my $problems = $c->cobrand->problems->search( $where, diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 767d38c21..23345df65 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -194,7 +194,7 @@ sub generate : Private { my $out = $c->stash->{rss}->as_string; my $uri = $c->uri_for( '/' . $c->req->path ); - $out =~ s{<link>(.*?)</link>}{"<link>" . $c->uri_for( $1 ) . "</link><uri>$uri</uri>"}e; + $out =~ s{(<link>.*?</link>)}{$1<uri>$uri</uri>}; $c->response->header('Content-Type' => 'application/xml; charset=utf-8'); $c->response->body( $out ); @@ -306,7 +306,7 @@ sub add_parameters : Private { $c->stash->{rss}->channel( title => ent($title), - link => $link . ($c->stash->{qs} || ''), + link => $c->uri_for($link) . ($c->stash->{qs} || ''), description => ent($desc), language => 'en-gb', ); diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index bf085e32a..c1a5d65c9 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -4,8 +4,6 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; -use File::Slurp; - use mySociety::DBHandle qw(dbh); use mySociety::EmailUtil; use mySociety::Gaze; @@ -189,7 +187,7 @@ sub _send_aggregated_alert_email(%) { unless -e $template; $template = FixMyStreet->path_to( "templates", "email", "default", "$data{template}.txt" )->stringify unless -e $template; - $template = File::Slurp::read_file($template); + $template = Utils::read_file($template); my $sender = $cobrand->contact_email; (my $from = $sender) =~ s/team/fms-DO-NOT-REPLY/; # XXX diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 44c066454..59227fce8 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -66,7 +66,7 @@ sub recent { my $result = Memcached::get($key); if ( $result ) { # Need to reattach schema so that confirmed column gets reinflated. - $result->[0]->result_source->schema( $rs->result_source->schema ); + $result->[0]->result_source->schema( $rs->result_source->schema ) if $result->[0]; } else { $result = [ $rs->search( { state => [ FixMyStreet::DB::Result::Problem->visible_states() ] diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index 665e0e3e0..0cf01b6d1 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -3,7 +3,7 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; -use File::Slurp; +use Encode; use Utils; use mySociety::EmailUtil; @@ -57,12 +57,12 @@ sub send_questionnaires_period { my $template; if ($params->{site} eq 'emptyhomes') { ($template = $period) =~ s/ //; - $template = File::Slurp::read_file( FixMyStreet->path_to( "templates/email/emptyhomes/" . $row->lang . "/questionnaire-$template.txt" )->stringify ); + $template = Utils::read_file( FixMyStreet->path_to( "templates/email/emptyhomes/" . $row->lang . "/questionnaire-$template.txt" )->stringify ); } else { $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, "questionnaire.txt" )->stringify; $template = FixMyStreet->path_to( "templates", "email", "default", "questionnaire.txt" )->stringify unless -e $template; - $template = File::Slurp::read_file( $template ); + $template = Utils::read_file( $template ); } my %h = map { $_ => $row->$_ } qw/name title detail category/; diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index d7c416fb5..6ee17029a 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -41,9 +41,8 @@ sub string { my $params = $c->cobrand->disambiguate_location(); return FixMyStreet::Geocode::Bing::string($s, $c, $params) if FixMyStreet->config('BING_MAPS_API_KEY'); - return FixMyStreet::Geocode::Google::string($s, $c, $params) - if FixMyStreet->config('GOOGLE_MAPS_API_KEY'); - die "No geocoding provider configured"; + # Fall back to Google API, which allow acces with and without a key + return FixMyStreet::Geocode::Google::string($s, $c, $params); } 1; diff --git a/perllib/FixMyStreet/Map/FMS.pm b/perllib/FixMyStreet/Map/FMS.pm index 2e40bfde3..d5edac763 100644 --- a/perllib/FixMyStreet/Map/FMS.pm +++ b/perllib/FixMyStreet/Map/FMS.pm @@ -21,7 +21,7 @@ sub map_template { } sub copyright { - return _('Map contains Ordnance Survey data © Crown copyright and database right 2010.<br>© 2011 <a href="http://www.bing.com/maps/">Microsoft</a>. © AND, Navteq, Ordnance Survey.'); + return ''; } sub get_quadkey { diff --git a/perllib/FixMyStreet/Map/OSM/StreetView.pm b/perllib/FixMyStreet/Map/OSM/StreetView.pm index 141c2e328..8fe4744a4 100644 --- a/perllib/FixMyStreet/Map/OSM/StreetView.pm +++ b/perllib/FixMyStreet/Map/OSM/StreetView.pm @@ -24,7 +24,6 @@ sub base_tile_url { } sub copyright { - return _('Map contains Ordnance Survey data © Crown copyright and database right 2010.'); } 1; diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index 1391254b6..185b59daa 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -364,7 +364,7 @@ sub extract_problem_banner { my $mech = shift; my $result = scraper { - process 'div#side > p', id => '@id', text => 'TEXT'; + process 'div#side > p.banner', id => '@id', text => 'TEXT'; } ->scrape( $mech->response ); diff --git a/perllib/Utils.pm b/perllib/Utils.pm index c9afff186..954561a08 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -13,6 +13,7 @@ package Utils; use strict; use Encode; +use File::Slurp qw(); use POSIX qw(strftime); use mySociety::DBHandle qw(dbh); use mySociety::GeoUtil; @@ -262,4 +263,17 @@ sub _part { } } +=head2 read_file + +Reads in a UTF-8 encoded file using File::Slurp and decodes it from UTF-8. +This appears simplest, rather than getting confused with binmodes and so on. + +=cut +sub read_file { + my $filename = shift; + my $data = File::Slurp::read_file( $filename ); + $data = Encode::decode( 'utf8', $data ); + return $data; +} + 1; |