diff options
author | pezholio <pezholio@gmail.com> | 2017-01-24 16:20:48 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2017-02-27 13:18:03 +0000 |
commit | 587a125c46f229ed23aaf68d3308f6755e2d8299 (patch) | |
tree | c6bff793a2dd44bc249326fdf8b2c187e20ef4ea | |
parent | 36838708a432de937828f6a8ef4aff608654f900 (diff) |
[Oxfordshire] Use 'days ago' format on problem lists
Fixes mysociety/fixmystreetforcouncils#98
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 14 | ||||
-rw-r--r-- | t/app/model/problem.t | 15 | ||||
-rw-r--r-- | templates/web/base/report/_item.html | 12 |
5 files changed, 51 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 63db8b64a..6d9f38d78 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -1204,4 +1204,15 @@ sub traffic_management_options { ]; } + +=head2 display_days_ago_threshold + +Used to control whether a relative 'n days ago' or absolute date is shown +for problems/updates. If a problem/update's `days_ago` value is <= this figure, +the 'n days ago' format is used. By default the absolute date is always used. + +=cut +sub display_days_ago_threshold { 0 } + + 1; diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index 7fa548406..2820719b9 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -165,4 +165,6 @@ sub user_extra_fields { return [ 'initials' ]; } +sub display_days_ago_threshold { 28 } + 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index d78eda78f..4ccad3690 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -697,6 +697,20 @@ sub time_ago { return Utils::prettify_duration( $duration ); } +=head2 days_ago + + Returns how many days ago a problem was reported. + +=cut + +sub days_ago { + my ( $self, $date ) = @_; + $date ||= 'confirmed'; + my $now = DateTime->now( time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone ); + my $duration = $now->delta_days($self->$date); + return $duration->delta_days; +} + =head2 response_templates Returns all ResponseTemplates attached to this problem's bodies, in alphabetical diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 52213ed51..b942a5333 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -833,7 +833,6 @@ subtest 'get report time ago in appropriate format' => sub { confirmed => DateTime->now->subtract( years => 2 ) } ); is $problem->time_ago, '2 years', 'problem returns time ago in years'; - }; subtest 'time ago works with other dates' => sub { @@ -845,6 +844,20 @@ subtest 'time ago works with other dates' => sub { is $problem->time_ago('lastupdate'), '4 days', 'problem returns last updated time ago in days'; }; +subtest 'return how many days ago a problem was reported' => sub { + my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE'); + $problem->update( { + confirmed => DateTime->now->subtract( weeks => 2 ) + } ); + is $problem->days_ago, 14, 'days_ago returns the amount of days'; + + $problem->update( { + lastupdate => DateTime->now->subtract( days => 4) + } ); + + is $problem->days_ago('lastupdate'), 4, 'days_ago allows other dates to be specified'; +}; + END { $problem->comments->delete if $problem; $problem->delete if $problem; diff --git a/templates/web/base/report/_item.html b/templates/web/base/report/_item.html index e233ff09f..a561c4c8d 100644 --- a/templates/web/base/report/_item.html +++ b/templates/web/base/report/_item.html @@ -45,13 +45,21 @@ <span class="item-list__item__state">[% problem.response_priority.name %]</span> [% END %] [%- IF c.cobrand.moniker != 'fixamingata' %] [%# Default: %] - [%- prettify_dt( problem.confirmed, 1 ) %] + [%- IF problem.days_ago > 0 AND problem.days_ago <= c.cobrand.display_days_ago_threshold %] + [% tprintf( nget( loc('Reported %d day ago'), loc('Reported %d days ago'), problem.days_ago), problem.days_ago ) %] + [%- ELSE %] + [% prettify_dt( problem.confirmed, 1 ) %] + [%- END %] [%- ELSE %] [%# Swedish cobrand fixamingata: %] [%- prettify_dt( problem.confirmed) %] [%- END %] [%- IF dist %], [% dist %]km[% END %] [%- IF problem.confirmed != problem.lastupdate AND problem.whensent != problem.lastupdate %], - [% tprintf(loc('last updated %s'), prettify_dt( problem.lastupdate, 1 ) ) %] + [%- IF problem.days_ago('lastupdate') > 0 AND problem.days_ago('lastupdate') <= c.cobrand.display_days_ago_threshold %] + [% tprintf(loc('last updated %s days ago'), problem.days_ago('lastupdate') ) %] + [%- ELSE %] + [% tprintf(loc('last updated %s'), prettify_dt( problem.lastupdate, 1 ) ) %] + [%- END %] [%- END %] [% IF include_sentinfo %] [% IF c.cobrand.is_council && !c.cobrand.owns_problem( problem ) %] |