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 @ 751:7bf2d69e9aeb

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