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 / lib / redmine_tags / patches / query_patch.rb @ 813:0987c3565751

History | View | Annotate | Download (2.22 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
require_dependency 'query'
20

    
21
module RedmineTags
22
  module Patches
23
    module QueryPatch
24
      def self.included(base)
25
        base.send(:include, InstanceMethods)
26

    
27
        base.class_eval do
28
          unloadable
29

    
30
          alias_method :statement_original, :statement
31
          alias_method :statement, :statement_extended
32

    
33
          alias_method :available_filters_original, :available_filters
34
          alias_method :available_filters, :available_filters_extended
35

    
36
          base.add_available_column(QueryColumn.new(:tags))
37
        end
38
      end
39

    
40

    
41
      module InstanceMethods
42
        def statement_extended
43
          filter  = filters.delete 'tags'
44
          clauses = statement_original
45

    
46
          if filter
47
            filters.merge!( 'tags' => filter )
48

    
49
            values    = values_for('tags').clone
50
            compare   = operator_for('tags').eql?('=') ? 'IN' : 'NOT IN'
51
            ids_list  = Issue.tagged_with(values).collect{ |issue| issue.id }.push(0).join(',')
52

    
53
            clauses << " AND ( #{Issue.table_name}.id #{compare} (#{ids_list}) ) "
54
          end
55

    
56
          clauses
57
        end
58

    
59

    
60
        def available_filters_extended
61
          unless @available_filters 
62
            available_filters_original.merge!({ 'tags' => {
63
              :type   => :list,
64
              :order  => 6,
65
              :values => Issue.available_tags(:project => project).collect{ |t| [t.name, t.name] }
66
            }})
67
          end
68
          @available_filters
69
        end
70
      end
71
    end
72
  end
73
end
74