To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / plugins / redmine_tags / app / helpers / tags_helper.rb @ 757:d38f5a55c590

History | View | Annotate | Download (3.13 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 751:7bf2d69e9aeb luis
  def render_project_tag_link(tag)
44 752:ded6cd947ade luis
    content = link_to tag.name, :controller => :projects, :action => :index, :project => { :tag_list => tag.name }
45 751:7bf2d69e9aeb luis
    content_tag('span', content, :class => 'tag-label')
46
  end
47
48
49 593:f12948591050 chris
  # Renders list of tags
50
  # Clouds are rendered as block <tt>div</tt> with internal <tt>span</t> per tag.
51
  # Lists are rendered as unordered lists <tt>ul</tt>. Lists are ordered by
52
  # <tt>tag.count</tt> descending.
53
  # === Parameters
54
  # * <i>tags</i> = Array of Tag instances
55
  # * <i>options</i> = (optional) Options (override system settings)
56
  #   * show_count  - Boolean. Whenever show tag counts
57
  #   * open_only   - Boolean. Whenever link to the filter with "open" issues
58
  #                   only limit.
59
  #   * style       - list, cloud
60
  def render_tags_list(tags, options = {})
61
    unless tags.nil? or tags.empty?
62
      content, style = '', options.delete(:style)
63
64
      tags.sort! { |a,b| b.count <=> a.count }
65
66
      if :list == style
67
        list_el, item_el = 'ul', 'li'
68
      elsif :cloud == style
69
        list_el, item_el = 'div', 'span'
70
        tags = cloudify(tags)
71
      else
72
        raise "Unknown list style"
73
      end
74
75
      tag_cloud tags, (1..8).to_a do |tag, weight|
76
        content << " " + content_tag(item_el, render_tag_link(tag, options), :class => "tag-nube-#{weight}") + " "
77
      end
78
79
      content_tag(list_el, content, :class => 'tags')
80
    end
81
  end
82
83
  private
84
  # put most massive tags in the middle
85
  def cloudify(tags)
86
    temp, tags, trigger = tags, [], true
87
    temp.each do |tag|
88
      tags.send((trigger ? 'push' : 'unshift'), tag)
89
      trigger = !trigger
90
    end
91
    tags
92
  end
93
94
end