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 / query_patch.rb @ 1249:774beb9b79da
History | View | Annotate | Download (2.62 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 |
op = operator_for('tags')
|
| 50 |
case op
|
| 51 |
when '=', '!' |
| 52 |
issues = Issue.tagged_with(values_for('tags').clone) |
| 53 |
when '!*' |
| 54 |
issues = Issue.tagged_with(ActsAsTaggableOn::Tag.all.map(&:to_s), :exclude => true) |
| 55 |
else
|
| 56 |
issues = Issue.tagged_with(ActsAsTaggableOn::Tag.all.map(&:to_s), :any => true) |
| 57 |
end
|
| 58 |
|
| 59 |
compare = op.eql?('!') ? 'NOT IN' : 'IN' |
| 60 |
ids_list = issues.collect{ |issue| issue.id }.push(0).join(',')
|
| 61 |
|
| 62 |
clauses << " AND " unless clauses.empty? |
| 63 |
clauses << "( #{Issue.table_name}.id #{compare} (#{ids_list}) ) "
|
| 64 |
end
|
| 65 |
|
| 66 |
clauses |
| 67 |
end
|
| 68 |
|
| 69 |
|
| 70 |
def available_filters_extended |
| 71 |
unless @available_filters |
| 72 |
available_filters_original.merge!({ 'tags' => {
|
| 73 |
:name => l(:tags), |
| 74 |
:type => :list_optional, |
| 75 |
:order => 6, |
| 76 |
:values => Issue.available_tags(:project => project).collect{ |t| [t.name, t.name] } |
| 77 |
}}) |
| 78 |
end
|
| 79 |
@available_filters
|
| 80 |
end
|
| 81 |
end
|
| 82 |
end
|
| 83 |
end
|
| 84 |
end
|
| 85 |
|