Project

General

Profile

Feature #22483 » 0002-Show-pdf-preview-for-repository-files-and-attachment.patch

Gregor Schmidt, 2016-05-09 11:08

View differences:

app/controllers/attachments_controller.rb
render :action => 'file'
elsif @attachment.is_image?
render :action => 'image'
elsif @attachment.is_pdf?
render :action => 'pdf'
else
render :action => 'other'
end
app/views/attachments/_links.html.erb
</div>
<% for attachment in attachments %>
<p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
<% if attachment.is_text? || attachment.is_image? %>
<% if attachment.is_text? || attachment.is_image? || attachment.is_pdf? %>
<%= link_to l(:button_view),
{ :controller => 'attachments', :action => 'show',
:id => attachment, :filename => attachment.filename },
app/views/attachments/pdf.html.erb
<%= render :layout => 'layouts/file' do %>
<%= render :partial => 'common/pdf', :locals => {:path => download_named_attachment_url(@attachment, @attachment.filename)} %>
<% end %>
app/views/common/_pdf.html.erb
<div class="filecontent pdf">
<object data="<%= path %>" type="application/pdf">
<iframe src="<%= path %>">
<%= render :partial => 'common/other' %>
</iframe>
</object>
</div>
app/views/repositories/entry.html.erb
<% if Redmine::MimeType.is_type?('image', @path) %>
<%= render :partial => 'common/image', :locals => {:path => url_for(params.merge(:action => 'raw')), :alt => @path} %>
<% elsif Redmine::MimeType.of(@path) == 'application/pdf' %>
<%= render :partial => 'common/pdf', :locals => {:path => url_for(params.merge(:action => 'raw'))} %>
<% elsif @content %>
<%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
<% else %>
public/stylesheets/scm.css
img.filecontent { max-width: 100%; margin-top: 1em;}
.filecontent.pdf {
width: 100%;
max-height: 80vh;
overflow: hidden;
position: relative;
}
.filecontent.pdf:before {
content: " ";
display: block;
width: 100%;
padding-bottom: 100%;
}
.filecontent.pdf object,
.filecontent.pdf iframe,
.filecontent.pdf p {
position: absolute;
top: 0;
left: 0;
right: 0;
}
.filecontent.pdf iframe,
.filecontent.pdf object {
border: none;
width: 100%;
height: 100%;
}
/* 12 different colors for the annonate view */
table.annotate tr.bloc-0 {background: #FFFFBF;}
table.annotate tr.bloc-1 {background: #EABFFF;}
test/fixtures/attachments.yml
filename: root_attachment.txt
filesize: 54
author_id: 2
attachments_021:
created_on: 2006-07-19 21:07:27 +02:00
container_type: Issue
container_id: 2
downloads: 0
disk_filename: 060719210727_example.pdf
disk_directory: "2006/07"
digest: ab1e1922943ce0777efaea3c780295c8
id: 21
filesize: 23415
filename: example.pdf
author_id: 2
description: This is a PDF file
content_type: application/pdf
test/functional/attachments_controller_test.rb
assert_select 'img.filecontent', :src => attachments(:attachments_010).filename
end
def test_show_pdf
get :show, :id => 21
assert_response :success
assert_template 'pdf'
assert_equal 'text/html', @response.content_type
assert_select '.filecontent.pdf object', :src => attachments(:attachments_010).filename
assert_select '.filecontent.pdf iframe', :src => attachments(:attachments_010).filename
assert_select '.nodata', :text => 'No preview available'
end
def test_show_other
get :show, :id => 6
assert_template 'other'
(3-3/8)