debian-mirror-gitlab/lib/sidebars/concerns/has_pill.rb

37 lines
829 B
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
# This module introduces the logic to show the "pill" element
# next to the menu item, indicating the a count.
module Sidebars
module Concerns
module HasPill
2021-10-27 15:23:28 +05:30
include ActionView::Helpers::NumberHelper
2021-06-08 01:23:25 +05:30
def has_pill?
false
end
# In this method we will need to provide the query
# to retrieve the elements count
def pill_count
raise NotImplementedError
end
def pill_html_options
{}
end
2021-10-27 15:23:28 +05:30
2021-11-11 11:23:49 +05:30
def format_cached_count(threshold, count)
if count > threshold
2021-10-27 15:23:28 +05:30
number_to_human(
count,
units: { thousand: 'k', million: 'm' }, precision: 1, significant: false, format: '%n%u'
)
else
number_with_delimiter(count)
end
end
2021-06-08 01:23:25 +05:30
end
end
end