To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / plugins / redmine_tags / lib / redmine_tags / patches / project_patch.rb @ 1248:1b44eeb49c5a
History | View | Annotate | Download (1.76 KB)
| 1 |
# C4DM
|
|---|---|
| 2 |
|
| 3 |
require_dependency 'project'
|
| 4 |
|
| 5 |
module RedmineTags |
| 6 |
module Patches |
| 7 |
module ProjectPatch |
| 8 |
def self.included(base) # :nodoc: |
| 9 |
base.extend(ClassMethods)
|
| 10 |
base.send(:include, InstanceMethods) |
| 11 |
|
| 12 |
base.class_eval do
|
| 13 |
unloadable |
| 14 |
|
| 15 |
attr_accessor :tag_list
|
| 16 |
acts_as_taggable |
| 17 |
|
| 18 |
end
|
| 19 |
end
|
| 20 |
|
| 21 |
module InstanceMethods |
| 22 |
end
|
| 23 |
|
| 24 |
module ClassMethods |
| 25 |
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 |
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 |
# 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 |
|
| 49 |
conditions = [""]
|
| 50 |
|
| 51 |
# 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 |
end
|
| 56 |
|
| 57 |
conditions[0] << TAGGING_IDS_LIMIT_SQL |
| 58 |
conditions << ids_scope.map{ |issue| issue.id }.push(-1)
|
| 59 |
|
| 60 |
self.all_tag_counts(:conditions => conditions) |
| 61 |
end
|
| 62 |
end
|
| 63 |
end
|
| 64 |
end
|
| 65 |
end
|