Module: AdditionalTagsHelper
- Includes:
- ActsAsTaggableOn::TagsHelper
- Included in:
- AdditionalTagsController
- Defined in:
- app/helpers/additional_tags_helper.rb
Instance Method Summary collapse
-
#additional_plain_tag_list(tags, sep: nil) ⇒ Object
plain list of tags.
- #additional_tag_link(tag_object, link: nil, link_wiki_tag: false, show_count: false, use_colors: nil, name: nil, color_theme: nil, **options) ⇒ Object
- #additional_tag_links(tag_list, **options) ⇒ Object
- #additional_tag_sep(use_colors: true) ⇒ Object
- #additional_tags_from_params(str) ⇒ Object
- #format_tags_json(tags) ⇒ Object
- #issue_tag_status_filter(operator: nil, open_issues_only: false) ⇒ Object
- #link_to_issue_tags_totals(entries:, project:, open_issues_only:) ⇒ Object
- #manageable_tag_column_values(tag) ⇒ Object
- #manageable_tag_columns ⇒ Object
- #manageable_tags ⇒ Object
- #render_tags_list(tags, **options) ⇒ Object
- #sort_tags_for_list(tags, sort_by: nil, sort_order: nil) ⇒ Object
- #values_for_sort_direction ⇒ Object
- #wiki_tags_on_show? ⇒ Boolean
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(, sep: nil) sep ||= "#{Query.additional_csv_separator} " s = .present? ? .map(&:name) : [''] s.join sep end |
#additional_tag_link(tag_object, link: nil, link_wiki_tag: false, show_count: false, use_colors: nil, name: nil, color_theme: nil, **options) ⇒ Object
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, **) [:project] = @project if [:project].blank? && @project.present? if !.key?(:display_type) && @query && @query.display_type != @query.default_display_type [: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 [:project].present? project_wiki_index_path [: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, **), 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 |
#additional_tag_links(tag_list, **options) ⇒ Object
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, **) return if tag_list.blank? unsorted = .delete :unsorted tag_list = AdditionalTags::Tags.sort_tag_list tag_list unless unsorted # set defaults if not defined [:use_colors] = AdditionalTags.use_colors? unless .key? :use_colors [:color_theme] = AdditionalTags.setting :tags_color_theme unless .key? :color_theme safe_join tag_list.map { |tag| additional_tag_link tag, ** }, additional_tag_sep(use_colors: [: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 (str) = str.is_a?(Array) ? str : str.to_s.split(',') .map!(&:strip) .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 () .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 |
#link_to_issue_tags_totals(entries:, project:, open_issues_only:) ⇒ Object
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 (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_columns ⇒ Object
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..to_h { |tag| [tag.id, tag.count] } } end if AdditionalTags.setting? :active_wiki_tags columns[:wiki] = { label: l(:label_wiki), counts: WikiPage..to_h { |tag| [tag.id, tag.count] } } end call_hook(:helper_additional_manageable_tag_columns, columns:) @manageable_tag_columns = columns end |
#manageable_tags ⇒ Object
15 16 17 |
# File 'app/helpers/additional_tags_helper.rb', line 15 def 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 (, **) return if .blank? [:show_count] = AdditionalTags.setting? :show_with_count unless .key? :show_count [:color_theme] = AdditionalTags.setting :tags_color_theme unless .key? :color_theme [:use_colors] = AdditionalTags.use_colors? unless .key? :use_colors style = .key?(:style) ? .delete(:style) : AdditionalTags.setting(:tags_sidebar).to_sym = .all.to_a if .respond_to? :all = 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' .group_by { |tag| tag.name.downcase.first }.each do |letter, | content << content_tag(item_el, letter.upcase, class: 'letter') style, , content, item_el, end else style, , content, item_el, end content_tag(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_by: nil, sort_order: nil) return if .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' = AdditionalTags::Tags.sort_tag_list().reverse when 'count:asc' .sort_by!(&:count) when 'count:desc' .sort! { |a, b| b.count <=> a.count } else = AdditionalTags::Tags.sort_tag_list end end |
#values_for_sort_direction ⇒ Object
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
230 231 232 233 234 235 236 |
# File 'app/helpers/additional_tags_helper.rb', line 230 def = { enabled: AdditionalTags.setting?(:active_wiki_tags) } call_hook(:helper_wiki_tags_on_show, options:) [:enabled] end |