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 / filters_helper.rb @ 1012:bbca6f4eebc7

History | View | Annotate | Download (2.14 KB)

1
# 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 FiltersHelper
20
  # returns link to the page with issues filtered by specified filters
21
  # === parameters
22
  # * <i>title</i> = link title text
23
  # * <i>filters</i> = filters to be applied (see <tt>link_to_filter_options</tt> for details)
24
  # * <i>options</i> = (optional) base options of the link
25
  # === example
26
  # link_to_filter 'foobar', [[ :tags, '~', 'foobar' ]]
27
  # link_to_filter 'foobar', [[ :tags, '~', 'foobar' ]], :project_id => project
28
  def link_to_filter(title, filters, options = {})
29
    options.merge! link_to_filter_options(filters)
30
    link_to title, options
31
  end
32

    
33

    
34
  # returns hash suitable for passing it to the <tt>to_link</tt>
35
  # === parameters
36
  # * <i>filters</i> = array of arrays. each child array is an array of strings:
37
  #                    name, operator and value
38
  # === example
39
  # link_to 'foobar', link_to_filter_options [[ :tags, '~', 'foobar' ]]
40
  #
41
  # filters = [[ :tags, '~', 'bazbaz' ], [:status_id, 'o']]
42
  # link_to 'bazbaz', link_to_filter_options filters
43
  def link_to_filter_options(filters)
44
    options = {
45
      :controller => 'issues',
46
      :action => 'index',
47
      :set_filter => 1,
48
      :fields => [],
49
      :values => {},
50
      :operators => {}
51
    }
52

    
53
    filters.each do |f|
54
      name, operator, value = f
55
      options[:fields].push(name)
56
      options[:operators][name] = operator
57
      options[:values][name] = [value]
58
    end
59

    
60
    options
61
  end
62
end