]> source.dussan.org Git - redmine.git/commitdiff
Attachments prev/next navigation (#29395).
authorGo MAEDA <maeda@farend.jp>
Thu, 4 Oct 2018 13:20:11 +0000 (13:20 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 4 Oct 2018 13:20:11 +0000 (13:20 +0000)
Patch by Jens Krämer.

git-svn-id: http://svn.redmine.org/redmine/trunk@17567 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/attachments_controller.rb
app/helpers/attachments_helper.rb
app/views/layouts/_file.html.erb
public/stylesheets/application.css
test/functional/attachments_controller_test.rb

index 1b18662ad742467155f100ba7a546ed22a29bf9c..9c0bf15baaf680dfd2e38b16857524d5107691b0 100644 (file)
@@ -32,6 +32,14 @@ class AttachmentsController < ApplicationController
   def show
     respond_to do |format|
       format.html {
+        if @attachment.container.respond_to?(:attachments)
+          @attachments = @attachment.container.attachments.to_a
+          if index = @attachments.index(@attachment)
+            @paginator = Redmine::Pagination::Paginator.new(
+              @attachments.size, 1, index+1
+            )
+          end
+        end
         if @attachment.is_diff?
           @diff = File.read(@attachment.diskfile, :mode => "rb")
           @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
index 36cf0d4feb0ebcfe9336f4a7464a914f7dccf547..385f3b8a4f4775446176c22af4a5af1972022af1 100644 (file)
@@ -56,6 +56,14 @@ module AttachmentsHelper
     end
   end
 
+  def render_pagination
+    pagination_links_each @paginator do |text, parameters, options|
+      if att = @attachments[parameters[:page] - 1]
+        link_to text, named_attachment_path(att, att.filename)
+      end
+    end if @paginator
+  end
+
   def render_api_attachment(attachment, api, options={})
     api.attachment do
       render_api_attachment_attributes(attachment, api)
index 3b225508b9b21568a08b173c3decf9e8440ed88c..8ffadf703f099d22d4439b538dff92be8c3c7a6a 100644 (file)
 </div>
 <%= yield %>
 
+<span class="pagination">
+  <%= render_pagination %>
+</span>
+
 <% html_title @attachment.filename %>
 
 <% content_for :header_tags do -%>
index 1ff1dbd8a7bccd7a3dc8c3d437f8cc033b08c38d..8a33fda3a458ffae53adb55304be1d2d4b7b6da4 100644 (file)
@@ -666,6 +666,10 @@ span.pagination {margin-left:3px; color:#888; display:block;}
   font-weight: bold;
 }
 span.pagination>span {white-space:nowrap;}
+.controller-attachments.action-show span.pagination{
+  display: block;
+  margin-top: 1.2em;
+}
 
 #search-form fieldset p {margin:0.2em 0;}
 
index 016ed28fa49297e7c4a5fdef5f53ce3fa00fc2ba..a5d4c17053059b0864573d795d7d84b17ba7034f 100644 (file)
@@ -287,6 +287,16 @@ class AttachmentsControllerTest < Redmine::ControllerTest
     assert_response 404
   end
 
+  def test_show_renders_pagination
+    get :show, :params => { :id => 5, :type => 'inline' }
+    assert_response :success
+
+    assert_select 'ul.pages li.next', :text => /next/i
+    assert_select 'ul.pages li.previous', :text => /previous/i
+
+    set_tmp_attachments_directory
+  end
+
   def test_download_text_file
     get :download, :params => {
         :id => 4