diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Nearby.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 17 | ||||
-rw-r--r-- | t/app/controller/around.t | 74 | ||||
-rw-r--r-- | t/map/tilma/original.t | 1 | ||||
-rw-r--r-- | templates/web/base/around/on_map_list_items.html | 2 | ||||
-rw-r--r-- | templates/web/base/pagination.html | 2 | ||||
-rw-r--r-- | templates/web/base/reports/_list-filters.html | 7 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 3 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 29 |
14 files changed, 143 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 82cca72b5..897b4af86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Simplify footer CSS. #2107 - Keep commas in geocode lookups. - Show message on reports closed to updates. + - Only display last 6 months of reports on around page by default #2098 - Admin improvements: - Category group can be edited. - Bugfixes: diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 8fed5c3aa..cc6f8387c 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -253,6 +253,7 @@ sub map_features : Private { $c->forward( '/reports/stash_report_filter_status' ); $c->forward( '/reports/stash_report_sort', [ 'created-desc' ]); + $c->stash->{show_old_reports} = $c->get_param('show_old_reports'); return if $c->get_param('js'); # JS will request the same (or more) data client side diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index dc9e2c913..05776a94f 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -758,10 +758,13 @@ sub stash_report_sort : Private { $sort =~ /^(updated|created|comments)-(desc|asc)$/; my $order_by = $types{$1} || $1; + # field to use for report age cutoff + $c->stash->{report_age_field} = $order_by eq 'comment_count' ? 'lastupdate' : $order_by; my $dir = $2; $order_by = { -desc => $order_by } if $dir eq 'desc'; $c->stash->{sort_order} = $order_by; + return 1; } diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 816c5e315..836b6af58 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -445,6 +445,10 @@ sub reports_per_page { return FixMyStreet->config('ALL_REPORTS_PER_PAGE') || 100; } +sub report_age { + return '6 months'; +} + =item reports_ordering The order_by clause to use for reports on all reports page diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index b075e3664..3d8f87b9f 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, $categories, $states, $extra_params ) = @_; + my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $categories, $states, $extra_params, $report_age ) = @_; unless ( $states ) { $states = FixMyStreet::DB::Result::Problem->visible_states(); @@ -23,6 +23,9 @@ sub nearby { if $ids; $params->{category} = $categories if $categories && @$categories; + $params->{$c->stash->{report_age_field}} = { '>=', \"current_timestamp-'$report_age'::interval" } + if $report_age; + FixMyStreet::DB::ResultSet::Problem->non_public_if_possible($params, $c); $rs = $c->cobrand->problems_restriction($rs); diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 967c90af5..cc28e4c33 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -172,6 +172,9 @@ sub around_map { latitude => { '>=', $p{min_lat}, '<', $p{max_lat} }, longitude => { '>=', $p{min_lon}, '<', $p{max_lon} }, }; + + $q->{$c->stash->{report_age_field}} = { '>=', \"current_timestamp-'$p{report_age}'::interval" } if + $p{report_age}; $q->{category} = $p{categories} if $p{categories} && @{$p{categories}}; $rs->non_public_if_possible($q, $c); diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index f5d4c1db6..8ed0c4b37 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -92,19 +92,34 @@ sub map_features { $p{latitude} = Utils::truncate_coordinate(($p{max_lat} + $p{min_lat} ) / 2); } + my $report_age = $c->stash->{show_old_reports} ? undef : $c->cobrand->report_age; + $p{report_age} = $report_age; + $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 ]; + if ( $c->{stash}->{show_old_reports} ) { + # if show_old_reports is on then there must be old reports + $c->stash->{num_old_reports} = 1; + } else { + $p{report_age} = undef; + $p{page} = 1; + my $older = $c->cobrand->problems_on_map->around_map( $c, %p ); + $c->stash->{num_old_reports} = $older->pager->total_entries - $pager->total_entries; + } + my $dist = FixMyStreet::Gaze::get_radius_containing_population( $p{latitude}, $p{longitude} ); + # if there are fewer entries than our paging limit on the map then + # also return nearby entries for display 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", "extra"} + $c, $dist, \@ids, $limit, @p{"latitude", "longitude", "categories", "states", "extra"}, $report_age ); } diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 02abefe7e..dc755a67f 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -137,9 +137,9 @@ subtest 'check non public reports are not displayed on around page' => sub { }; -subtest 'check category, status and extra filtering works on /around' => sub { - my $body = $mech->create_body_ok(2237, "Oxfordshire"); +my $body = $mech->create_body_ok(2237, "Oxfordshire"); +subtest 'check category, status and extra filtering works on /around' => sub { my $categories = [ 'Pothole', 'Vegetation', 'Flytipping' ]; my $params = { postcode => 'OX20 1SZ', @@ -195,6 +195,76 @@ subtest 'check category, status and extra filtering works on /around' => sub { is scalar @$pins, 1, 'correct number of external_body reports'; }; +subtest 'check old problems not shown by default on around page' => sub { + my $params = { + postcode => 'OX20 1SZ', + latitude => 51.754926, + longitude => -1.256179, + }; + my $bbox = ($params->{longitude} - 0.01) . ',' . ($params->{latitude} - 0.01) + . ',' . ($params->{longitude} + 0.01) . ',' . ($params->{latitude} + 0.01); + + my $json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox ); + my $pins = $json->{pins}; + is scalar @$pins, 9, 'correct number of reports when no age'; + + my $problems = FixMyStreet::App->model('DB::Problem')->to_body( $body->id ); + $problems->first->update( { confirmed => \"current_timestamp-'7 months'::interval" } ); + + $json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox ); + $pins = $json->{pins}; + is scalar @$pins, 8, 'correct number of reports with old report'; + + $json = $mech->get_ok_json( '/around?show_old_reports=1&ajax=1&bbox=' . $bbox ); + $pins = $json->{pins}; + is scalar @$pins, 9, 'correct number of reports with show_old_reports'; + + $problems->update( { confirmed => \"current_timestamp" } ); +}; + +subtest 'check sorting by update uses lastupdate to determine age' => sub { + my $params = { + postcode => 'OX20 1SZ', + latitude => 51.754926, + longitude => -1.256179, + }; + my $bbox = ($params->{longitude} - 0.01) . ',' . ($params->{latitude} - 0.01) + . ',' . ($params->{longitude} + 0.01) . ',' . ($params->{latitude} + 0.01); + + my $problems = FixMyStreet::App->model('DB::Problem')->to_body( $body->id ); + $problems->first->update( { confirmed => \"current_timestamp-'7 months'::interval" } ); + + my $json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox ); + my $pins = $json->{pins}; + is scalar @$pins, 8, 'correct number of reports with default sorting'; + + + $json = $mech->get_ok_json( '/around?ajax=1&sort=updated-desc&bbox=' . $bbox ); + $pins = $json->{pins}; + is scalar @$pins, 9, 'correct number of reports with updated sort'; + + $problems->update( { confirmed => \"current_timestamp" } ); +}; + +subtest 'check show old reports checkbox shown on around page' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->get_ok( '/around?pc=OX20+1SZ' ); + $mech->content_contains('id="show_old_reports_wrapper" class="report-list-filters hidden"'); + + my $problems = FixMyStreet::App->model('DB::Problem')->to_body( $body->id ); + $problems->first->update( { confirmed => \"current_timestamp-'7 months'::interval" } ); + + $mech->get_ok( '/around?pc=OX20+1SZ' ); + $mech->content_lacks('id="show_old_reports_wrapper" class="report-list-filters hidden"'); + $mech->content_contains('id="show_old_reports_wrapper" class="report-list-filters"'); + + $problems->update( { confirmed => \"current_timestamp" } ); + }; +}; + subtest 'check skip_around skips around page' => sub { my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Default'); $cobrand->mock('skip_around_page', sub { 1 }); diff --git a/t/map/tilma/original.t b/t/map/tilma/original.t index e89251285..42cbbd9f2 100644 --- a/t/map/tilma/original.t +++ b/t/map/tilma/original.t @@ -91,6 +91,7 @@ for my $test ( subtest "pin colour for state $test->{state}" => sub { $report->state($test->{state}); $report->update; + $c->stash->{report_age_field} = 'lastupdate'; my ( $on_map, $nearby, $dist ) = FixMyStreet::Map::map_features($c, bbox => "0,0,0,0"); diff --git a/templates/web/base/around/on_map_list_items.html b/templates/web/base/around/on_map_list_items.html index e1be87754..dddaf6341 100644 --- a/templates/web/base/around/on_map_list_items.html +++ b/templates/web/base/around/on_map_list_items.html @@ -1,4 +1,4 @@ -<ul class="item-list item-list--reports"> +<ul class="item-list item-list--reports"[%' data-show-old-reports="1"' IF num_old_reports > 0 %]> [% IF on_map.size %] [% FOREACH problem IN on_map %] [% INCLUDE 'reports/_list-entry.html' %] diff --git a/templates/web/base/pagination.html b/templates/web/base/pagination.html index 7c13ec9cb..7ae3559ce 100644 --- a/templates/web/base/pagination.html +++ b/templates/web/base/pagination.html @@ -8,6 +8,8 @@ [% IF pager.next_page %] <a class="next" href="[% c.uri_with({ $param => pager.next_page, ajax => undefined }) %][% '#' _ hash IF hash %]">[% loc('Next') %]</a> + [% ELSIF num_old_reports > 0 AND NOT show_old_reports AND page == 'around' %] + <a class="next show_old" href="[% c.uri_with({ $param => pager.current_page, show_old_reports = 1, ajax => undefined }) %][% '#' _ hash IF hash %]">[% loc('Show older') %]</a> [% END %] </p> [% END %] diff --git a/templates/web/base/reports/_list-filters.html b/templates/web/base/reports/_list-filters.html index 61cff8de0..002bfc6c2 100644 --- a/templates/web/base/reports/_list-filters.html +++ b/templates/web/base/reports/_list-filters.html @@ -80,6 +80,13 @@ </select> <input type="submit" name="filter_update" value="[% loc('Go') %]"> </p> + [% IF page == 'around' %] + <p id="show_old_reports_wrapper" class="report-list-filters[% ' hidden' UNLESS num_old_reports > 0 %]"> + <label for="show_old_reports">[% loc('Show older reports') %]</label> + <input type="checkbox" name="show_old_reports" id="show_old_reports" value="1"[% ' checked' IF show_old_reports %]> + <input type="submit" name="filter_update" value="[% loc('Go') %]"> + </p> + [% END %] [% IF use_form_wrapper %] </form> diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index a7df18187..26b0b293a 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -1280,6 +1280,7 @@ $(function() { if (fixmystreet.utils && fixmystreet.utils.parse_query_string) { var qs = fixmystreet.utils.parse_query_string(); var page = qs.p || 1; + $('#show_old_reports').prop('checked', qs.show_old_reports || ''); $('.pagination:first').data('page', page) .trigger('change.filters'); } @@ -1290,6 +1291,7 @@ $(function() { fixmystreet.display.begin_report(e.state.newReportAtLonlat, false); } else if ('page_change' in e.state) { fixmystreet.markers.protocol.use_page = true; + $('#show_old_reports').prop('checked', e.state.page_change.show_old_reports); $('.pagination:first').data('page', e.state.page_change.page) //; .trigger('change.filters'); if ( fixmystreet.page != 'reports' ) { @@ -1299,6 +1301,7 @@ $(function() { $('#filter_categories').val(e.state.filter_change.filter_categories); $('#statuses').val(e.state.filter_change.statuses); $('#sort').val(e.state.filter_change.sort); + $('#show_old_reports').prop('checked', e.state.filter_change.show_old_reports); $('#filter_categories').add('#statuses') .trigger('change.filters').trigger('change.multiselect'); fixmystreet.display.reports_list(location.href); diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 281940aca..3c9e3fb91 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -361,8 +361,14 @@ $.extend(fixmystreet.utils, { function replace_query_parameter(qs, id, key) { var value = $('#' + id).val(); + if ( $('#' + id).prop('type') == 'checkbox' ) { + value = $('#' + id).prop('checked') ? '1' : ''; + } else if (value) { + value = (typeof value === 'string') ? value : fixmystreet.utils.array_to_csv_line(value); + } + if (value) { - qs[key] = (typeof value === 'string') ? value : fixmystreet.utils.array_to_csv_line(value); + qs[key] = value; } else { delete qs[key]; } @@ -387,15 +393,17 @@ $.extend(fixmystreet.utils, { } var qs = fixmystreet.utils.parse_query_string(); + var show_old_reports = ''; var page = $('.pagination:first').data('page'); if (page > 1) { + show_old_reports = replace_query_parameter(qs, 'show_old_reports', 'show_old_reports'); qs.p = page; } else { delete qs.p; } var new_url = update_url(qs); history.pushState({ - page_change: { 'page': page } + page_change: { 'page': page, 'show_old_reports': show_old_reports } }, null, new_url); } @@ -407,10 +415,11 @@ $.extend(fixmystreet.utils, { var filter_categories = replace_query_parameter(qs, 'filter_categories', 'filter_category'); var filter_statuses = replace_query_parameter(qs, 'statuses', 'status'); var sort_key = replace_query_parameter(qs, 'sort', 'sort'); + var show_old_reports = replace_query_parameter(qs, 'show_old_reports', 'show_old_reports'); delete qs.p; var new_url = update_url(qs); history.pushState({ - filter_change: { 'filter_categories': filter_categories, 'statuses': filter_statuses, 'sort': sort_key } + filter_change: { 'filter_categories': filter_categories, 'statuses': filter_statuses, 'sort': sort_key, 'show_old_reports': show_old_reports } }, null, new_url); } @@ -640,11 +649,14 @@ $.extend(fixmystreet.utils, { $("#filter_categories").on("change.filters", categories_or_status_changed); $("#statuses").on("change.filters", categories_or_status_changed); $("#sort").on("change.filters", categories_or_status_changed); + $("#show_old_reports").on("change.filters", categories_or_status_changed); $('.js-pagination').on('change.filters', categories_or_status_changed); $('.js-pagination').on('click', 'a', function(e) { e.preventDefault(); var page = $('.pagination:first').data('page'); - if ($(this).hasClass('next')) { + if ($(this).hasClass('show_old')) { + $("#show_old_reports").prop('checked', true); + } else if ($(this).hasClass('next')) { $('.pagination:first').data('page', page + 1); } else { $('.pagination:first').data('page', page - 1); @@ -655,6 +667,7 @@ $.extend(fixmystreet.utils, { $("#filter_categories").on("change.user", categories_or_status_changed_history); $("#statuses").on("change.user", categories_or_status_changed_history); $("#sort").on("change.user", categories_or_status_changed_history); + $("#show_old_reports").on("change.user", categories_or_status_changed_history); $('.js-pagination').on('click', 'a', page_changed_history); } else if (fixmystreet.page == 'new') { drag.activate(); @@ -914,6 +927,9 @@ OpenLayers.Protocol.FixMyStreet = OpenLayers.Class(OpenLayers.Protocol.HTTP, { options.params[key] = val.join ? fixmystreet.utils.array_to_csv_line(val) : val; } }); + if ( $('#show_old_reports').is(':checked') ) { + options.params.show_old_reports = 1; + } var page; if (this.use_page) { page = $('.pagination:first').data('page'); @@ -942,6 +958,11 @@ OpenLayers.Format.FixMyStreet = OpenLayers.Class(OpenLayers.Format.JSON, { var reports_list; if (typeof(obj.reports_list) != 'undefined' && (reports_list = document.getElementById('js-reports-list'))) { reports_list.innerHTML = obj.reports_list; + if ( $('.item-list--reports').data('show-old-reports') ) { + $('#show_old_reports_wrapper').removeClass('hidden'); + } else { + $('#show_old_reports_wrapper').addClass('hidden'); + } } if (typeof(obj.pagination) != 'undefined') { $('.js-pagination').html(obj.pagination); |