Skip to content

Commit

Permalink
introduce label_with_count helper
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermeindl committed Dec 12, 2023
1 parent c7cbb3b commit 44d68a6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/views/additionals/_select2_ajax_call.js.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- options ||= {}
javascript:
$(function() {
$("#{defined?(field_id) ? ('#' + field_id) : ('.' + field_class)}").select2({
$("#{defined?(field_name_id) ? ('#' + field_name_id) : ('.' + field_class)}").select2({
ajax: {
url: "#{ajax_url}",
dataType: 'json',
Expand Down
2 changes: 1 addition & 1 deletion app/views/additionals_macros/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
h2 = l(:label_settings_macros) + " (#{@available_macros.count})"
h2 = label_with_count :label_settings_macros, @available_macros.count

.info = t :label_top_macros_help_html
br
Expand Down
3 changes: 1 addition & 2 deletions app/views/dashboards/blocks/_query_list.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
query.sort_criteria = params[:sort] if params[:sort].present?

h3.query-list-block
= dashboard_query_list_block_title query, query_block, @project
= " (#{count})"
= label_with_count dashboard_query_list_block_title(query, query_block, @project), count
= dashboard_query_list_block_alerts dashboard, query, block_definition

- if query.respond_to?(:description) && query.description.present?
Expand Down
4 changes: 1 addition & 3 deletions app/views/issues/_hide_attachments.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
- if max_files.present? && file_count > max_files.to_i
fieldset.collapsible.collapsed.hide-attachments
legend.icon.icon-collapsed onclick='toggleFieldset(this);'
strong
= l :label_attachment_plural
= " (#{file_count})"
strong = label_with_count :label_attachment_plural, file_count
.hidden
= link_to_attachments @issue, thumbnails: true
- else
Expand Down
11 changes: 10 additions & 1 deletion lib/additionals/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

module Additionals
module Helpers
def label_with_count(label, info, only_positive: false)
text = label.is_a?(Symbol) ? l(label) : label
if info.blank? || only_positive && !info.positive?
text
else
safe_join [text, ' (', info, ')']
end
end

def render_query_group_view(query, locals = {})
return if locals[:group_name].blank?

Expand Down Expand Up @@ -137,7 +146,7 @@ def autocomplete_select_entries(name, type, option_tags, **options)
s << render(layout: false,
partial: 'additionals/select2_ajax_call',
formats: [:js],
locals: { field_id: sanitize_to_id(name),
locals: { field_name_id: sanitize_to_id(name),
ajax_url: send("#{type}_path", ajax_params),
options: options })
safe_join s
Expand Down

0 comments on commit 44d68a6

Please sign in to comment.