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
This commit is contained in:
Harry Wood 2022-09-02 00:51:59 +01:00
parent bf11e06e63
commit d8e51614cb
5 changed files with 46 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -71,6 +71,21 @@
<% end %>
<% if current_user && current_user != @note.author %>
<p><small class="text-muted"><%= t "javascripts.notes.show.report_link_html", :link => report_link(t(".report"), @note) %></small></p>
<p>
<small class="text-muted">
<%= 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 %>
</small>
</p>
<% end %>
<% if @note.freshly_closed? %>
<small class="text-muted">
<%= t "javascripts.notes.show.disappear_date_html", :disappear_in => disappear_in(@note) %>
</small>
<% end %>
</div>

View file

@ -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"

View file

@ -21,4 +21,13 @@ class NoteHelperTest < ActionView::TestCase
assert_equal "<a href=\"/user/#{ERB::Util.u(user.display_name)}\">#{user.display_name}</a>", note_author(user)
assert_equal "<a href=\"http://test.host/user/#{ERB::Util.u(user.display_name)}\">#{user.display_name}</a>", 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{^<span title=" 8 January 2022 at 12:00">6 days</span>$}, disappear_in(note)
end
end
end