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 @ 1078:b9e34a051f82

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