Project

General

Profile

Feature #22483 » 0001-Show-PDF-preview-for-repository-files-and-attachment.patch

Go MAEDA, 2026-02-18 06:57

View differences:

app/assets/stylesheets/application.css
box-shadow: 0 1px 2px rgba(var(--oc-gray-9-rgb), 0.05);
}
.pdf-full-view-link { margin: 0 0 0.5em; }
/* tablesort */
th[role=columnheader]:not(.no-sort) {
cursor: pointer;
app/assets/stylesheets/scm.css
img.filecontent, video.filecontent { max-inline-size: 100%; }
.filecontent.pdf {
inline-size: 100%;
max-block-size: 80vh;
overflow: hidden;
position: relative;
}
.filecontent.pdf::before {
content: " ";
display: block;
inline-size: 100%;
padding-block-end: 100%;
}
.filecontent.pdf object,
.filecontent.pdf iframe,
.filecontent.pdf p {
position: absolute;
inset-block-start: 0;
inset-inline-start: 0;
inset-inline-end: 0;
}
.filecontent.pdf iframe,
.filecontent.pdf object {
border: none;
inline-size: 100%;
block-size: 100%;
}
.previous-filename {
font-weight: normal;
}
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/pdf.html.erb
<%= render :layout => 'layouts/file' do %>
<%= render :partial => 'common/pdf',
:locals => {:path => download_named_attachment_path(@attachment, @attachment.filename)} %>
<% end %>
app/views/common/_pdf.html.erb
<p class="pdf-full-view-link">
<%= link_to l(:label_open_in_full_view, :default => l(:button_download)), path %>
</p>
<div class="filecontent pdf">
<object data="<%= path %>" type="application/pdf">
<%= render :partial => 'common/other' %>
</object>
</div>
app/views/repositories/entry.html.erb
<% if Redmine::MimeType.is_type?('image', @path) %>
<%= render :partial => 'common/image', :locals => {:path => @raw_url, :alt => @path} %>
<% elsif Redmine::MimeType.of(@path) == 'application/pdf' %>
<%= render :partial => 'common/pdf', :locals => {:path => @raw_url} %>
<% elsif Redmine::MimeType.of(@path) == 'text/x-textile' %>
<%= render :partial => 'common/markup', :locals => {:markup_text_formatting => 'textile', :markup_text => @content} %>
<% elsif Redmine::MimeType.of(@path) == 'text/markdown' %>
config/locales/en.yml
label_no_preview: No preview available
label_no_preview_alternative_html: No preview available. %{link} the file instead.
label_no_preview_download: Download
label_open_in_full_view: Open in full view
label_change_status: Change status
label_history: History
label_attachment: File
test/functional/attachments_controller_test.rb
assert_select 'img.filecontent', :src => attachments(:attachments_010).filename
end
def test_show_pdf
@request.session[:user_id] = 2
get(:show, :params => {:id => 23})
assert_response :success
assert_equal 'text/html', @response.media_type
path = download_named_attachment_path(attachments(:attachments_023), attachments(:attachments_023).filename)
assert_select ".filecontent.pdf object[data='#{path}']"
assert_select '.nodata', :text => 'No preview available'
end
def test_show_other_with_no_preview
@request.session[:user_id] = 2
get(:show, :params => {:id => 6})
(8-8/8)