Feature #22483 » 0002-Show-pdf-preview-for-repository-files-and-attachment.patch
app/controllers/attachments_controller.rb | ||
---|---|---|
42 | 42 |
render :action => 'file' |
43 | 43 |
elsif @attachment.is_image? |
44 | 44 |
render :action => 'image' |
45 |
elsif @attachment.is_pdf? |
|
46 |
render :action => 'pdf' |
|
45 | 47 |
else |
46 | 48 |
render :action => 'other' |
47 | 49 |
end |
app/views/attachments/_links.html.erb | ||
---|---|---|
8 | 8 |
</div> |
9 | 9 |
<% for attachment in attachments %> |
10 | 10 |
<p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> |
11 |
<% if attachment.is_text? || attachment.is_image? %> |
|
11 |
<% if attachment.is_text? || attachment.is_image? || attachment.is_pdf? %>
|
|
12 | 12 |
<%= link_to l(:button_view), |
13 | 13 |
{ :controller => 'attachments', :action => 'show', |
14 | 14 |
:id => attachment, :filename => attachment.filename }, |
app/views/attachments/pdf.html.erb | ||
---|---|---|
1 |
<%= render :layout => 'layouts/file' do %> |
|
2 |
<%= render :partial => 'common/pdf', :locals => {:path => download_named_attachment_url(@attachment, @attachment.filename)} %> |
|
3 |
<% end %> |
app/views/common/_pdf.html.erb | ||
---|---|---|
1 |
<div class="filecontent pdf"> |
|
2 |
<object data="<%= path %>" type="application/pdf"> |
|
3 |
<iframe src="<%= path %>"> |
|
4 |
<%= render :partial => 'common/other' %> |
|
5 |
</iframe> |
|
6 |
</object> |
|
7 |
</div> |
app/views/repositories/entry.html.erb | ||
---|---|---|
10 | 10 | |
11 | 11 |
<% if Redmine::MimeType.is_type?('image', @path) %> |
12 | 12 |
<%= render :partial => 'common/image', :locals => {:path => url_for(params.merge(:action => 'raw')), :alt => @path} %> |
13 |
<% elsif Redmine::MimeType.of(@path) == 'application/pdf' %> |
|
14 |
<%= render :partial => 'common/pdf', :locals => {:path => url_for(params.merge(:action => 'raw'))} %> |
|
13 | 15 |
<% elsif @content %> |
14 | 16 |
<%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %> |
15 | 17 |
<% else %> |
public/stylesheets/scm.css | ||
---|---|---|
69 | 69 | |
70 | 70 |
img.filecontent { max-width: 100%; margin-top: 1em;} |
71 | 71 | |
72 |
.filecontent.pdf { |
|
73 |
width: 100%; |
|
74 |
max-height: 80vh; |
|
75 |
overflow: hidden; |
|
76 |
position: relative; |
|
77 |
} |
|
78 |
.filecontent.pdf:before { |
|
79 |
content: " "; |
|
80 |
display: block; |
|
81 |
width: 100%; |
|
82 |
padding-bottom: 100%; |
|
83 |
} |
|
84 | ||
85 |
.filecontent.pdf object, |
|
86 |
.filecontent.pdf iframe, |
|
87 |
.filecontent.pdf p { |
|
88 |
position: absolute; |
|
89 |
top: 0; |
|
90 |
left: 0; |
|
91 |
right: 0; |
|
92 |
} |
|
93 |
.filecontent.pdf iframe, |
|
94 |
.filecontent.pdf object { |
|
95 |
border: none; |
|
96 |
width: 100%; |
|
97 |
height: 100%; |
|
98 |
} |
|
99 | ||
100 | ||
72 | 101 |
/* 12 different colors for the annonate view */ |
73 | 102 |
table.annotate tr.bloc-0 {background: #FFFFBF;} |
74 | 103 |
table.annotate tr.bloc-1 {background: #EABFFF;} |
test/fixtures/attachments.yml | ||
---|---|---|
267 | 267 |
filename: root_attachment.txt |
268 | 268 |
filesize: 54 |
269 | 269 |
author_id: 2 |
270 |
attachments_021: |
|
271 |
created_on: 2006-07-19 21:07:27 +02:00 |
|
272 |
container_type: Issue |
|
273 |
container_id: 2 |
|
274 |
downloads: 0 |
|
275 |
disk_filename: 060719210727_example.pdf |
|
276 |
disk_directory: "2006/07" |
|
277 |
digest: ab1e1922943ce0777efaea3c780295c8 |
|
278 |
id: 21 |
|
279 |
filesize: 23415 |
|
280 |
filename: example.pdf |
|
281 |
author_id: 2 |
|
282 |
description: This is a PDF file |
|
283 |
content_type: application/pdf |
test/functional/attachments_controller_test.rb | ||
---|---|---|
199 | 199 |
assert_select 'img.filecontent', :src => attachments(:attachments_010).filename |
200 | 200 |
end |
201 | 201 | |
202 |
def test_show_pdf |
|
203 |
get :show, :id => 21 |
|
204 |
assert_response :success |
|
205 |
assert_template 'pdf' |
|
206 |
assert_equal 'text/html', @response.content_type |
|
207 | ||
208 |
assert_select '.filecontent.pdf object', :src => attachments(:attachments_010).filename |
|
209 |
assert_select '.filecontent.pdf iframe', :src => attachments(:attachments_010).filename |
|
210 | ||
211 |
assert_select '.nodata', :text => 'No preview available' |
|
212 |
end |
|
213 | ||
202 | 214 |
def test_show_other |
203 | 215 |
get :show, :id => 6 |
204 | 216 |
assert_template 'other' |