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
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'
app/helpers/attachments_helper.rb
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)
app/views/layouts/_file.html.erb
</div>
<%= yield %>
<span class="pagination">
<%= render_pagination %>
</span>
<% html_title @attachment.filename %>
<% content_for :header_tags do -%>
public/stylesheets/application.css
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;}
test/functional/attachments_controller_test.rb
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
(1-1/6)