aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm21
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Buckinghamshire.pm54
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm8
7 files changed, 83 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 2cd34b7e2..a923a3407 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -843,6 +843,27 @@ sub report_edit : Path('report_edit') : Args(1) {
}
$c->stash->{problem} = $problem;
+ if ( $problem->extra ) {
+ my @fields;
+ if ( my $fields = $problem->get_extra_fields ) {
+ for my $field ( @{$fields} ) {
+ my $name = $field->{description} ?
+ "$field->{description} ($field->{name})" :
+ "$field->{name}";
+ push @fields, { name => $name, val => $field->{value} };
+ }
+ }
+ my $extra = $problem->get_extra_metadata;
+ if ( $extra->{duplicates} ) {
+ push @fields, { name => 'Duplicates', val => join( ',', @{ $problem->get_extra_metadata('duplicates') } ) };
+ delete $extra->{duplicates};
+ }
+ for my $key ( keys %$extra ) {
+ push @fields, { name => $key, val => $extra->{$key} };
+ }
+
+ $c->stash->{extra_fields} = \@fields;
+ }
$c->forward('/auth/get_csrf_token');
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index 9d522dbc9..1060c080b 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -369,7 +369,7 @@ sub process_user : Private {
# return 1;
# }
#
-# $alert_user->password( Utils::trim_text( $params{password_register} ) );
+# $alert_user->password( $params{password_register} );
}
=head2 setup_coordinate_rss_feeds
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 8c6c1b244..3a8362b5b 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -829,7 +829,7 @@ sub process_user : Private {
$c->forward('update_user', [ \%params ]);
if ($params{password_register}) {
$c->forward('/auth/test_password', [ $params{password_register} ]);
- $report->user->password(Utils::trim_text($params{password_register}));
+ $report->user->password($params{password_register});
}
return 1;
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 9d97688c5..13eceadb0 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -156,7 +156,7 @@ sub process_user : Private {
if ($params{password_register}) {
$c->forward('/auth/test_password', [ $params{password_register} ]);
- $update->user->password(Utils::trim_text($params{password_register}));
+ $update->user->password($params{password_register});
}
return 1;
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 20381bb85..3aa24c2db 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -490,8 +490,8 @@ sub export_summary_csv : Private {
'id',
'title',
'category',
- 'created_pp',
- 'confirmed_pp',
+ 'created',
+ 'confirmed',
'state',
'latitude', 'longitude',
'postcode',
diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
index a1ba25e6c..1b42055b6 100644
--- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
@@ -322,7 +322,7 @@ sub lookup_site_code {
my $self = shift;
my $row = shift;
- my $buffer = 10; # metres
+ my $buffer = 200; # metres
my ($x, $y) = $row->local_coords;
my ($w, $s, $e, $n) = ($x-$buffer, $y-$buffer, $x+$buffer, $y+$buffer);
@@ -342,13 +342,61 @@ sub lookup_site_code {
my $j = JSON->new->utf8->allow_nonref;
try {
$j = $j->decode($response);
- return $j->{features}->[0]->{properties}->{site_code};
} catch {
# There was either no asset found, or an error with the WFS
# call - in either case let's just proceed without the USRN.
- return;
+ return '';
+ };
+
+ # We have a list of features, and we want to find the one closest to the
+ # report location.
+ my $site_code = '';
+ my $nearest;
+
+ # There are only certain features we care about, the rest can be ignored.
+ my @valid_types = ( "2", "3A", "3B", "4A", "4B", "HE", "HWOA", "HWSA", "P" );
+ my %valid_types = map { $_ => 1 } @valid_types;
+
+ for my $feature ( @{ $j->{features} } ) {
+ my $type = $feature->{properties}->{feature_ty};
+ next unless $valid_types{$type};
+
+ # We shouldn't receive anything aside from these two geometry types, but belt and braces.
+ next unless $feature->{geometry}->{type} eq 'MultiLineString' || $feature->{geometry}->{type} eq 'LineString';
+
+ my @coordinates = @{ $feature->{geometry}->{coordinates} };
+ if ( $feature->{geometry}->{type} eq 'MultiLineString') {
+ # The coordinates are stored as a list of lists, so flatten 'em out
+ @coordinates = map { @{ $_ } } @coordinates;
+ }
+
+ # If any of this feature's points are closer than those we've seen so
+ # far then use the site_code from this feature.
+ for my $coords ( @coordinates ) {
+ my ($fx, $fy) = @$coords;
+ my $distance = $self->_distance($x, $y, $fx, $fy);
+ if ( !defined $nearest || $distance < $nearest ) {
+ $site_code = $feature->{properties}->{site_code};
+ $nearest = $distance;
+ }
+ }
}
+ return $site_code;
+}
+
+
+=head2 _distance
+
+Returns the cartesian distance between two coordinates.
+This is not a general-purpose distance function, it's intended for use with
+fairly nearby coordinates in EPSG:27700 where a spheroid doesn't need to be
+taken into account.
+
+=cut
+sub _distance {
+ my ($self, $ax, $ay, $bx, $by) = @_;
+ return sqrt( (($ax - $bx) ** 2) + (($ay - $by) ** 2) );
}
1;
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index e052e4bd4..b4d7c6347 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -136,8 +136,8 @@ sub update_comments {
# a more fine-grained status code that we use within FMS for
# response templates.
if ( $external_status_code ) {
- $comment->set_extra_metadata(external_status_code =>$external_status_code);
- $p->set_extra_metadata(external_status_code =>$external_status_code);
+ $comment->set_extra_metadata(external_status_code => $external_status_code);
+ $p->set_extra_metadata(external_status_code => $external_status_code);
}
$open311->add_media($request->{media_url}, $comment)
@@ -162,6 +162,10 @@ sub update_comments {
}
}
+ # If nothing to show (no text, photo, or state change), don't show this update
+ $comment->state('hidden') unless $comment->text || $comment->photo
+ || ($comment->problem_state && $state ne $old_state);
+
$p->lastupdate( $comment->created );
$p->update;
$comment->insert();