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 @ 1430:04cc33a44d4c
History | View | Annotate | Download (2 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 |
acts_as_taggable |
| 15 |
|
| 16 |
Project.safe_attributes 'tag_list' |
| 17 |
|
| 18 |
# TODO: review need for this callback (uneeded on update) ~lf.03042013
|
| 19 |
after_create :save_tags
|
| 20 |
end
|
| 21 |
end
|
| 22 |
|
| 23 |
module InstanceMethods |
| 24 |
def save_tags |
| 25 |
self.tags = Tag.transaction do |
| 26 |
@tag_list.each(&:save) |
| 27 |
end
|
| 28 |
end
|
| 29 |
end
|
| 30 |
|
| 31 |
module ClassMethods |
| 32 |
TAGGING_IDS_LIMIT_SQL = <<-SQL |
| 33 |
tag_id IN (
|
| 34 |
SELECT #{ActsAsTaggableOn::Tagging.table_name}.tag_id
|
| 35 |
FROM #{ActsAsTaggableOn::Tagging.table_name}
|
| 36 |
WHERE #{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN (?)
|
| 37 |
)
|
| 38 |
SQL
|
| 39 |
|
| 40 |
def search_by_question(question) |
| 41 |
if question.length > 1 |
| 42 |
search(RedmineProjectFiltering.calculate_tokens(question), nil, :all_words => true).first.sort_by(&:lft) |
| 43 |
else
|
| 44 |
all(:order => 'lft') |
| 45 |
end
|
| 46 |
end
|
| 47 |
|
| 48 |
# Returns available project tags
|
| 49 |
# Does not return tags from private projects
|
| 50 |
# === Parameters
|
| 51 |
# * <i>options</i> = (optional) Options hash of
|
| 52 |
# * name_like - String. Substring to filter found tags.
|
| 53 |
def available_tags( options = {} ) |
| 54 |
ids_scope = Project.visible
|
| 55 |
|
| 56 |
conditions = [""]
|
| 57 |
|
| 58 |
# limit to the tags matching given %name_like%
|
| 59 |
if options[:name_like] |
| 60 |
conditions[0] << "#{ActsAsTaggableOn::Tag.table_name}.name LIKE ? AND " |
| 61 |
conditions << "%#{options[:name_like].downcase}%"
|
| 62 |
end
|
| 63 |
|
| 64 |
conditions[0] << TAGGING_IDS_LIMIT_SQL |
| 65 |
conditions << ids_scope.map{ |issue| issue.id }.push(-1)
|
| 66 |
|
| 67 |
self.all_tag_counts(:conditions => conditions) |
| 68 |
end
|
| 69 |
end
|
| 70 |
end
|
| 71 |
end
|
| 72 |
end
|