##// END OF EJS Templates
Previous/next links may be lost after editing the issue (#14462)....
Jean-Philippe Lang -
r14871:17ea1539ef03
parent child
Show More
@@ -191,7 +191,7 class IssuesController < ApplicationController
191 191 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
192 192
193 193 respond_to do |format|
194 format.html { redirect_back_or_default issue_path(@issue) }
194 format.html { redirect_back_or_default issue_path(@issue, previous_and_next_issue_ids_params) }
195 195 format.api { render_api_ok }
196 196 end
197 197 else
@@ -354,23 +354,39 class IssuesController < ApplicationController
354 354 private
355 355
356 356 def retrieve_previous_and_next_issue_ids
357 retrieve_query_from_session
358 if @query
359 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
360 sort_update(@query.sortable_columns, 'issues_index_sort')
361 limit = 500
362 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
363 if (idx = issue_ids.index(@issue.id)) && idx < limit
364 if issue_ids.size < 500
365 @issue_position = idx + 1
366 @issue_count = issue_ids.size
357 if params[:prev_issue_id].present? || params[:next_issue_id].present?
358 @prev_issue_id = params[:prev_issue_id].presence.try(:to_i)
359 @next_issue_id = params[:next_issue_id].presence.try(:to_i)
360 @issue_position = params[:issue_position].presence.try(:to_i)
361 @issue_count = params[:issue_count].presence.try(:to_i)
362 else
363 retrieve_query_from_session
364 if @query
365 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
366 sort_update(@query.sortable_columns, 'issues_index_sort')
367 limit = 500
368 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
369 if (idx = issue_ids.index(@issue.id)) && idx < limit
370 if issue_ids.size < 500
371 @issue_position = idx + 1
372 @issue_count = issue_ids.size
373 end
374 @prev_issue_id = issue_ids[idx - 1] if idx > 0
375 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
367 376 end
368 @prev_issue_id = issue_ids[idx - 1] if idx > 0
369 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
370 377 end
371 378 end
372 379 end
373 380
381 def previous_and_next_issue_ids_params
382 {
383 :prev_issue_id => params[:prev_issue_id],
384 :next_issue_id => params[:next_issue_id],
385 :issue_position => params[:issue_position],
386 :issue_count => params[:issue_count]
387 }.reject {|k,v| k.blank?}
388 end
389
374 390 # Used by #edit and #update to set some common instance variables
375 391 # from the params
376 392 def update_issue_from_params
@@ -49,6 +49,11
49 49 <%= submit_tag l(:button_submit) %>
50 50 <%= preview_link preview_edit_issue_path(:project_id => @project, :id => @issue), 'issue-form' %>
51 51 | <%= link_to l(:button_cancel), {}, :onclick => "$('#update').hide(); return false;" %>
52
53 <%= hidden_field_tag 'prev_issue_id', @prev_issue_id if @prev_issue_id %>
54 <%= hidden_field_tag 'next_issue_id', @next_issue_id if @next_issue_id %>
55 <%= hidden_field_tag 'issue_position', @issue_position if @issue_position %>
56 <%= hidden_field_tag 'issue_count', @issue_count if @issue_count %>
52 57 <% end %>
53 58
54 59 <div id="preview" class="wiki"></div>
@@ -1423,6 +1423,17 class IssuesControllerTest < ActionController::TestCase
1423 1423 end
1424 1424 end
1425 1425
1426 def test_show_should_display_prev_next_links_when_request_has_previous_and_next_issue_ids_params
1427 get :show, :id => 1, :prev_issue_id => 1, :next_issue_id => 3, :issue_position => 2, :issue_count => 4
1428 assert_response :success
1429
1430 assert_select 'div.next-prev-links' do
1431 assert_select 'a[href="/issues/1"]', :text => /Previous/
1432 assert_select 'a[href="/issues/3"]', :text => /Next/
1433 assert_select 'span.position', :text => "2 of 4"
1434 end
1435 end
1436
1426 1437 def test_show_should_display_category_field_if_categories_are_defined
1427 1438 Issue.update_all :category_id => nil
1428 1439
@@ -3681,6 +3692,19 class IssuesControllerTest < ActionController::TestCase
3681 3692 assert_response :redirect
3682 3693 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
3683 3694 end
3695
3696 def test_put_update_should_redirect_with_previous_and_next_issue_ids_params
3697 @request.session[:user_id] = 2
3698
3699 put :update, :id => 11,
3700 :issue => {:status_id => 6, :notes => 'Notes'},
3701 :prev_issue_id => 8,
3702 :next_issue_id => 12,
3703 :issue_position => 2,
3704 :issue_count => 3
3705
3706 assert_redirected_to '/issues/11?issue_count=3&issue_position=2&next_issue_id=12&prev_issue_id=8'
3707 end
3684 3708
3685 3709 def test_get_bulk_edit
3686 3710 @request.session[:user_id] = 2
General Comments 0
You need to be logged in to leave comments. Login now