Feature #26826 » issue-filter-by-spent-time-4.diff
app/models/issue_query.rb | ||
---|---|---|
134 | 134 |
add_available_filter "start_date", :type => :date |
135 | 135 |
add_available_filter "due_date", :type => :date |
136 | 136 |
add_available_filter "estimated_hours", :type => :float |
137 | ||
138 |
if User.current.allowed_to?(:view_time_entries, project, :global => true) |
|
139 |
add_available_filter "spent_time", :type => :float, :label => :label_spent_time |
|
140 |
end |
|
141 | ||
137 | 142 |
add_available_filter "done_ratio", :type => :integer |
138 | 143 | |
139 | 144 |
if User.current.allowed_to?(:set_issues_private, nil, :global => true) || |
... | ... | |
380 | 385 |
"#{neg} EXISTS (#{subquery})" |
381 | 386 |
end |
382 | 387 | |
388 |
def sql_for_spent_time_field(field, operator, value) |
|
389 |
first, second = value.first.to_f, value.second.to_f |
|
390 | ||
391 |
sql_op = |
|
392 |
case operator |
|
393 |
when "=", ">=", "<=" ; "#{operator} #{first}" |
|
394 |
when "><" ; "BETWEEN #{first} AND #{second}" |
|
395 |
when "*" ; "> 0" |
|
396 |
when "!*" ; "= 0" |
|
397 |
else ; return nil |
|
398 |
end |
|
399 | ||
400 |
"COALESCE((" + |
|
401 |
"SELECT ROUND(CAST(SUM(hours) AS DECIMAL(30,3)), 2) " + |
|
402 |
"FROM #{TimeEntry.table_name} " + |
|
403 |
"WHERE issue_id = #{Issue.table_name}.id), 0) #{sql_op}" |
|
404 |
end |
|
405 | ||
383 | 406 |
def sql_for_watcher_id_field(field, operator, value) |
384 | 407 |
db_table = Watcher.table_name |
385 | 408 |
test/unit/query_test.rb | ||
---|---|---|
30 | 30 |
:projects_trackers, |
31 | 31 |
:custom_fields_trackers, |
32 | 32 |
:workflows, :journals, |
33 |
:attachments |
|
33 |
:attachments, :time_entries
|
|
34 | 34 | |
35 | 35 |
INTEGER_KLASS = RUBY_VERSION >= "2.4" ? Integer : Fixnum |
36 | 36 | |
... | ... | |
2184 | 2184 | |
2185 | 2185 |
assert_equal ['1','2','3','4','5','6'], query.available_filters['status_id'][:values].map(&:second) |
2186 | 2186 |
end |
2187 | ||
2188 |
def test_issue_query_filter_by_spent_time |
|
2189 |
query = IssueQuery.new(:name => '_') |
|
2190 | ||
2191 |
query.filters = {'spent_time' => {:operator => '*', :values => ['']}} |
|
2192 |
assert_equal query.issues.pluck(:id), [3, 1] |
|
2193 | ||
2194 |
query.filters = {'spent_time' => {:operator => '!*', :values => ['']}} |
|
2195 |
assert_equal query.issues.pluck(:id), [13, 12, 11, 8, 7, 5, 2] |
|
2196 | ||
2197 |
query.filters = {'spent_time' => {:operator => '>=', :values => ['10']}} |
|
2198 |
assert_equal query.issues.pluck(:id), [1] |
|
2199 | ||
2200 |
query.filters = {'spent_time' => {:operator => '<=', :values => ['10']}} |
|
2201 |
assert_equal query.issues.pluck(:id), [13, 12, 11, 8, 7, 5, 3, 2] |
|
2202 | ||
2203 |
query.filters = {'spent_time' => {:operator => '><', :values => ['1', '2']}} |
|
2204 |
assert_equal query.issues.pluck(:id), [3] |
|
2205 |
end |
|
2187 | 2206 |
end |