Skip to content

Commit

Permalink
Merge pull request #4201 from AntonKhorev/issues-limit-settings
Browse files Browse the repository at this point in the history
Move max value of issues counter to settings
  • Loading branch information
gravitystorm authored Sep 27, 2023
2 parents a569343 + 09225bc commit 0a04667
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/helpers/issues_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def reportable_title(reportable)
end

def open_issues_count
count = Issue.visible_to(current_user).open.limit(100).size
if count > 99
tag.span("99+", :class => "badge count-number")
count = Issue.visible_to(current_user).open.limit(Settings.max_issues_count).size
if count >= Settings.max_issues_count
tag.span(I18n.t("count.at_least_pattern", :count => Settings.max_issues_count), :class => "badge count-number")
elsif count.positive?
tag.span(count, :class => "badge count-number")
end
Expand Down
1 change: 1 addition & 0 deletions config/initializers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
required(:tracepoints_per_page).filled(:int?)
required(:max_number_of_way_nodes).filled(:int?)
required(:max_number_of_relation_members).filled(:int?)
required(:max_issues_count).filled(:int?)
required(:api_timeout).filled(:int?)
required(:imagery_blacklist).maybe(:array?)
required(:status).filled(:str?, :included_in? => ALLOWED_STATUS)
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ en:
formats:
friendly: "%e %B %Y at %H:%M"
blog: "%e %B %Y"
count:
at_least_pattern: "%{count}+"
helpers:
file:
prompt: Choose file
Expand Down
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ max_note_request_area: 25
default_note_query_limit: 100
# Maximum limit on the number of notes returned by the note search api method
max_note_query_limit: 10000
# Maximum value of open issues counter for moderators, anything equal or greater to this value "n" is shown as "n+"
max_issues_count: 99
# Zoom level to use for postcode results from the geocoder
postcode_zoom: 15
# Timeout for API calls in seconds
Expand Down
30 changes: 30 additions & 0 deletions test/helpers/issues_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "test_helper"

class IssuesHelperTest < ActionView::TestCase
attr_accessor :current_user

def test_issues_count
target_user = create(:user)
self.current_user = create(:moderator_user)

n = (Settings.max_issues_count - 1)
n.times do
create(:note_with_comments) do |note|
create(:issue, :reportable => note, :reported_user => target_user, :assigned_role => "moderator")
end
end
expected = <<~HTML.delete("\n")
<span class="badge count-number">#{n}</span>
HTML
assert_dom_equal expected, open_issues_count

n += 1
create(:note_with_comments) do |note|
create(:issue, :reportable => note, :reported_user => target_user, :assigned_role => "moderator")
end
expected = <<~HTML.delete("\n")
<span class="badge count-number">#{n}+</span>
HTML
assert_dom_equal expected, open_issues_count
end
end

0 comments on commit 0a04667

Please sign in to comment.