aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm44
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm16
2 files changed, 51 insertions, 9 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 5090ef7ff..8f651fae2 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -293,19 +293,51 @@ sub location_autocomplete : Path('/ajax/geocode') {
# we want the match even if there's no ambiguity, so recommendation doesn't
# disappear when it's the last choice being offered in the autocomplete.
$c->stash->{allow_single_geocode_match_strings} = 1;
+ return $self->_geocode( $c, $c->req->param('term') );
+}
+
+sub location_lookup : Path('/ajax/lookup_location') {
+ my ( $self, $c ) = @_;
+ $c->res->content_type('application/json; charset=utf-8');
+ unless ( $c->req->param('term') ) {
+ $c->res->status(404);
+ $c->res->body('');
+ return;
+ }
+
+ return $self->_geocode( $c, $c->req->param('term') );
+}
+
+sub _geocode : Private {
+ my ( $self, $c, $term ) = @_;
+
my ( $lat, $long, $suggestions ) =
FixMyStreet::Geocode::lookup( $c->req->param('term'), $c );
- my @addresses;
- # $error doubles up to return multiple choices by being an array
- if ( ref($suggestions) eq 'ARRAY' ) {
- foreach (@$suggestions) {
- push @addresses, decode_utf8($_->{address});
+
+ my ($response, @addresses);
+
+ if ( $lat && $long ) {
+ $response = { latitude => $lat, longitude => $long };
+ } else {
+ if ( ref($suggestions) eq 'ARRAY' ) {
+ foreach (@$suggestions) {
+ push @addresses, decode_utf8($_->{address});
+ }
+ $response = { suggestions => \@addresses };
+ } else {
+ $response = { error => $suggestions };
}
}
+
+ if ( $c->stash->{allow_single_geocode_match_strings} ) {
+ $response = \@addresses;
+ }
+
my $body = JSON->new->utf8(1)->encode(
- \@addresses
+ $response
);
$c->res->body($body);
+
}
__PACKAGE__->meta->make_immutable;
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index eab308054..f4093ef21 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -5,6 +5,7 @@ use namespace::autoclean;
use File::Slurp;
use List::MoreUtils qw(zip);
use POSIX qw(strcoll);
+use RABX;
use mySociety::MaPit;
BEGIN { extends 'Catalyst::Controller'; }
@@ -356,9 +357,13 @@ sub load_and_group_problems : Private {
# A proxy for an external_body
$where->{'lower(external_body)'} = lc $c->stash->{body}->name;
} elsif ($c->stash->{body}) {
- $where->{areas} = { 'like', '%,' . $c->stash->{body}->id . ',%' };
+ # XXX FixMyStreet used to have the following line so that reports not
+ # currently sent anywhere could still be listed in the appropriate
+ # (body/area), as they were the same. Now they're not, not sure if
+ # there's a way to do this easily.
+ #$where->{areas} = { 'like', '%,' . $c->stash->{body}->id . ',%' };
$where->{bodies_str} = [
- undef,
+ # undef,
$c->stash->{body}->id,
{ 'like', $c->stash->{body}->id . ',%' },
{ 'like', '%,' . $c->stash->{body}->id },
@@ -371,6 +376,7 @@ sub load_and_group_problems : Private {
'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand',
#{ duration => { extract => "epoch from current_timestamp-lastupdate" } },
#{ age => { extract => "epoch from current_timestamp-confirmed" } },
+ { created => { extract => 'epoch from created' } },
{ confirmed => { extract => 'epoch from confirmed' } },
{ whensent => { extract => 'epoch from whensent' } },
{ lastupdate => { extract => 'epoch from lastupdate' } },
@@ -384,10 +390,14 @@ sub load_and_group_problems : Private {
$problems = $problems->cursor; # Raw DB cursor for speed
my ( %problems, @pins );
- my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo', 'extra' );
+ my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'created', 'confirmed', 'whensent', 'lastupdate', 'photo', 'extra' );
while ( my @problem = $problems->next ) {
my %problem = zip @cols, @problem;
$problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}};
+ if ($problem{extra} && $c->cobrand->moniker eq 'zurich') { # Inflate
+ utf8::encode($problem{extra}) if utf8::is_utf8($problem{extra});
+ $problem{extra} = RABX::unserialise($problem{extra});
+ }
$c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker );
if ( !$c->stash->{body}->id ) {
# An external_body entry