aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm46
-rw-r--r--perllib/FixMyStreet/App/Controller/Location.pm15
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm15
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm16
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm7
-rw-r--r--perllib/FixMyStreet/Cobrand/Greenwich.pm4
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Nearby.pm4
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm12
-rw-r--r--perllib/FixMyStreet/Map.pm26
10 files changed, 70 insertions, 79 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 6af780c35..d1bf2d950 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -33,19 +33,24 @@ If no search redirect back to the homepage.
sub index : Path : Args(0) {
my ( $self, $c ) = @_;
- # handle old coord systems
- $c->forward('redirect_en_or_xy_to_latlon');
-
- # Check if we have a partial report
- my $partial_report = $c->forward('load_partial');
+ if ($c->get_param('ajax')) {
+ $c->detach('ajax');
+ }
# Check if the user is searching for a report by ID
if ( $c->get_param('pc') && $c->get_param('pc') =~ $c->cobrand->lookup_by_ref_regex ) {
$c->go('lookup_by_ref', [ $1 ]);
}
+ # handle old coord systems
+ $c->forward('redirect_en_or_xy_to_latlon');
+
+ # Check if we have a partial report
+ my $partial_report = $c->forward('load_partial');
+
# Try to create a location for whatever we have
- my $ret = $c->forward('/location/determine_location_from_coords')
+ my $ret = $c->forward('/location/determine_location_from_bbox')
+ || $c->forward('/location/determine_location_from_coords')
|| $c->forward('/location/determine_location_from_pc');
unless ($ret) {
return $c->res->redirect('/') unless $c->get_param('pc') || $partial_report;
@@ -170,7 +175,11 @@ sub display_location : Private {
my $latitude = $c->stash->{latitude};
my $longitude = $c->stash->{longitude};
- $c->forward('map_features', [ { latitude => $latitude, longitude => $longitude } ] );
+ if (my $bbox = $c->stash->{bbox}) {
+ $c->forward('map_features', [ { bbox => $bbox } ]);
+ } else {
+ $c->forward('map_features', [ { latitude => $latitude, longitude => $longitude } ]);
+ }
FixMyStreet::Map::display_map(
$c,
@@ -245,16 +254,11 @@ sub map_features : Private {
$c->forward( '/reports/stash_report_filter_status' );
$c->forward( '/reports/stash_report_sort', [ 'created-desc' ]);
- # Deal with pin hiding/age
- my $all_pins = $c->get_param('all_pins') ? 1 : undef;
- $c->stash->{all_pins} = $all_pins;
- my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age;
-
return if $c->get_param('js'); # JS will request the same (or more) data client side
- my ( $on_map_all, $on_map_list, $nearby, $distance ) =
+ my ( $on_map, $nearby, $distance ) =
FixMyStreet::Map::map_features(
- $c, interval => $interval, %$extra,
+ $c, %$extra,
categories => [ keys %{$c->stash->{filter_category}} ],
states => $c->stash->{filter_problem_states},
order => $c->stash->{sort_order},
@@ -266,16 +270,16 @@ sub map_features : Private {
# Here we might have a DB::Problem or a DB::Result::Nearby, we always want the problem.
my $p = (ref $_ eq 'FixMyStreet::DB::Result::Nearby') ? $_->problem : $_;
$p->pin_data($c, 'around');
- } @$on_map_all, @$nearby;
+ } @$on_map, @$nearby;
}
$c->stash->{pins} = \@pins;
- $c->stash->{on_map} = $on_map_list;
+ $c->stash->{on_map} = $on_map;
$c->stash->{around_map} = $nearby;
$c->stash->{distance} = $distance;
}
-=head2 /ajax
+=head2 ajax
Handle the ajax calls that the map makes when it is dragged. The info returned
is used to update the pins on the map and the text descriptions on the side of
@@ -283,11 +287,11 @@ the map.
=cut
-sub ajax : Path('/ajax') {
+sub ajax : Private {
my ( $self, $c ) = @_;
- my $bbox = $c->get_param('bbox');
- unless ($bbox) {
+ my $ret = $c->forward('/location/determine_location_from_bbox');
+ unless ($ret) {
$c->res->status(404);
$c->res->body('');
return;
@@ -296,7 +300,7 @@ sub ajax : Path('/ajax') {
my %valid_categories = map { $_ => 1 } $c->get_param_list('filter_category', 1);
$c->stash->{filter_category} = \%valid_categories;
- $c->forward('map_features', [ { bbox => $bbox } ]);
+ $c->forward('map_features', [ { bbox => $c->stash->{bbox} } ]);
$c->forward('/reports/ajax', [ 'around/on_map_list_items.html' ]);
}
diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm
index cb2077ede..8d5b0b147 100644
--- a/perllib/FixMyStreet/App/Controller/Location.pm
+++ b/perllib/FixMyStreet/App/Controller/Location.pm
@@ -110,6 +110,21 @@ sub determine_location_from_pc : Private {
return;
}
+sub determine_location_from_bbox : Private {
+ my ( $self, $c ) = @_;
+
+ my $bbox = $c->get_param('bbox');
+ return unless $bbox;
+
+ my ($min_lon, $min_lat, $max_lon, $max_lat) = split /,/, $bbox;
+ my $longitude = ($max_lon + $min_lon ) / 2;
+ my $latitude = ($max_lat + $min_lat ) / 2;
+ $c->stash->{bbox} = $bbox;
+ $c->stash->{latitude} = $latitude;
+ $c->stash->{longitude} = $longitude;
+ return $c->forward('check_location');
+}
+
=head2 check_location
Just make sure that for UK installs, our co-ordinates are indeed in the UK.
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 4c7931420..ac52b217c 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -524,24 +524,23 @@ sub nearby_json : Private {
$c->stash->{page} = 'report';
my $nearby = $c->model('DB::Nearby')->nearby(
- $c, $dist, [ $p->id ], 5, $p->latitude, $p->longitude, undef, [ $p->category ], undef
+ $c, $dist, [ $p->id ], 5, $p->latitude, $p->longitude, [ $p->category ], undef
);
my @pins = map {
my $p = $_->problem;
- my $colour = $c->cobrand->pin_colour( $p, 'around' );
- [ $p->latitude, $p->longitude,
- $colour,
- $p->id, $p->title_safe, 'small', JSON->false
+ $p = $p->pin_data($c, 'around');
+ [ $p->{latitude}, $p->{longitude}, $p->{colour},
+ $p->{id}, $p->{title}, 'small', JSON->false
]
} @$nearby;
- my $on_map_list_html = $c->render_fragment(
+ my $list_html = $c->render_fragment(
'around/on_map_list_items.html',
- { on_map => [], around_map => $nearby }
+ { around_map => [], on_map => $nearby }
);
my $json = { pins => \@pins };
- $json->{reports_list} = $on_map_list_html if $on_map_list_html;
+ $json->{reports_list} = $list_html if $list_html;
my $body = encode_json($json);
$c->res->content_type('application/json; charset=utf-8');
$c->res->body($body);
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
index e7d5e186a..2f47225a7 100644
--- a/perllib/FixMyStreet/Cobrand/Bromley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -59,10 +59,6 @@ sub map_type {
'Bromley';
}
-sub on_map_default_max_pin_age {
- return '1 month';
-}
-
# Bromley pins always yellow
sub pin_colour {
my ( $self, $p, $context ) = @_;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 9e49099aa..ada1058f5 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -437,22 +437,6 @@ sub reports_ordering {
return 'updated-desc';
}
-=head2 on_map_list_limit
-
-Return the maximum number of items to be given in the list of reports on the map
-
-=cut
-
-sub on_map_list_limit { return undef; }
-
-=head2 on_map_default_max_pin_age
-
-Return the default maximum age for pins.
-
-=cut
-
-sub on_map_default_max_pin_age { return '6 months'; }
-
=head2 on_map_default_status
Return the default ?status= query parameter to use for filter on map page.
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index a50a22ff9..ed9e5bdea 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -55,10 +55,9 @@ sub extra_contact_validation {
$c->stash->{dest} = $c->get_param('dest');
- $errors{dest} = "Please enter who your message is for"
- unless $c->get_param('dest');
-
- if ( $c->get_param('dest') eq 'council' || $c->get_param('dest') eq 'update' ) {
+ if (!$c->get_param('dest')) {
+ $errors{dest} = "Please enter who your message is for";
+ } elsif ( $c->get_param('dest') eq 'council' || $c->get_param('dest') eq 'update' ) {
$errors{not_for_us} = 1;
}
diff --git a/perllib/FixMyStreet/Cobrand/Greenwich.pm b/perllib/FixMyStreet/Cobrand/Greenwich.pm
index ce4fae381..6ff30e83d 100644
--- a/perllib/FixMyStreet/Cobrand/Greenwich.pm
+++ b/perllib/FixMyStreet/Cobrand/Greenwich.pm
@@ -57,10 +57,6 @@ sub contact_email {
sub reports_per_page { return 20; }
-sub on_map_default_max_pin_age {
- return '21 days';
-}
-
sub open311_config {
my ($self, $row, $h, $params) = @_;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
index 8b8951007..6e5e0220f 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
@@ -10,7 +10,7 @@ sub to_body {
}
sub nearby {
- my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval, $categories, $states ) = @_;
+ my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $categories, $states ) = @_;
unless ( $states ) {
$states = FixMyStreet::DB::Result::Problem->visible_states();
@@ -20,8 +20,6 @@ sub nearby {
non_public => 0,
state => [ keys %$states ],
};
- $params->{'current_timestamp-lastupdate'} = { '<', \"'$interval'::interval" }
- if $interval;
$params->{id} = { -not_in => $ids }
if $ids;
$params->{category} = $categories if $categories && @$categories;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index f1ed50721..ae45351c4 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -140,11 +140,11 @@ sub _recent {
# Problems around a location
sub around_map {
- my ( $rs, $limit, %p) = @_;
+ my ( $rs, $c, %p) = @_;
my $attr = {
order_by => $p{order},
};
- $attr->{rows} = $limit if $limit;
+ $attr->{rows} = $c->cobrand->reports_per_page;
unless ( $p{states} ) {
$p{states} = FixMyStreet::DB::Result::Problem->visible_states();
@@ -156,12 +156,12 @@ sub around_map {
latitude => { '>=', $p{min_lat}, '<', $p{max_lat} },
longitude => { '>=', $p{min_lon}, '<', $p{max_lon} },
};
- $q->{'current_timestamp - lastupdate'} = { '<', \"'$p{interval}'::interval" }
- if $p{interval};
$q->{category} = $p{categories} if $p{categories} && @{$p{categories}};
- my @problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->include_comment_counts->all };
- return \@problems;
+ my $problems = mySociety::Locale::in_gb_locale {
+ $rs->search( $q, $attr )->include_comment_counts->page($p{page});
+ };
+ return $problems;
}
# Admin functions
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm
index b6b618efb..e0e3c3128 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -88,23 +88,23 @@ sub map_features {
$p{latitude} = ($p{max_lat} + $p{min_lat} ) / 2;
}
- # list of problems around map can be limited, but should show all pins
- my $around_limit = $c->cobrand->on_map_list_limit || undef;
-
- my $on_map_all = $c->cobrand->problems_on_map->around_map( undef, %p );
- my $on_map_list = $around_limit
- ? $c->cobrand->problems_on_map->around_map( $around_limit, %p )
- : $on_map_all;
+ $p{page} = $c->get_param('p') || 1;
+ my $on_map = $c->cobrand->problems_on_map->around_map( $c, %p );
+ my $pager = $c->stash->{pager} = $on_map->pager;
+ $on_map = [ $on_map->all ];
my $dist = FixMyStreet::Gaze::get_radius_containing_population( $p{latitude}, $p{longitude} );
- my $limit = 20;
- my @ids = map { $_->id } @$on_map_list;
- my $nearby = $c->model('DB::Nearby')->nearby(
- $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "interval", "categories", "states"}
- );
+ my $nearby;
+ if (@$on_map < $pager->entries_per_page && $pager->current_page == 1) {
+ my $limit = 20;
+ my @ids = map { $_->id } @$on_map;
+ $nearby = $c->model('DB::Nearby')->nearby(
+ $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "categories", "states"}
+ );
+ }
- return ( $on_map_all, $on_map_list, $nearby, $dist );
+ return ( $on_map, $nearby, $dist );
}
sub click_to_wgs84 {