Feature #20081 » 0002-Filter-time-entries-after-project-status.patch
| app/models/time_entry_query.rb | ||
|---|---|---|
| 80 | 80 |
:type => :list, :values => activities.map {|a| [a.name, a.id.to_s]}
|
| 81 | 81 |
) |
| 82 | 82 | |
| 83 |
add_available_filter("project.status",
|
|
| 84 |
:type => :list, |
|
| 85 |
:name => l(:label_attribute_of_project, :name => l(:field_status)), |
|
| 86 |
:values => lambda { project_statuses_values }
|
|
| 87 |
) if project.nil? || !project.leaf? |
|
| 88 | ||
| 83 | 89 |
add_available_filter "comments", :type => :text |
| 84 | 90 |
add_available_filter "hours", :type => :float |
| 85 | 91 | |
| ... | ... | |
| 205 | 211 |
sql_for_field("category_id", operator, value, Issue.table_name, "category_id")
|
| 206 | 212 |
end |
| 207 | 213 | |
| 214 |
def sql_for_project_status_field(field, operator, value, options={})
|
|
| 215 |
sql_for_field(field, operator, value, Project.table_name, "status") |
|
| 216 |
end |
|
| 217 | ||
| 208 | 218 |
# Accepts :from/:to params as shortcut filters |
| 209 | 219 |
def build_from_params(params, defaults={})
|
| 210 | 220 |
super |
| test/functional/timelog_controller_test.rb | ||
|---|---|---|
| 986 | 986 |
assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
|
| 987 | 987 |
end |
| 988 | 988 | |
| 989 |
def test_index_with_project_status_filter |
|
| 990 |
project = Project.find(3) |
|
| 991 |
project.close |
|
| 992 |
project.save |
|
| 993 | ||
| 994 |
get :index, :params => {
|
|
| 995 |
:set_filter => 1, |
|
| 996 |
:f => ['project.status'], |
|
| 997 |
:op => {'project.status' => '='},
|
|
| 998 |
:v => {'project.status' => ['1']}
|
|
| 999 |
} |
|
| 1000 | ||
| 1001 |
assert_response :success |
|
| 1002 | ||
| 1003 |
time_entries = css_select('input[name="ids[]"]').map {|e| e.attr('value')}
|
|
| 1004 |
assert_include '1', time_entries |
|
| 1005 |
assert_not_include '4', time_entries |
|
| 1006 |
end |
|
| 1007 | ||
| 989 | 1008 |
def test_index_with_issue_status_column |
| 990 | 1009 |
issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4) |
| 991 | 1010 |
entry = TimeEntry.generate!(:issue => issue) |
| test/unit/time_entry_query_test.rb | ||
|---|---|---|
| 108 | 108 |
query = TimeEntryQuery.new(:project => nil, :name => '_') |
| 109 | 109 |
assert !query.available_filters.has_key?('issue.category_id')
|
| 110 | 110 |
end |
| 111 | ||
| 112 |
def test_project_status_filter_should_be_available_in_global_queries |
|
| 113 |
query = TimeEntryQuery.new(:project => nil, :name => '_') |
|
| 114 |
assert query.available_filters.has_key?('project.status')
|
|
| 115 |
end |
|
| 116 | ||
| 117 |
def test_project_status_filter_should_be_available_when_project_has_subprojects |
|
| 118 |
query = TimeEntryQuery.new(:project => Project.find(1), :name => '_') |
|
| 119 |
assert query.available_filters.has_key?('project.status')
|
|
| 120 |
end |
|
| 121 | ||
| 122 |
def test_project_status_filter_should_not_be_available_when_project_is_leaf |
|
| 123 |
query = TimeEntryQuery.new(:project => Project.find(2), :name => '_') |
|
| 124 |
assert !query.available_filters.has_key?('project.status')
|
|
| 125 |
end |
|
| 111 | 126 |
end |