mirror of
https://github.com/meineerde/redmine.git
synced 2026-02-25 04:51:45 +00:00
Filter issues by file description (#34715).
Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@21034 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
9e3d772e15
commit
a0bf4e5cd3
@ -41,6 +41,8 @@ module QueriesHelper
|
|||||||
group = :label_date
|
group = :label_date
|
||||||
elsif %w(estimated_hours spent_time).include?(field)
|
elsif %w(estimated_hours spent_time).include?(field)
|
||||||
group = :label_time_tracking
|
group = :label_time_tracking
|
||||||
|
elsif %w(attachment attachment_description).include?(field)
|
||||||
|
group = :label_attachment
|
||||||
end
|
end
|
||||||
if group
|
if group
|
||||||
(grouped[group] ||= []) << [field_options[:name], field]
|
(grouped[group] ||= []) << [field_options[:name], field]
|
||||||
|
|||||||
@ -202,6 +202,10 @@ class IssueQuery < Query
|
|||||||
"attachment",
|
"attachment",
|
||||||
:type => :text, :name => l(:label_attachment)
|
:type => :text, :name => l(:label_attachment)
|
||||||
)
|
)
|
||||||
|
add_available_filter(
|
||||||
|
"attachment_description",
|
||||||
|
:type => :text, :name => l(:label_attachment_description)
|
||||||
|
)
|
||||||
if User.current.logged?
|
if User.current.logged?
|
||||||
add_available_filter(
|
add_available_filter(
|
||||||
"watcher_id",
|
"watcher_id",
|
||||||
@ -597,6 +601,23 @@ class IssueQuery < Query
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sql_for_attachment_description_field(field, operator, value)
|
||||||
|
cond_description = "a.description IS NOT NULL AND a.description <> ''"
|
||||||
|
c =
|
||||||
|
case operator
|
||||||
|
when '*', '!*'
|
||||||
|
(operator == '*' ? cond_description : "NOT (#{cond_description})")
|
||||||
|
when '~', '!~'
|
||||||
|
(operator == '~' ? '' : "#{cond_description} AND ") +
|
||||||
|
sql_contains('a.description', value.first, :match => (operator == '~'))
|
||||||
|
when '^', '$'
|
||||||
|
sql_contains('a.description', value.first, (operator == '^' ? :starts_with : :ends_with) => true)
|
||||||
|
else
|
||||||
|
'1=0'
|
||||||
|
end
|
||||||
|
"EXISTS (SELECT 1 FROM #{Attachment.table_name} a WHERE a.container_type = 'Issue' AND a.container_id = #{Issue.table_name}.id AND #{c})"
|
||||||
|
end
|
||||||
|
|
||||||
def sql_for_parent_id_field(field, operator, value)
|
def sql_for_parent_id_field(field, operator, value)
|
||||||
case operator
|
case operator
|
||||||
when "="
|
when "="
|
||||||
|
|||||||
@ -701,6 +701,7 @@ en:
|
|||||||
label_attachment_delete: Delete file
|
label_attachment_delete: Delete file
|
||||||
label_attachment_plural: Files
|
label_attachment_plural: Files
|
||||||
label_file_added: File added
|
label_file_added: File added
|
||||||
|
label_attachment_description: File description
|
||||||
label_report: Report
|
label_report: Report
|
||||||
label_report_plural: Reports
|
label_report_plural: Reports
|
||||||
label_news: News
|
label_news: News
|
||||||
|
|||||||
@ -1527,6 +1527,48 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
assert_equal [3, 4], issues.collect(&:id).sort
|
assert_equal [3, 4], issues.collect(&:id).sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_filter_on_attachment_description_when_any
|
||||||
|
query = IssueQuery.new(:name => '_')
|
||||||
|
query.filters = {"attachment_description" => {:operator => '*', :values => ['']}}
|
||||||
|
issues = find_issues_with_query(query)
|
||||||
|
assert_equal [2, 3, 14], issues.collect(&:id).sort
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_filter_on_attachment_description_when_none
|
||||||
|
query = IssueQuery.new(:name => '_')
|
||||||
|
query.filters = {"attachment_description" => {:operator => '!*', :values => ['']}}
|
||||||
|
issues = find_issues_with_query(query)
|
||||||
|
assert_equal [2, 3, 4, 14], issues.collect(&:id).sort
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_filter_on_attachment_description_when_contains
|
||||||
|
query = IssueQuery.new(:name => '_')
|
||||||
|
query.filters = {"attachment_description" => {:operator => '~', :values => ['attachment']}}
|
||||||
|
issues = find_issues_with_query(query)
|
||||||
|
assert_equal [3, 14], issues.collect(&:id).sort
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_filter_on_attachment_description_when_does_not_contain
|
||||||
|
query = IssueQuery.new(:name => '_')
|
||||||
|
query.filters = {"attachment_description" => {:operator => '!~', :values => ['attachment']}}
|
||||||
|
issues = find_issues_with_query(query)
|
||||||
|
assert_equal [2], issues.collect(&:id).sort
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_filter_on_attachment_description_when_starts_with
|
||||||
|
query = IssueQuery.new(:name => '_')
|
||||||
|
query.filters = {"attachment_description" => {:operator => '^', :values => ['attachment']}}
|
||||||
|
issues = find_issues_with_query(query)
|
||||||
|
assert_equal [14], issues.collect(&:id).sort
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_filter_on_attachment_description_when_ends_with
|
||||||
|
query = IssueQuery.new(:name => '_')
|
||||||
|
query.filters = {"attachment_description" => {:operator => '$', :values => ['attachment']}}
|
||||||
|
issues = find_issues_with_query(query)
|
||||||
|
assert_equal [3], issues.collect(&:id).sort
|
||||||
|
end
|
||||||
|
|
||||||
def test_filter_on_subject_when_starts_with
|
def test_filter_on_subject_when_starts_with
|
||||||
query = IssueQuery.new(:name => '_')
|
query = IssueQuery.new(:name => '_')
|
||||||
query.filters = {'subject' => {:operator => '^', :values => ['issue']}}
|
query.filters = {'subject' => {:operator => '^', :values => ['issue']}}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user