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 / plugins / redmine_tags / lib / redmine_tags / patches / issue_patch.rb @ 1396:5b65c47087b9

History | View | Annotate | Download (2.53 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 'issue'
20

    
21
module RedmineTags
22
  module Patches
23
    module IssuePatch
24
      def self.included(base)
25
        base.extend(ClassMethods)
26

    
27
        base.class_eval do
28
          unloadable
29
          acts_as_taggable
30

    
31
          scope :on_project, lambda { |project|
32
            project = project.id if project.is_a? Project
33
            { :conditions => ["#{Project.table_name}.id=?", project] }
34
          }
35

    
36
          Issue.safe_attributes 'tag_list'
37
        end
38
      end
39

    
40
      module ClassMethods
41
        TAGGING_IDS_LIMIT_SQL = <<-SQL
42
          tag_id IN (
43
            SELECT #{ActsAsTaggableOn::Tagging.table_name}.tag_id
44
              FROM #{ActsAsTaggableOn::Tagging.table_name}
45
             WHERE #{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN (?)
46
          )
47
        SQL
48

    
49
        # Returns available issue tags
50
        # === Parameters
51
        # * <i>options</i> = (optional) Options hash of
52
        #   * project   - Project to search in.
53
        #   * open_only - Boolean. Whenever search within open issues only.
54
        #   * name_like - String. Substring to filter found tags.
55
        def available_tags(options = {})
56
          ids_scope = Issue.visible
57
          ids_scope = ids_scope.on_project(options[:project]) if options[:project]
58
          ids_scope = ids_scope.open if options[:open_only]
59

    
60
          conditions = [""]
61

    
62
          # limit to the tags matching given %name_like%
63
          if options[:name_like]
64
            conditions[0] << "#{ActsAsTaggableOn::Tag.table_name}.name LIKE ? AND "
65
            conditions << "%#{options[:name_like].downcase}%"
66
          end
67

    
68
          conditions[0] << TAGGING_IDS_LIMIT_SQL
69
          conditions << ids_scope.map{ |issue| issue.id }.push(-1)
70

    
71
          self.all_tag_counts(:conditions => conditions)
72
        end
73
      end
74
    end
75
  end
76
end