aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2019-02-20 14:08:33 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2019-02-25 12:19:50 +0000
commit0c8aae1ab17617f46f400bab81bb7a3b144b4a1e (patch)
tree61395979a0dad8a235a7b0c8bf505bc55acd5aef
parent66f2160d3718f049a3772f2f69f623971295f547 (diff)
Internal JSON endpoint to get reports near a point
Unused right now, but will be soon, for the duplicate suggestion UI.
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm12
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm20
-rw-r--r--t/app/controller/around.t6
3 files changed, 34 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 4c68ce414..a09161494 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -317,6 +317,18 @@ sub ajax : Path('/ajax') {
$c->forward('/reports/ajax', [ 'around/on_map_list_items.html' ]);
}
+sub nearby : Path {
+ my ($self, $c) = @_;
+
+ my $states = FixMyStreet::DB::Result::Problem->open_states();
+ $c->forward('/report/_nearby_json', [ {
+ latitude => $c->get_param('latitude'),
+ longitude => $c->get_param('longitude'),
+ categories => [ $c->get_param('filter_category') || () ],
+ states => $states,
+ } ]);
+}
+
sub location_closest_address : Path('/ajax/closest') {
my ( $self, $c ) = @_;
$c->res->content_type('application/json; charset=utf-8');
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 796c2a42b..e032caa09 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -600,17 +600,29 @@ sub nearby_json :PathPart('nearby.json') :Chained('id') :Args(0) {
my ($self, $c) = @_;
my $p = $c->stash->{problem};
- my $params = {
+ $c->forward('_nearby_json', [ {
latitude => $p->latitude,
longitude => $p->longitude,
categories => [ $p->category ],
ids => [ $p->id ],
- distance => 1,
- };
+ } ]);
+}
+
+sub _nearby_json :Private {
+ my ($self, $c, $params) = @_;
# This is for the list template, this is a list on that page.
$c->stash->{page} = 'report';
+ # distance in metres
+ my $dist = $c->get_param('distance') || '';
+ $dist = 1000 unless $dist =~ /^\d+$/;
+ $dist = 1000 if $dist > 1000;
+ $params->{distance} = $dist / 1000;
+
+ my $pin_size = $c->get_param('pin_size') || '';
+ $pin_size = 'small' unless $pin_size =~ /^(mini|small|normal|big)$/;
+
$params->{extra} = $c->cobrand->call_hook('display_location_extra_params');
$params->{limit} = 5;
@@ -621,7 +633,7 @@ sub nearby_json :PathPart('nearby.json') :Chained('id') :Args(0) {
my @pins = map {
my $p = $_->pin_data($c, 'around');
[ $p->{latitude}, $p->{longitude}, $p->{colour},
- $p->{id}, $p->{title}, 'small', JSON->false
+ $p->{id}, $p->{title}, $pin_size, JSON->false
]
} @$nearby;
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index ed29d438c..3f0fff666 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -359,4 +359,10 @@ subtest 'check map zoom level customisation' => sub {
};
};
+subtest 'check nearby lookup' => sub {
+ my $p = FixMyStreet::DB->resultset("Problem")->search({ external_body => "Pothole-confirmed" })->first;
+ $mech->get_ok('/around/nearby?latitude=51.754926&longitude=-1.256179&filter_category=Pothole');
+ $mech->content_contains('["51.754926","-1.256179","yellow",' . $p->id . ',"Around page Test 1 for ' . $body->id . '","small",false]');
+};
+
done_testing();