Feature #43948 ยป hours_filter_time_span_format.patch
| app/assets/javascripts/application-legacy.js | ||
|---|---|---|
|
break;
|
||
|
case "integer":
|
||
|
case "float":
|
||
|
case "hour":
|
||
|
case "tree":
|
||
|
tr.find('.values').append(
|
||
|
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="14" class="value" /></span>' +
|
||
| app/models/query.rb | ||
|---|---|---|
|
:search => [ "~", "*~", "!~" ],
|
||
|
:integer => [ "=", ">=", "<=", "><", "!*", "*" ],
|
||
|
:float => [ "=", ">=", "<=", "><", "!*", "*" ],
|
||
|
:hour => [ "=", ">=", "<=", "><", "!*", "*" ],
|
||
|
:relation => ["=", "!", "=p", "=!p", "!p", "*o", "!o", "!*", "*"],
|
||
|
:tree => ["=", "~", "!*", "*"]
|
||
|
}
|
||
| ... | ... | |
|
if values_for(field).detect {|v| v.present? && !/\A[+-]?\d+(\.\d*)?\z/.match?(v)}
|
||
|
add_filter_error(field, :invalid)
|
||
|
end
|
||
|
when :hour
|
||
|
if values_for(field).detect {|v| v.present? && v.to_s.to_hours.nil? }
|
||
|
add_filter_error(field, :invalid)
|
||
|
end
|
||
|
when :date, :date_past
|
||
|
case operator_for(field)
|
||
|
when "=", ">=", "<=", "><"
|
||
| ... | ... | |
|
else
|
||
|
sql = "1=0"
|
||
|
end
|
||
|
when :float
|
||
|
when :float, :hour
|
||
|
if is_custom_filter
|
||
|
sql =
|
||
|
"(#{db_table}.#{db_field} <> '' AND " \
|
||
| app/models/time_entry_query.rb | ||
|---|---|---|
|
) if project.nil? || !project.leaf?
|
||
|
add_available_filter "comments", :type => :text
|
||
|
add_available_filter "hours", :type => :float
|
||
|
add_available_filter "hours", :type => :hour
|
||
|
add_custom_fields_filters(time_entry_custom_fields)
|
||
|
add_associations_custom_fields_filters :project
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def sql_for_hours_field(field, operator, value)
|
||
|
sql_for_field("hours", operator, value.map(&:to_hours), TimeEntry.table_name, "hours")
|
||
|
end
|
||
|
def sql_for_activity_id_field(field, operator, value)
|
||
|
ids = value.map(&:to_i).join(',')
|
||
|
table_name = Enumeration.table_name
|
||
| test/unit/time_entry_query_test.rb | ||
|---|---|---|
|
assert_equal 7.0, query.results_scope.sum(:hours)
|
||
|
end
|
||
|
def test_hours_filter_with_float_string
|
||
|
project = Project.find(1)
|
||
|
TimeEntry.delete_all
|
||
|
t1 = TimeEntry.generate!(:project => project, :hours => 0.25, :user_id => 2)
|
||
|
t2 = TimeEntry.generate!(:project => project, :hours => 0.50, :user_id => 2)
|
||
|
t3 = TimeEntry.generate!(:project => project, :hours => 0.75, :user_id => 2)
|
||
|
t4 = TimeEntry.generate!(:project => project, :hours => 1.00, :user_id => 2)
|
||
|
query = TimeEntryQuery.new(:project => project, :name => '_')
|
||
|
query.add_filter('hours', '>=', ['0.75'])
|
||
|
assert_equal [t3.id, t4.id].sort, query.results_scope.pluck(:id).sort
|
||
|
end
|
||
|
def test_hours_filter_with_hhmm_string
|
||
|
project = Project.find(1)
|
||
|
TimeEntry.delete_all
|
||
|
t1 = TimeEntry.generate!(:project => project, :hours => 0.25, :user_id => 2)
|
||
|
t2 = TimeEntry.generate!(:project => project, :hours => 0.50, :user_id => 2)
|
||
|
t3 = TimeEntry.generate!(:project => project, :hours => 0.75, :user_id => 2)
|
||
|
t4 = TimeEntry.generate!(:project => project, :hours => 1.00, :user_id => 2)
|
||
|
query = TimeEntryQuery.new(:project => project, :name => '_')
|
||
|
query.add_filter('hours', '>=', ['0:45'])
|
||
|
assert_equal [t3.id, t4.id].sort, query.results_scope.pluck(:id).sort
|
||
|
end
|
||
|
def test_results_scope_should_be_in_the_same_order_when_paginating
|
||
|
4.times {TimeEntry.generate!}
|
||
|
q = TimeEntryQuery.new
|
||