Feature #26826 » issue-filter-by-spent-time-2.diff
app/models/issue_query.rb | ||
---|---|---|
88 | 88 |
:type => :list, :values => lambda { project_values } |
89 | 89 |
) if project.nil? |
90 | 90 | |
91 |
if User.current.allowed_to?(:view_time_entries, project, :global => true) |
|
92 |
add_available_filter "spent_time", :type => :float, :label => :label_spent_time |
|
93 |
end |
|
94 | ||
91 | 95 |
add_available_filter "tracker_id", |
92 | 96 |
:type => :list, :values => trackers.collect{|s| [s.name, s.id.to_s] } |
93 | 97 | |
... | ... | |
380 | 384 |
"#{neg} EXISTS (#{subquery})" |
381 | 385 |
end |
382 | 386 | |
387 |
def sql_for_spent_time_field(field, operator, value) |
|
388 |
first, second = value.first.to_f, value.second.to_f |
|
389 | ||
390 |
sql_op = |
|
391 |
case operator |
|
392 |
when "=", ">=", "<=" ; "#{operator} #{first}" |
|
393 |
when "><" ; "BETWEEN #{first} AND #{second}" |
|
394 |
when "*" ; "> 0" |
|
395 |
when "!*" ; "= 0" |
|
396 |
else ; return nil |
|
397 |
end |
|
398 | ||
399 |
"COALESCE((" + |
|
400 |
"SELECT ROUND(CAST(SUM(hours) AS DECIMAL(30,3)), 2) " + |
|
401 |
"FROM #{TimeEntry.table_name} " + |
|
402 |
"WHERE issue_id = #{Issue.table_name}.id), 0) #{sql_op}" |
|
403 |
end |
|
404 | ||
383 | 405 |
def sql_for_watcher_id_field(field, operator, value) |
384 | 406 |
db_table = Watcher.table_name |
385 | 407 |
"#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND " + |
test/unit/query_test.rb | ||
---|---|---|
2119 | 2119 | |
2120 | 2120 |
assert_equal ['1','2','3','4','5','6'], query.available_filters['status_id'][:values].map(&:second) |
2121 | 2121 |
end |
2122 | ||
2123 |
def test_issue_query_filter_by_spent_time |
|
2124 |
query = IssueQuery.new(:name => '_') |
|
2125 | ||
2126 |
query.filters = {'spent_time' => {:operator => '*', :values => ['']}} |
|
2127 |
assert_equal query.issues.pluck(:id), [3, 1] |
|
2128 | ||
2129 |
query.filters = {'spent_time' => {:operator => '!*', :values => ['']}} |
|
2130 |
assert_equal query.issues.pluck(:id), [13, 12, 11, 8, 7, 5, 2] |
|
2131 | ||
2132 |
query.filters = {'spent_time' => {:operator => '>=', :values => ['10']}} |
|
2133 |
assert_equal query.issues.pluck(:id), [1] |
|
2134 | ||
2135 |
query.filters = {'spent_time' => {:operator => '<=', :values => ['10']}} |
|
2136 |
assert_equal query.issues.pluck(:id), [13, 12, 11, 8, 7, 5, 3, 2] |
|
2137 | ||
2138 |
query.filters = {'spent_time' => {:operator => '><', :values => ['1', '2']}} |
|
2139 |
assert_equal query.issues.pluck(:id), [3] |
|
2140 |
end |
|
2122 | 2141 |
end |