Project

General

Profile

Feature #14462 » prev_next_button_remember_issues_list_trunk_r15160.patch

Takenori TAKAKI, 2016-03-02 03:39

View differences:

app/controllers/issues_controller.rb
94 94
  end
95 95

  
96 96
  def show
97
    @prev = params[:prev]
98
    @next = params[:next]
99
    @pos  = params[:pos]
100
    @count = params[:count]
101

  
97 102
    @journals = @issue.journals.includes(:user, :details).
98 103
                    references(:user, :details).
99 104
                    reorder(:created_on, :id).to_a
......
174 179

  
175 180
  def update
176 181
    return unless update_issue_from_params
182
    retrieve_previous_and_next_issue_ids
177 183
    @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
178 184
    saved = false
179 185
    begin
......
191 197
      flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
192 198

  
193 199
      respond_to do |format|
194
        format.html { redirect_back_or_default issue_path(@issue) }
200
        format.html { redirect_back_or_default issue_path(@issue, {'next' => @next_issue_id, 'prev' => @prev_issue_id, 'pos' => @issue_position, 'count' => @issue_count}.reject{|k,v|k.blank?}) }
195 201
        format.api  { render_api_ok }
196 202
      end
197 203
    else
......
367 373
        end
368 374
        @prev_issue_id = issue_ids[idx - 1] if idx > 0
369 375
        @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
376
      else
377
        return if issue_ids.empty?
378
        @prev_issue_id  = @prev
379
        @next_issue_id  = @next
380
        @issue_position = @pos
381
        @issue_count    = @count
370 382
      end
371 383
    end
372 384
  end
test/functional/issues_controller_test.rb
1354 1354
    assert_select 'a', :text => /Next/, :count => 0
1355 1355
  end
1356 1356

  
1357
  def test_show_should_display_prev_next_links_when_issue_does_not_match_query_condition_but_request_param_has_link_attributes
1358
    @request.session[:query] = {:filters => {'status_id' => {:values => ['5'], :operator => 'c'}}, :project_id => 1}
1359
    issue_5 = Issue.find(5)
1360
    issue_5.status_id = 5 # be matched the query conditions
1361
    issue_5.save!
1362
    issue_1 = Issue.find(1)
1363
    issue_1.status_id = 1 # not be matched the query conditions
1364
    issue_1.save!
1365

  
1366
    get :show, :id => 1, :prev => 1, :next => 3, :pos => 2, :count => 4
1367
    assert_response :success
1368

  
1369
    assert_equal '1', assigns(:prev)
1370
    assert_equal '3', assigns(:next)
1371
    assert_equal '2', assigns(:pos)
1372
    assert_equal '4', assigns(:count)
1373

  
1374
    assert_equal '1', assigns(:prev_issue_id)
1375
    assert_equal '3', assigns(:next_issue_id)
1376
    assert_equal '2', assigns(:issue_position)
1377
    assert_equal '4', assigns(:issue_count)
1378

  
1379
    assert_select 'div.next-prev-links' do
1380
      assert_select 'a[href="/issues/1"]', :text => /Previous/
1381
      assert_select 'a[href="/issues/3"]', :text => /Next/
1382
      assert_select 'span.position', :text => "2 of 4"
1383
    end
1384
  end
1385

  
1386
  def test_show_should_not_display_prev_next_links_when_request_param_has_link_attributes_but_query_results_empty
1387
    @request.session[:query] = {:filters => {'status_id' => {:values => ['5'], :operator => 'c'}}, :project_id => 1}
1388
    Issue.update_all("status_id=1") # all issues is not matched the qeury condition
1389

  
1390
    get :show, :id => 1, :prev => 1, :next => 3, :pos => 2, :count => 4
1391
    assert_response :success
1392

  
1393
    assert_nil assigns(:prev_issue_id)
1394
    assert_nil assigns(:next_issue_id)
1395
    assert_nil assigns(:issue_position)
1396
    assert_nil assigns(:issue_count)
1397

  
1398
    assert_select 'a', :text => /Previous/, :count => 0
1399
    assert_select 'a', :text => /Next/, :count => 0
1400
  end
1401

  
1357 1402
  def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
1358 1403
    cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
1359 1404
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
......
3537 3582
    assert ActionMailer::Base.deliveries.empty?
3538 3583
  end
3539 3584

  
3585
  def test_put_update_should_retrieve_previous_and_next_issue_ids_and_added_parameters_on_redirect_url
3586
    issue = Issue.find(11)
3587
    issue.status_id = 5
3588
    issue.save!
3589
    ActionMailer::Base.deliveries.clear
3590

  
3591
    @request.session[:query] = {:filters => {'status_id' => {:values => ['5'], :operator => 'c'}}, :project_id => 1}
3592
    @request.session['issues_index_sort'] = 'id'
3593
    @request.session[:user_id] = 2
3594

  
3595
    put :update, :id => 11, :issue => {:status_id => 6, :notes => 'change status.'}
3596

  
3597
    assert_equal 6, assigns(:issue).status_id
3598
    issue.reload
3599
    assert_equal 6, issue.status_id
3600

  
3601
    assert_equal 3, assigns[:issue_count]
3602
    assert_equal 8, assigns[:prev_issue_id]
3603
    assert_equal 12, assigns[:next_issue_id]
3604
    assert_equal 2, assigns[:issue_position]
3605
    assert_redirected_to '/issues/11?count=3&next=12&pos=2&prev=8'
3606
  end
3607

  
3540 3608
  def test_put_update_should_send_a_notification
3541 3609
    @request.session[:user_id] = 2
3542 3610
    ActionMailer::Base.deliveries.clear
(3-3/3)