Project

General

Profile

Patch #29395 » 0001-attachments-prev-next-navigation.patch

Jens Krämer, 2018-08-16 10:58

View differences:

app/controllers/attachments_controller.rb
32 32
  def show
33 33
    respond_to do |format|
34 34
      format.html {
35
        if @attachment.container.respond_to?(:attachments)
36
          @attachments = @attachment.container.attachments.to_a
37
          if index = @attachments.index(@attachment)
38
            @paginator = Redmine::Pagination::Paginator.new(
39
              @attachments.size, 1, index+1
40
            )
41
          end
42
        end
35 43
        if @attachment.is_diff?
36 44
          @diff = File.read(@attachment.diskfile, :mode => "rb")
37 45
          @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
app/helpers/attachments_helper.rb
56 56
    end
57 57
  end
58 58

  
59
  def render_pagination
60
    pagination_links_each @paginator do |text, parameters, options|
61
      if att = @attachments[parameters[:page] - 1]
62
        link_to text, named_attachment_path(att, att.filename)
63
      end
64
    end if @paginator
65
  end
66

  
59 67
  def render_api_attachment(attachment, api, options={})
60 68
    api.attachment do
61 69
      render_api_attachment_attributes(attachment, api)
app/views/layouts/_file.html.erb
12 12
</div>
13 13
<%= yield %>
14 14

  
15
<span class="pagination">
16
  <%= render_pagination %>
17
</span>
18

  
15 19
<% html_title @attachment.filename %>
16 20

  
17 21
<% content_for :header_tags do -%>
public/stylesheets/application.css
668 668
  font-weight: bold;
669 669
}
670 670
span.pagination>span {white-space:nowrap;}
671
.controller-attachments.action-show span.pagination{
672
  display: block;
673
  margin-top: 1.2em;
674
}
671 675

  
672 676
#search-form fieldset p {margin:0.2em 0;}
673 677

  
test/functional/attachments_controller_test.rb
287 287
    assert_response 404
288 288
  end
289 289

  
290
  def test_show_renders_pagination
291
    get :show, :params => { :id => 5, :type => 'inline' }
292
    assert_response :success
293

  
294
    assert_select 'ul.pages li.next', :text => /next/i
295
    assert_select 'ul.pages li.previous', :text => /previous/i
296

  
297
    set_tmp_attachments_directory
298
  end
299

  
290 300
  def test_download_text_file
291 301
    get :download, :params => {
292 302
        :id => 4
(1-1/6)