1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-03-03 15:53:05 +00:00

Add inline image preview/display for attachments and repository entries (#22058).

Patch by Jan Schulz-Hofen.

git-svn-id: http://svn.redmine.org/redmine/trunk@15324 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2016-04-11 19:17:48 +00:00
parent c75157ac4a
commit 2fbce6515d
8 changed files with 20 additions and 2 deletions

View File

@ -40,6 +40,8 @@ class AttachmentsController < ApplicationController
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
@content = File.read(@attachment.diskfile, :mode => "rb")
render :action => 'file'
elsif @attachment.is_image?
render :action => 'image'
else
download
end

View File

@ -170,7 +170,9 @@ class RepositoriesController < ApplicationController
@content = @repository.cat(@path, @rev)
(show_error_not_found; return) unless @content
if is_raw ||
if !is_raw && Redmine::MimeType.is_type?('image', @path)
# simply render
elsif is_raw ||
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
! is_entry_text_data?(@content, @path)
# Force the download

View File

@ -237,6 +237,10 @@ class Attachment < ActiveRecord::Base
Redmine::MimeType.is_type?('text', filename)
end
def is_image?
Redmine::MimeType.is_type?('image', filename)
end
def is_diff?
self.filename =~ /\.(patch|diff)$/i
end

View File

@ -8,7 +8,7 @@
</div>
<% for attachment in attachments %>
<p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
<% if attachment.is_text? %>
<% if attachment.is_text? || attachment.is_image? %>
<%= link_to l(:button_view),
{ :controller => 'attachments', :action => 'show',
:id => attachment, :filename => attachment.filename },

View File

@ -0,0 +1,3 @@
<%= render :layout => 'layouts/file' do %>
<%= render :partial => 'common/image', :locals => {:path => download_named_attachment_url(@attachment, @attachment.filename), :alt => @attachment.filename} %>
<% end %>

View File

@ -0,0 +1 @@
<%= image_tag path, :alt => alt, :class => 'filecontent image' %>

View File

@ -8,7 +8,11 @@
<%= render :partial => 'link_to_functions' %>
<% if Redmine::MimeType.is_type?('image', @path) %>
<%= render :partial => 'common/image', :locals => {:path => url_for(params.merge(:action => 'raw')), :alt => @path} %>
<% else %>
<%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
<% end %>
<% content_for :header_tags do %>
<%= stylesheet_link_tag "scm" %>

View File

@ -67,6 +67,8 @@ table.filecontent td.line-code pre {
table.filecontent tr:target th.line-num { background-color:#E0E0E0; color: #777; }
table.filecontent tr:target td.line-code { background-color:#DDEEFF; }
img.filecontent.image { max-width: 100%; }
/* 12 different colors for the annonate view */
table.annotate tr.bloc-0 {background: #FFFFBF;}
table.annotate tr.bloc-1 {background: #EABFFF;}