introduce label_with_count helper

This commit is contained in:
Alexander Meindl 2023-12-12 20:47:32 +01:00
parent c7cbb3b2ed
commit 44d68a65e5
5 changed files with 14 additions and 8 deletions

View File

@ -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',

View File

@ -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

View File

@ -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?

View File

@ -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

View File

@ -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?
@ -137,7 +146,7 @@ module Additionals
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