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 / project_patch.rb @ 1244:a3ed5c4d90f0

History | View | Annotate | Download (1.76 KB)

1 727:e3e958595e07 luis
# C4DM
2
3
require_dependency 'project'
4
5
module RedmineTags
6
  module Patches
7
    module ProjectPatch
8 729:291c4d7dc0b6 luis
      def self.included(base) # :nodoc:
9 727:e3e958595e07 luis
        base.extend(ClassMethods)
10 730:4a9bb3b8d5cd luis
        base.send(:include, InstanceMethods)
11 727:e3e958595e07 luis
12
        base.class_eval do
13
          unloadable
14 730:4a9bb3b8d5cd luis
15
          attr_accessor :tag_list
16 727:e3e958595e07 luis
          acts_as_taggable
17 730:4a9bb3b8d5cd luis
18 727:e3e958595e07 luis
        end
19
      end
20
21 730:4a9bb3b8d5cd luis
      module InstanceMethods
22
      end
23 729:291c4d7dc0b6 luis
24 727:e3e958595e07 luis
      module ClassMethods
25 1244:a3ed5c4d90f0 luis
        TAGGING_IDS_LIMIT_SQL = <<-SQL
26
            tag_id IN (
27
                SELECT #{ActsAsTaggableOn::Tagging.table_name}.tag_id
28
                FROM #{ActsAsTaggableOn::Tagging.table_name}
29
                WHERE #{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN (?)
30
            )
31
        SQL
32
33 739:b7ac21913927 luis
        def search_by_question(question)
34
          if question.length > 1
35
            search(RedmineProjectFiltering.calculate_tokens(question), nil, :all_words => true).first.sort_by(&:lft)
36
          else
37
            all(:order => 'lft')
38
          end
39
        end
40
41 1244:a3ed5c4d90f0 luis
        # Returns available project tags
42
        # Does not return tags from private projects
43
        # === Parameters
44
        # * <i>options</i> = (optional) Options hash of
45
        #   * name_like - String. Substring to filter found tags.
46
        def available_tags( options = {} )
47
          ids_scope = Project.visible
48 739:b7ac21913927 luis
49 1244:a3ed5c4d90f0 luis
          conditions = [""]
50 746:2ced57750157 luis
51 1244:a3ed5c4d90f0 luis
          # limit to the tags matching given %name_like%
52
          if options[:name_like]
53
            conditions[0] << "#{ActsAsTaggableOn::Tag.table_name}.name LIKE ? AND "
54
            conditions << "%#{options[:name_like].downcase}%"
55 746:2ced57750157 luis
          end
56
57 1244:a3ed5c4d90f0 luis
          conditions[0] << TAGGING_IDS_LIMIT_SQL
58
          conditions << ids_scope.map{ |issue| issue.id }.push(-1)
59 746:2ced57750157 luis
60 1244:a3ed5c4d90f0 luis
          self.all_tag_counts(:conditions => conditions)
61 727:e3e958595e07 luis
        end
62
      end
63
    end
64
  end
65
end