diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 0b07a7bcf..d122c47e6 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -2443,6 +2443,8 @@ img { 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; diff --git a/app/assets/stylesheets/scm.css b/app/assets/stylesheets/scm.css index 23cc99dd3..90d8f2ce8 100644 --- a/app/assets/stylesheets/scm.css +++ b/app/assets/stylesheets/scm.css @@ -102,6 +102,34 @@ table.filecontent tr:target td.line-code { background-color:var(--oc-blue-0); } 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 p { + position: absolute; + inset-block-start: 0; + inset-inline-start: 0; + inset-inline-end: 0; +} + +.filecontent.pdf object { + border: none; + inline-size: 100%; + block-size: 100%; +} + .previous-filename { font-weight: normal; } diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 90c3c7070..18795891d 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -61,6 +61,8 @@ class AttachmentsController < ApplicationController render :action => 'file' elsif @attachment.is_image? render :action => 'image' + elsif @attachment.is_pdf? + render :action => 'pdf' else render :action => 'other' end diff --git a/app/views/repositories/entry.html.erb b/app/views/repositories/entry.html.erb index b4a221af9..66c2154b9 100644 --- a/app/views/repositories/entry.html.erb +++ b/app/views/repositories/entry.html.erb @@ -10,6 +10,8 @@ <% 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' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c0158faff..17dfdfb6d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -726,6 +726,7 @@ en: 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 diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index 7d856b11d..bc664cea5 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -239,6 +239,17 @@ class AttachmentsControllerTest < Redmine::ControllerTest 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})