To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / plugins / redmine_tags / app / helpers / tags_helper.rb @ 1309:5ed688bfd441
History | View | Annotate | Download (4 KB)
| 1 | 593:f12948591050 | chris | # This file is a part of redmine_tags
|
|---|---|---|---|
| 2 | # redMine plugin, that adds tagging support.
|
||
| 3 | #
|
||
| 4 | # Copyright (c) 2010 Aleksey V Zapparov AKA ixti
|
||
| 5 | #
|
||
| 6 | # redmine_tags is free software: you can redistribute it and/or modify
|
||
| 7 | # it under the terms of the GNU General Public License as published by
|
||
| 8 | # the Free Software Foundation, either version 3 of the License, or
|
||
| 9 | # (at your option) any later version.
|
||
| 10 | #
|
||
| 11 | # redmine_tags is distributed in the hope that it will be useful,
|
||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 14 | # GNU General Public License for more details.
|
||
| 15 | #
|
||
| 16 | # You should have received a copy of the GNU General Public License
|
||
| 17 | # along with redmine_tags. If not, see <http://www.gnu.org/licenses/>.
|
||
| 18 | |||
| 19 | module TagsHelper |
||
| 20 | include ActsAsTaggableOn::TagsHelper |
||
| 21 | include FiltersHelper
|
||
| 22 | |||
| 23 | |||
| 24 | # Returns tag link
|
||
| 25 | # === Parameters
|
||
| 26 | # * <i>tag</i> = Instance of Tag
|
||
| 27 | # * <i>options</i> = (optional) Options (override system settings)
|
||
| 28 | # * show_count - Boolean. Whenever show tag counts
|
||
| 29 | # * open_only - Boolean. Whenever link to the filter with "open" issues
|
||
| 30 | # only limit.
|
||
| 31 | def render_tag_link(tag, options = {}) |
||
| 32 | filters = [[:tags, '=', tag.name]] |
||
| 33 | filters << [:status_id, 'o'] if options[:open_only] |
||
| 34 | |||
| 35 | content = link_to_filter tag.name, filters, :project_id => @project |
||
| 36 | if options[:show_count] |
||
| 37 | content << content_tag('span', "(#{tag.count})", :class => 'tag-count') |
||
| 38 | end
|
||
| 39 | |||
| 40 | content_tag('span', content, :class => 'tag-label') |
||
| 41 | end
|
||
| 42 | |||
| 43 | 998:a2660a5eb395 | chris | def render_project_tag_link(tag, options = {}) |
| 44 | 1259:94a6e3687c45 | luis | content = link_to tag.name, :controller => :projects, :action => :index, :tag_search => tag.name |
| 45 | |||
| 46 | 998:a2660a5eb395 | chris | if options[:show_count] |
| 47 | content << content_tag('span', "(#{tag.count})", :class => 'tag-count') |
||
| 48 | end
|
||
| 49 | 751:7bf2d69e9aeb | luis | content_tag('span', content, :class => 'tag-label') |
| 50 | end
|
||
| 51 | |||
| 52 | |||
| 53 | 593:f12948591050 | chris | # Renders list of tags
|
| 54 | # Clouds are rendered as block <tt>div</tt> with internal <tt>span</t> per tag.
|
||
| 55 | # Lists are rendered as unordered lists <tt>ul</tt>. Lists are ordered by
|
||
| 56 | # <tt>tag.count</tt> descending.
|
||
| 57 | # === Parameters
|
||
| 58 | # * <i>tags</i> = Array of Tag instances
|
||
| 59 | # * <i>options</i> = (optional) Options (override system settings)
|
||
| 60 | # * show_count - Boolean. Whenever show tag counts
|
||
| 61 | # * open_only - Boolean. Whenever link to the filter with "open" issues
|
||
| 62 | # only limit.
|
||
| 63 | # * style - list, cloud
|
||
| 64 | def render_tags_list(tags, options = {}) |
||
| 65 | unless tags.nil? or tags.empty? |
||
| 66 | content, style = '', options.delete(:style) |
||
| 67 | 1132:9b2f28ecd125 | luis | |
| 68 | # prevent ActsAsTaggableOn::TagsHelper from calling `all`
|
||
| 69 | # otherwise we will need sort tags after `tag_cloud`
|
||
| 70 | tags = tags.all if tags.respond_to?(:all) |
||
| 71 | |||
| 72 | case sorting = "#{RedmineTags.settings[:issues_sort_by]}:#{RedmineTags.settings[:issues_sort_order]}" |
||
| 73 | when "name:asc"; tags.sort! { |a,b| a.name <=> b.name } |
||
| 74 | when "name:desc"; tags.sort! { |a,b| b.name <=> a.name } |
||
| 75 | when "count:asc"; tags.sort! { |a,b| a.count <=> b.count } |
||
| 76 | when "count:desc"; tags.sort! { |a,b| b.count <=> a.count } |
||
| 77 | # Unknown sorting option. Fallback to default one
|
||
| 78 | else
|
||
| 79 | logger.warn "[redmine_tags] Unknown sorting option: <#{sorting}>"
|
||
| 80 | tags.sort! { |a,b| a.name <=> b.name }
|
||
| 81 | end
|
||
| 82 | 593:f12948591050 | chris | |
| 83 | if :list == style |
||
| 84 | list_el, item_el = 'ul', 'li' |
||
| 85 | elsif :cloud == style |
||
| 86 | list_el, item_el = 'div', 'span' |
||
| 87 | tags = cloudify(tags) |
||
| 88 | else
|
||
| 89 | raise "Unknown list style"
|
||
| 90 | end
|
||
| 91 | |||
| 92 | 1132:9b2f28ecd125 | luis | content = content.html_safe |
| 93 | 593:f12948591050 | chris | tag_cloud tags, (1..8).to_a do |tag, weight| |
| 94 | 1309:5ed688bfd441 | chris | content << " ".html_safe + content_tag(item_el, render_project_tag_link(tag, options), :class => "tag-nube-#{weight}") + " ".html_safe |
| 95 | 593:f12948591050 | chris | end
|
| 96 | |||
| 97 | content_tag(list_el, content, :class => 'tags') |
||
| 98 | end
|
||
| 99 | end
|
||
| 100 | |||
| 101 | private |
||
| 102 | 1132:9b2f28ecd125 | luis | |
| 103 | # make snowball. first tags comes in th middle.
|
||
| 104 | 593:f12948591050 | chris | def cloudify(tags) |
| 105 | temp, tags, trigger = tags, [], true
|
||
| 106 | temp.each do |tag|
|
||
| 107 | tags.send((trigger ? 'push' : 'unshift'), tag) |
||
| 108 | trigger = !trigger |
||
| 109 | end
|
||
| 110 | tags |
||
| 111 | end
|
||
| 112 | |||
| 113 | end |