]> git.openstreetmap.org Git - rails.git/commitdiff
Display how long until a note will disappear
authorHarry Wood <github@harrywood.co.uk>
Thu, 1 Sep 2022 23:51:59 +0000 (00:51 +0100)
committerHarry Wood <github@harrywood.co.uk>
Wed, 14 Sep 2022 22:59:25 +0000 (23:59 +0100)
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

app/helpers/note_helper.rb
app/models/note.rb
app/views/browse/note.html.erb
config/locales/en.yml
test/helpers/note_helper_test.rb

index 7e52937a008f94903a9e2c9fe57ea2c3e541f275..809480a04020df137e8b7b98e5c32d9da01605bb 100644 (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
       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
 end
index 8c61374790af4cf2b65c8099d544753136e9b995..c3e0d776c61416fb32ed29d0af81c05279cff1e6 100644 (file)
@@ -66,6 +66,18 @@ class Note < ApplicationRecord
     !closed_at.nil?
   end
 
     !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
   # Return the author object, derived from the first comment
   def author
     comments.first.author
index fb186e55e49130f1360939fe687c815cd890f300..29c5ca3e15539654e327e859d43002cc2f6250b6 100644 (file)
   <% end %>
 
   <% if current_user && current_user != @note.author %>
   <% 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>
   <% end %>
 </div>
index 55bd1c0a85c1bbf07ef4452601127b07c5a12a7d..c7664c83c7cb28fc6c9b0d989fa1d286da2b00d1 100644 (file)
@@ -2888,7 +2888,10 @@ en:
         reactivate: Reactivate
         comment_and_resolve: Comment & Resolve
         comment: Comment
         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"
     edit_help: Move the map and zoom in on a location you want to edit, then click here.
     directions:
       ascend: "Ascend"
index 838217e405afd05c297c66bee32046158df8d46a..d5f3021fbf6dc97a90920558336d4eef918fdb20 100644 (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
     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
 end