Merge pull request #3676 from harry-wood/notes-disappear-time

Display how long until a note will disappear
This commit is contained in:
Andy Allan 2022-11-23 15:44:26 +00:00 committed by GitHub
commit 067b0de439
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 5 deletions

View file

@ -360,9 +360,9 @@ module Api
# on their status and the user's request parameters # on their status and the user's request parameters
def closed_condition(notes) def closed_condition(notes)
closed_since = if params[:closed] closed_since = if params[:closed]
params[:closed].to_i params[:closed].to_i.days
else else
7 Note::DEFAULT_FRESHLY_CLOSED_LIMIT
end end
if closed_since.negative? if closed_since.negative?
@ -370,7 +370,7 @@ module Api
elsif closed_since.positive? elsif closed_since.positive?
notes.where(:status => "open") notes.where(:status => "open")
.or(notes.where(:status => "closed") .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 else
notes.where(:status => "open") notes.where(:status => "open")
end end

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) link_to h(author.display_name), link_options.merge(:controller => "/users", :action => "show", :display_name => author.display_name)
end end
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

View file

@ -37,6 +37,8 @@ class Note < ApplicationRecord
after_initialize :set_defaults after_initialize :set_defaults
DEFAULT_FRESHLY_CLOSED_LIMIT = 7.days
# Sanity check the latitude and longitude and add an error if it's broken # Sanity check the latitude and longitude and add an error if it's broken
def validate_position def validate_position
errors.add(:base, "Note is not in the world") unless in_world? errors.add(:base, "Note is not in the world") unless in_world?
@ -66,6 +68,18 @@ class Note < ApplicationRecord
!closed_at.nil? !closed_at.nil?
end 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 # Return the author object, derived from the first comment
def author def author
comments.first.author comments.first.author

View file

@ -71,6 +71,21 @@
<% end %> <% end %>
<% if current_user && current_user != @note.author %> <% 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 %> <% end %>
</div> </div>

View file

@ -2918,7 +2918,10 @@ en:
reactivate: Reactivate reactivate: Reactivate
comment_and_resolve: Comment & Resolve comment_and_resolve: Comment & Resolve
comment: Comment 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. edit_help: Move the map and zoom in on a location you want to edit, then click here.
directions: directions:
ascend: "Ascend" 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=\"/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) 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 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