]> git.openstreetmap.org Git - rails.git/commitdiff
Merge pull request #3676 from harry-wood/notes-disappear-time
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 23 Nov 2022 15:44:26 +0000 (15:44 +0000)
committerGitHub <noreply@github.com>
Wed, 23 Nov 2022 15:44:26 +0000 (15:44 +0000)
Display how long until a note will disappear

app/controllers/api/notes_controller.rb
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 5e24aa7858ddf1c70b6106baee616a7ce385b1eb..5e24532e79bf7f31594a82db9143465aa502dcbf 100644 (file)
@@ -360,9 +360,9 @@ module Api
     # on their status and the user's request parameters
     def closed_condition(notes)
       closed_since = if params[:closed]
-                       params[:closed].to_i
+                       params[:closed].to_i.days
                      else
-                       7
+                       Note::DEFAULT_FRESHLY_CLOSED_LIMIT
                      end
 
       if closed_since.negative?
@@ -370,7 +370,7 @@ module Api
       elsif closed_since.positive?
         notes.where(:status => "open")
              .or(notes.where(:status => "closed")
-                      .where(notes.arel_table[:closed_at].gt(Time.now.utc - closed_since.days)))
+                      .where(notes.arel_table[:closed_at].gt(Time.now.utc - closed_since)))
       else
         notes.where(:status => "open")
       end
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
+
+  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
index 8c61374790af4cf2b65c8099d544753136e9b995..0b0597434f0fa5842f31862da19bdf9ec1711da6 100644 (file)
@@ -37,6 +37,8 @@ class Note < ApplicationRecord
 
   after_initialize :set_defaults
 
+  DEFAULT_FRESHLY_CLOSED_LIMIT = 7.days
+
   # Sanity check the latitude and longitude and add an error if it's broken
   def validate_position
     errors.add(:base, "Note is not in the world") unless in_world?
@@ -66,6 +68,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 + DEFAULT_FRESHLY_CLOSED_LIMIT
+  end
+
   # Return the author object, derived from the first comment
   def author
     comments.first.author
index 1181e0b034f0caadb2c0dd7201673100f1f7dab7..a814d8c8b13a8dc44ec68aa59b5ff6ce003523a6 100644 (file)
   <% 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>
index 6a32e29a2ac0de6be7cddf8e6ff6b3ea7201756b..e05dfd8d03ede1c7f48cd01be575e7f34627ccd0 100644 (file)
@@ -2918,7 +2918,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"
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
+
+  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