Defect #44667 ยป 0001-Keep-the-sort-order-of-a-saved-query-in-the-session-.patch
| app/controllers/issues_controller.rb | ||
|---|---|---|
|
@next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
|
||
|
end
|
||
|
query_params = @query.as_params
|
||
|
query_params[:sort] = @query.sort_criteria.to_param unless @query.new_record?
|
||
|
if @issue_position
|
||
|
query_params = query_params.merge(:page => (@issue_position / per_page_option) + 1, :per_page => per_page_option)
|
||
|
end
|
||
| app/helpers/queries_helper.rb | ||
|---|---|---|
|
:filters => session[session_key][:filters],
|
||
|
:group_by => session[session_key][:group_by],
|
||
|
:column_names => session[session_key][:column_names],
|
||
|
:totalable_names => session[session_key][:totalable_names],
|
||
|
:sort_criteria => session[session_key][:sort]
|
||
|
:totalable_names => session[session_key][:totalable_names]
|
||
|
)
|
||
|
@query.sort_criteria = session[session_key][:sort] if session[session_key][:sort].present?
|
||
|
@query.project = @project
|
||
|
end
|
||
|
if params[:sort].present?
|
||
| ... | ... | |
|
:filters => session_data[:filters],
|
||
|
:group_by => session_data[:group_by],
|
||
|
:column_names => session_data[:column_names],
|
||
|
:totalable_names => session_data[:totalable_names],
|
||
|
:sort_criteria => session[session_key][:sort]
|
||
|
:totalable_names => session_data[:totalable_names]
|
||
|
)
|
||
|
end
|
||
|
@query.sort_criteria = session_data[:sort] if session_data[:sort].present?
|
||
|
if session_data.has_key?(:project_id)
|
||
|
@query.project_id = session_data[:project_id]
|
||
|
else
|
||
| test/functional/issues_controller_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_show_should_display_prev_next_links_with_saved_query_and_sort_in_session
|
||
|
query =
|
||
|
IssueQuery.create!(
|
||
|
:name => 'test',
|
||
|
:visibility => IssueQuery::VISIBILITY_PUBLIC,
|
||
|
:user_id => 1,
|
||
|
:filters => {'status_id' => {:values => ['5'], :operator => '='}},
|
||
|
:sort_criteria => [['id', 'asc']]
|
||
|
)
|
||
|
# Sort the issues of the saved query by clicking on a column header
|
||
|
get(:index, :params => {:query_id => query.id, :sort => 'id:desc'})
|
||
|
assert_response :success
|
||
|
assert_equal [['id', 'desc']], session[:issue_query][:sort]
|
||
|
get(:show, :params => {:id => 11})
|
||
|
assert_response :success
|
||
|
assert_select 'div.next-prev-links' do
|
||
|
assert_select 'a[href="/issues/12"]', :text => /Previous/
|
||
|
assert_select 'a[href="/issues/8"]', :text => /Next/
|
||
|
end
|
||
|
get(:show, :params => {:id => 12})
|
||
|
assert_response :success
|
||
|
assert_select 'div.next-prev-links li.position', :text => '1 of 3' do
|
||
|
assert_select 'a[href=?]', "/issues?page=1&per_page=25&query_id=#{query.id}&sort=id%3Adesc"
|
||
|
end
|
||
|
end
|
||
|
def test_index_should_keep_sort_of_saved_query_in_session
|
||
|
query =
|
||
|
IssueQuery.create!(
|
||
|
:name => 'test',
|
||
|
:visibility => IssueQuery::VISIBILITY_PUBLIC,
|
||
|
:user_id => 1,
|
||
|
:sort_criteria => [['id', 'asc']]
|
||
|
)
|
||
|
get(:index, :params => {:query_id => query.id, :sort => 'id:desc'})
|
||
|
assert_response :success
|
||
|
# Back to the issue list, e.g. from an issue
|
||
|
get :index
|
||
|
assert_response :success
|
||
|
ids = issues_in_list.map(&:id)
|
||
|
assert ids.size > 1
|
||
|
assert_equal ids.sort.reverse, ids
|
||
|
end
|
||
|
def test_show_should_display_prev_next_links_with_query_and_sort_on_association
|
||
|
@request.session[:issue_query] =
|
||
|
{
|
||