Module: AdditionalTagsHelper

Includes:
ActsAsTaggableOn::TagsHelper
Included in:
AdditionalTagsController
Defined in:
app/helpers/additional_tags_helper.rb

Instance Method Summary collapse

Instance Method Details

#additional_plain_tag_list(tags, sep: nil) ⇒ Object

plain list of tags



174
175
176
177
178
179
# File 'app/helpers/additional_tags_helper.rb', line 174

def additional_plain_tag_list(tags, sep: nil)
  sep ||= "#{Query.additional_csv_separator} "

  s = tags.present? ? tags.map(&:name) : ['']
  s.join sep
end


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/helpers/additional_tags_helper.rb', line 114

def additional_tag_link(tag_object,
                        link: nil,
                        link_wiki_tag: false,
                        show_count: false,
                        use_colors: nil,
                        name: nil,
                        color_theme: nil,
                        **options)
  options[:project] = @project if options[:project].blank? && @project.present?
  if !options.key?(:display_type) && @query && @query.display_type != @query.default_display_type
    options[:display_type] = @query.display_type
  end

  use_colors = AdditionalTags.use_colors? if use_colors.nil?
  color_theme = AdditionalTags.setting :tags_color_theme if color_theme.nil?

  tag_info = AdditionalTag.new(name: name.nil? ? tag_object.name : name,
                               disable_grouping: !use_colors,
                               color_theme:)
  tag_name = [tag_info.tag_name]

  tag_style = "background-color: #{tag_info.tag_bg_color}; color: #{tag_info.tag_fg_color}" if use_colors

  if tag_info.scoped?
    tag_name << if show_count
                  tag.span tag_info.group_value, class: 'tag-group-value'
                else
                  tag.span tag_info.group_value, class: 'tag-group-value tag-group-nocount'
                end
  end

  tag_name << tag.span(tag_object.count, class: 'tag-count') if show_count

  content = if link
              link_to safe_join(tag_name),
                      link,
                      style: tag_style
            elsif link_wiki_tag
              link = if options[:project].present?
                       project_wiki_index_path options[:project], tag: tag_object.name
                     else
                       wiki_path tag_object.name
                     end
              link_to safe_join(tag_name), link, style: tag_style
            else
              link_to safe_join(tag_name),
                      tag_url(tag_object.name, **options),
                      style: tag_style
            end

  style = if use_colors
            { class: 'additional-tag-label-color', style: tag_style }
          else
            { class: 'tag-label' }
          end

  tag.span content, **style
end


191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'app/helpers/additional_tags_helper.rb', line 191

def additional_tag_links(tag_list, **options)
  return if tag_list.blank?

  unsorted = options.delete :unsorted
  tag_list = AdditionalTags::Tags.sort_tag_list tag_list unless unsorted

  # set defaults if not defined
  options[:use_colors] = AdditionalTags.use_colors? unless options.key? :use_colors
  options[:color_theme] = AdditionalTags.setting :tags_color_theme unless options.key? :color_theme

  safe_join tag_list.map { |tag| additional_tag_link tag, **options },
            additional_tag_sep(use_colors: options[:use_colors])
end

#additional_tag_sep(use_colors: true) ⇒ Object



181
182
183
# File 'app/helpers/additional_tags_helper.rb', line 181

def additional_tag_sep(use_colors: true)
  use_colors ? ' ' : ', '
end

#additional_tags_from_params(str) ⇒ Object



185
186
187
188
189
# File 'app/helpers/additional_tags_helper.rb', line 185

def additional_tags_from_params(str)
  tags = str.is_a?(Array) ? str : str.to_s.split(',')
  tags.map!(&:strip)
  tags.compact_blank
end

#format_tags_json(tags) ⇒ Object



6
7
8
9
10
11
12
13
# File 'app/helpers/additional_tags_helper.rb', line 6

def format_tags_json(tags)
  tags.map do |tag|
    {
      'id' => tag.name,
      'text' => tag.name
    }
  end
end

#issue_tag_status_filter(operator: nil, open_issues_only: false) ⇒ Object



222
223
224
225
226
227
228
# File 'app/helpers/additional_tags_helper.rb', line 222

def issue_tag_status_filter(operator: nil, open_issues_only: false)
  if operator
    { field: :status_id, operator: }
  elsif open_issues_only
    { field: :status_id, operator: 'o' }
  end
end


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'app/helpers/additional_tags_helper.rb', line 205

def link_to_issue_tags_totals(entries:, project:, open_issues_only:)
  sum = if entries.blank? || entries.empty?
          0
        else
          query = IssueQuery.new project:, name: '_'
          query.add_filter 'tags', '*'
          query.filters['status_id'][:operator] = '*' if !open_issues_only && query.filters.key?('status_id')

          query.issue_count
        end

  link_to sum, _project_issues_path(project,
                                    set_filter: 1,
                                    tags: '*',
                                    status_id: open_issues_only ? 'o' : '*')
end

#manageable_tag_column_values(tag) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/additional_tags_helper.rb', line 40

def manageable_tag_column_values(tag)
  columns = []
  manageable_tag_columns.each_value do |column_values|
    cnt = column_values[:counts][tag.id]
    cnt = 0 if cnt.blank?

    columns << if cnt.positive? && column_values[:tag_controller]
                 link_to cnt, tag_url(tag.name, tag_controller: column_values[:tag_controller])
               else
                 cnt
               end
  end
  columns
end

#manageable_tag_columnsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/additional_tags_helper.rb', line 19

def manageable_tag_columns
  return @manageable_tag_columns if defined? @manageable_tag_columns

  columns = {}

  if AdditionalTags.setting? :active_issue_tags
    columns[:issue] = { label: l(:label_issue_plural),
                        tag_controller: :issues,
                        counts: Issue.available_tags.to_h { |tag| [tag.id, tag.count] } }
  end

  if AdditionalTags.setting? :active_wiki_tags
    columns[:wiki] = { label: l(:label_wiki),
                       counts: WikiPage.available_tags.to_h { |tag| [tag.id, tag.count] } }
  end

  call_hook(:helper_additional_manageable_tag_columns, columns:)

  @manageable_tag_columns = columns
end

#manageable_tagsObject



15
16
17
# File 'app/helpers/additional_tags_helper.rb', line 15

def manageable_tags
  AdditionalTags::Tags.sort_tag_list ActsAsTaggableOn::Tag.where({})
end

#render_tags_list(tags, **options) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/helpers/additional_tags_helper.rb', line 79

def render_tags_list(tags, **options)
  return if tags.blank?

  options[:show_count] = AdditionalTags.setting? :show_with_count unless options.key? :show_count
  options[:color_theme] = AdditionalTags.setting :tags_color_theme unless options.key? :color_theme
  options[:use_colors] = AdditionalTags.use_colors? unless options.key? :use_colors

  style = options.key?(:style) ? options.delete(:style) : AdditionalTags.setting(:tags_sidebar).to_sym
  tags = tags.all.to_a if tags.respond_to? :all
  tags = sort_tags_for_list tags

  case style
  when :list
    list_el = 'ul'
    item_el = 'li'
  when :simple_cloud, :cloud
    list_el = 'div'
    item_el = 'span'
  else
    raise 'Unknown list style'
  end

  content = +''.html_safe
  if style == :list && AdditionalTags.setting(:tags_sort_by) == 'name'
    tags.group_by { |tag| tag.name.downcase.first }.each do |letter, grouped_tags|
      content << (item_el, letter.upcase, class: 'letter')
      add_tags style, grouped_tags, content, item_el, options
    end
  else
    add_tags style, tags, content, item_el, options
  end

  (list_el, content, class: 'tags-cloud', style: (style == :simple_cloud ? 'text-align: left;' : ''))
end

#sort_tags_for_list(tags, sort_by: nil, sort_order: nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/additional_tags_helper.rb', line 59

def sort_tags_for_list(tags, sort_by: nil, sort_order: nil)
  return tags if tags.size < 2

  sort_by = AdditionalTags.setting :tags_sort_by if sort_by.blank?
  sort_order = AdditionalTags.setting :tags_sort_order if sort_order.blank?

  case "#{sort_by}:#{sort_order}"
  when 'name:desc'
    tags = AdditionalTags::Tags.sort_tag_list(tags).reverse
  when 'count:asc'
    tags.sort_by!(&:count)
  when 'count:desc'
    tags.sort! { |a, b| b.count <=> a.count }
  else
    tags = AdditionalTags::Tags.sort_tag_list tags
  end

  tags
end

#values_for_sort_directionObject



55
56
57
# File 'app/helpers/additional_tags_helper.rb', line 55

def values_for_sort_direction
  [[l(:label_ascending), 'asc'], [l(:label_descending), 'desc']]
end

#wiki_tags_on_show?Boolean

Returns:

  • (Boolean)


230
231
232
233
234
235
236
# File 'app/helpers/additional_tags_helper.rb', line 230

def wiki_tags_on_show?
  options = { enabled: AdditionalTags.setting?(:active_wiki_tags) }

  call_hook(:helper_wiki_tags_on_show, options:)

  options[:enabled]
end