From b1a719a95a736937f6d5c92bf81d95f0bc999152 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 16 Feb 2015 14:32:52 +0000 Subject: Switch easting/northing output to one line. This is more friendly for e.g. copy and pasting by someone using the Dynamics CRM software. Fixes #997. --- perllib/FixMyStreet/DB/ResultSet/Problem.pm | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/DB/ResultSet/Problem.pm') diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index a84a309ee..10d395684 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -302,10 +302,7 @@ sub send_reports { ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude} ); # email templates don't have conditionals so we need to farmat this here - $h{easting_northing} # - = "Easting: $h{easting}\n\n" # - . "Northing: $h{northing}\n\n"; - + $h{easting_northing} = "Easting/Northing: $h{easting}/$h{northing}\n\n"; } if ( $row->used_map ) { -- cgit v1.2.3 From c79b9b54210cc5483bed03783417fbeb6ed422cb Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 20 Feb 2015 14:50:47 +0000 Subject: [UK] Output NI grid references to NI councils. --- perllib/FixMyStreet/DB/ResultSet/Problem.pm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'perllib/FixMyStreet/DB/ResultSet/Problem.pm') diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 10d395684..cc0cc5242 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -295,16 +295,6 @@ sub send_reports { : _('The user could not locate the problem on a map, but to see the area around the location they entered'); $h{closest_address} = ''; - # If we are in the UK include eastings and northings, and nearest stuff - $h{easting_northing} = ''; - if ( $cobrand->country eq 'GB' ) { - - ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude} ); - - # email templates don't have conditionals so we need to farmat this here - $h{easting_northing} = "Easting/Northing: $h{easting}/$h{northing}\n\n"; - } - if ( $row->used_map ) { $h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude}, $row ); } @@ -407,6 +397,20 @@ sub send_reports { next; } + # If we are in the UK include eastings and northings, and nearest stuff + $h{easting_northing} = ''; + if ( $cobrand->country eq 'GB' ) { + + my $coordsyst = 'G'; + $coordsyst = 'I' if grep { /FixMyStreet::SendReport::NI/ } keys %reporters; + ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude}, $coordsyst ); + + # email templates don't have conditionals so we need to format this here + $h{easting_northing} = "Easting/Northing"; + $h{easting_northing} .= " (IE)" if $coordsyst eq 'I'; + $h{easting_northing} .= ": $h{easting}/$h{northing}\n\n"; + } + if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING')) { # on a staging server send emails to ourselves rather than the bodies %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI|EmptyHomes)/ } keys %reporters; -- cgit v1.2.3 From 72e7c2ac4b6a644ee2bb002915122648d97c56e0 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 16 Mar 2015 16:24:34 +0000 Subject: [fixmystreet.com] Remove special NI code. This is now handled by normal bodies in the admin. In order to remove references in send_reports, tidy up (unused) EmptyHomes code a bit. --- perllib/FixMyStreet/DB/ResultSet/Problem.pm | 152 +++++++++++++--------------- 1 file changed, 70 insertions(+), 82 deletions(-) (limited to 'perllib/FixMyStreet/DB/ResultSet/Problem.pm') diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index cc0cc5242..7a50a3146 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -302,118 +302,106 @@ sub send_reports { if ( $cobrand->allow_anonymous_reports && $row->user->email eq $cobrand->anonymous_account->{'email'} ) { - $h{anonymous_report} = 1; - $h{user_details} = _('This report was submitted anonymously'); - } else { - $h{user_details} = sprintf(_('Name: %s'), $row->name) . "\n\n"; - $h{user_details} .= sprintf(_('Email: %s'), $row->user->email) . "\n\n"; - } + $h{anonymous_report} = 1; + $h{user_details} = _('This report was submitted anonymously'); + } else { + $h{user_details} = sprintf(_('Name: %s'), $row->name) . "\n\n"; + $h{user_details} .= sprintf(_('Email: %s'), $row->user->email) . "\n\n"; + } + + $h{easting_northing} = ''; if ($cobrand->can('process_additional_metadata_for_email')) { $cobrand->process_additional_metadata_for_email($row, \%h); } + # XXX Needs locks! + # XXX Only copes with at most one missing body + my ($bodies, $missing) = $row->bodies_str =~ /^([\d,]+)(?:\|(\d+))?/; + my @bodies = split(/,/, $bodies); + $bodies = FixMyStreet::App->model("DB::Body")->search( + { id => \@bodies }, + { order_by => 'name' }, + ); + $missing = FixMyStreet::App->model("DB::Body")->find($missing) if $missing; + + my @dear; my %reporters = (); - my ( $sender_count ); - if ($site eq 'emptyhomes') { - - my $body = $row->bodies_str; - $body = FixMyStreet::App->model("DB::Body")->find($body); - my $sender = "FixMyStreet::SendReport::EmptyHomes"; - $reporters{ $sender } = $sender->new() unless $reporters{$sender}; - $reporters{ $sender }->add_body( $body ); - $sender_count = 1; + while (my $body = $bodies->next) { + my $sender_info = $cobrand->get_body_sender( $body, $row->category ); + my $sender = "FixMyStreet::SendReport::" . $sender_info->{method}; - } else { - - # XXX Needs locks! - # XXX Only copes with at most one missing body - my ($bodies, $missing) = $row->bodies_str =~ /^([\d,]+)(?:\|(\d+))?/; - my @bodies = split(/,/, $bodies); - $bodies = FixMyStreet::App->model("DB::Body")->search( - { id => \@bodies }, - { order_by => 'name' }, - ); - $missing = FixMyStreet::App->model("DB::Body")->find($missing) if $missing; - my @dear; - - while (my $body = $bodies->next) { - my $sender_info = $cobrand->get_body_sender( $body, $row->category ); - my $sender = "FixMyStreet::SendReport::" . $sender_info->{method}; - - if ( ! exists $senders->{ $sender } ) { - warn "No such sender [ $sender ] for body $body->name ( $body->id )"; - next; - } - $reporters{ $sender } ||= $sender->new(); - - if ( $reporters{ $sender }->should_skip( $row ) ) { - debug_print("skipped by sender " . $sender_info->{method} . " (might be due to previous failed attempts?)", $row->id) if $debug_mode; - } else { - debug_print("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $body->send_method, $row->id) if $debug_mode; - push @dear, $body->name; - $reporters{ $sender }->add_body( $body, $sender_info->{config} ); - } + if ( ! exists $senders->{ $sender } ) { + warn "No such sender [ $sender ] for body $body->name ( $body->id )"; + next; } + $reporters{ $sender } ||= $sender->new(); - if ($h{category} eq _('Other')) { - $h{category_footer} = _('this type of local problem'); - $h{category_line} = ''; + if ( $reporters{ $sender }->should_skip( $row ) ) { + debug_print("skipped by sender " . $sender_info->{method} . " (might be due to previous failed attempts?)", $row->id) if $debug_mode; } else { - $h{category_footer} = "'" . $h{category} . "'"; - $h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n"; + debug_print("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $body->send_method, $row->id) if $debug_mode; + push @dear, $body->name; + $reporters{ $sender }->add_body( $body, $sender_info->{config} ); } - if ( $row->subcategory ) { - $h{subcategory_line} = sprintf(_("Subcategory: %s"), $row->subcategory) . "\n\n"; - } else { - $h{subcategory_line} = "\n\n"; - } + # If we are in the UK include eastings and northings, and nearest stuff + if ( $cobrand->country eq 'GB' && !$h{easting} ) { + my $coordsyst = 'G'; + my $first_area = $body->body_areas->first->area_id; + my $area_info = mySociety::MaPit::call('area', $first_area); + $coordsyst = 'I' if $area_info->{type} eq 'LGD'; - $h{bodies_name} = join(_(' and '), @dear); - if ($h{category} eq _('Other')) { - $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to both councils covering the location of the problem, as the user did not categorise it; please ignore it if you're not the correct council to deal with the issue, or let us know what category of problem this is so we can add it to our system.") . " ]\n\n" - : ''; - } else { - $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to several councils covering the location of the problem, as the category selected is provided for all of them; please ignore it if you're not the correct council to deal with the issue.") . " ]\n\n" - : ''; - } - $h{missing} = ''; - if ($missing) { - $h{missing} = '[ ' - . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $missing->name) - . " ]\n\n"; - } + ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude}, $coordsyst ); - $sender_count = scalar @dear; + # email templates don't have conditionals so we need to format this here + $h{easting_northing} = "Easting/Northing"; + $h{easting_northing} .= " (IE)" if $coordsyst eq 'I'; + $h{easting_northing} .= ": $h{easting}/$h{northing}\n\n"; + } } unless ( keys %reporters ) { die 'Report not going anywhere for ID ' . $row->id . '!'; } - if (! $sender_count) { + unless (@dear) { debug_print("can't send because sender count is zero", $row->id) if $debug_mode; next; } - # If we are in the UK include eastings and northings, and nearest stuff - $h{easting_northing} = ''; - if ( $cobrand->country eq 'GB' ) { + if ($h{category} eq _('Other')) { + $h{category_footer} = _('this type of local problem'); + $h{category_line} = ''; + } else { + $h{category_footer} = "'" . $h{category} . "'"; + $h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n"; + } - my $coordsyst = 'G'; - $coordsyst = 'I' if grep { /FixMyStreet::SendReport::NI/ } keys %reporters; - ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude}, $coordsyst ); + if ( $row->subcategory ) { + $h{subcategory_line} = sprintf(_("Subcategory: %s"), $row->subcategory) . "\n\n"; + } else { + $h{subcategory_line} = "\n\n"; + } - # email templates don't have conditionals so we need to format this here - $h{easting_northing} = "Easting/Northing"; - $h{easting_northing} .= " (IE)" if $coordsyst eq 'I'; - $h{easting_northing} .= ": $h{easting}/$h{northing}\n\n"; + $h{bodies_name} = join(_(' and '), @dear); + if ($h{category} eq _('Other')) { + $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to both councils covering the location of the problem, as the user did not categorise it; please ignore it if you're not the correct council to deal with the issue, or let us know what category of problem this is so we can add it to our system.") . " ]\n\n" + : ''; + } else { + $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to several councils covering the location of the problem, as the category selected is provided for all of them; please ignore it if you're not the correct council to deal with the issue.") . " ]\n\n" + : ''; + } + $h{missing} = ''; + if ($missing) { + $h{missing} = '[ ' + . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $missing->name) + . " ]\n\n"; } if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING')) { # on a staging server send emails to ourselves rather than the bodies - %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI|EmptyHomes)/ } keys %reporters; + %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|EmptyHomes)/ } keys %reporters; unless (%reporters) { %reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() ); } -- cgit v1.2.3 From 09f94956ecd20a7aa861d0f7254189fd9373b813 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Fri, 27 Feb 2015 12:51:29 +0000 Subject: Add category filtering support to /ajax via 'category' GET param --- perllib/FixMyStreet/DB/ResultSet/Problem.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/DB/ResultSet/Problem.pm') diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 7a50a3146..affc6b177 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -131,7 +131,7 @@ sub _recent { # Problems around a location sub around_map { - my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit ) = @_; + my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit, $category ) = @_; my $attr = { order_by => { -desc => 'created' }, }; @@ -145,6 +145,7 @@ sub around_map { }; $q->{'current_timestamp - lastupdate'} = { '<', \"'$interval'::interval" } if $interval; + $q->{category} = $category if $category; my @problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->all }; return \@problems; -- cgit v1.2.3 From 0176b3c6918fbfa6ee22f24066d3a3d8850c8cca Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Tue, 3 Mar 2015 20:32:07 +0000 Subject: Allow /ajax to be filtered by status If present, the 'status' param can be set to 'open' or 'fixed' to display ensure only open or fixed reports respectively are included in the response. --- perllib/FixMyStreet/DB/ResultSet/Problem.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/DB/ResultSet/Problem.pm') diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index affc6b177..7885c28b3 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -131,15 +131,19 @@ sub _recent { # Problems around a location sub around_map { - my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit, $category ) = @_; + my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit, $category, $states ) = @_; my $attr = { order_by => { -desc => 'created' }, }; $attr->{rows} = $limit if $limit; + unless ( $states ) { + $states = FixMyStreet::DB::Result::Problem->visible_states(); + } + my $q = { non_public => 0, - state => [ FixMyStreet::DB::Result::Problem->visible_states() ], + state => [ keys %$states ], latitude => { '>=', $min_lat, '<', $max_lat }, longitude => { '>=', $min_lon, '<', $max_lon }, }; -- cgit v1.2.3