From: Harry Wood Date: Thu, 1 Sep 2022 23:51:59 +0000 (+0100) Subject: Display how long until a note will disappear X-Git-Tag: live~890^2~1 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/d8e51614cb04da1f61ec403af49d249209c1f7f9 Display how long until a note will disappear Modify the message displayed at the bottom of the notes sidepanel. For already resolved notes we don't want to say "please resolve it". Fixes https://github.com/openstreetmap/openstreetmap-website/issues/3663 Instead explain that it will disappear from the map (so reporting is probably not necessary) and display how long to go until that happens. Tackling https://github.com/openstreetmap/openstreetmap-website/issues/3071 --- diff --git a/app/helpers/note_helper.rb b/app/helpers/note_helper.rb index 7e52937a0..809480a04 100644 --- a/app/helpers/note_helper.rb +++ b/app/helpers/note_helper.rb @@ -23,4 +23,9 @@ module NoteHelper link_to h(author.display_name), link_options.merge(:controller => "/users", :action => "show", :display_name => author.display_name) end end + + def disappear_in(note) + date = note.freshly_closed_until + tag.span(distance_of_time_in_words(date, Time.now.utc), :title => l(date, :format => :friendly)) + end end diff --git a/app/models/note.rb b/app/models/note.rb index 8c6137479..c3e0d776c 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -66,6 +66,18 @@ class Note < ApplicationRecord !closed_at.nil? end + def freshly_closed? + return false unless closed? + + Time.now.utc < freshly_closed_until + end + + def freshly_closed_until + return nil unless closed? + + closed_at + 7.days + end + # Return the author object, derived from the first comment def author comments.first.author diff --git a/app/views/browse/note.html.erb b/app/views/browse/note.html.erb index fb186e55e..29c5ca3e1 100644 --- a/app/views/browse/note.html.erb +++ b/app/views/browse/note.html.erb @@ -71,6 +71,21 @@ <% end %> <% if current_user && current_user != @note.author %> -

<%= t "javascripts.notes.show.report_link_html", :link => report_link(t(".report"), @note) %>

+

+ + <%= t "javascripts.notes.show.report_link_html", :link => report_link(t(".report"), @note) %> + <% if @note.status == "open" %> + <%= t "javascripts.notes.show.other_problems_resolve", :link => report_link(t(".report"), @note) %> + <% elsif @note.status == "closed" %> + <%= t "javascripts.notes.show.other_problems_resolved" %> + <% end %> + +

+ <% end %> + + <% if @note.freshly_closed? %> + + <%= t "javascripts.notes.show.disappear_date_html", :disappear_in => disappear_in(@note) %> + <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 55bd1c0a8..c7664c83c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2888,7 +2888,10 @@ en: reactivate: Reactivate comment_and_resolve: Comment & Resolve comment: Comment - report_link_html: "If this note contains sensitive information that needs to be removed, you can %{link}. For all other problems with the note, please resolve it yourself with a comment." + report_link_html: "If this note contains sensitive information that needs to be removed, you can %{link}." + other_problems_resolve: "For all other problems with the note, please resolve it yourself with a comment." + other_problems_resolved: "For all other problems, resolving is sufficient." + disappear_date_html: "This resolved note will disappear from the map in %{disappear_in}." edit_help: Move the map and zoom in on a location you want to edit, then click here. directions: ascend: "Ascend" diff --git a/test/helpers/note_helper_test.rb b/test/helpers/note_helper_test.rb index 838217e40..d5f3021fb 100644 --- a/test/helpers/note_helper_test.rb +++ b/test/helpers/note_helper_test.rb @@ -21,4 +21,13 @@ class NoteHelperTest < ActionView::TestCase assert_equal "#{user.display_name}", note_author(user) assert_equal "#{user.display_name}", note_author(user, :only_path => false) end + + def test_disappear_in + note_closed_date = Time.new(2022, 1, 1, 12, 0, 0, "+00:00") + note = create(:note, :closed_at => note_closed_date) + + travel_to note_closed_date + 1.day do + assert_match %r{^6 days$}, disappear_in(note) + end + end end