diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-04-11 19:17:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-04-11 19:17:48 +0000 |
commit | 2fbce6515d6f87cae8c4f02d082f208595821bdd (patch) | |
tree | b41d298a944b58d2e5239a26a003551a770fb4b3 /app | |
parent | c75157ac4ae830c309b397b43c732a38fe290faf (diff) | |
download | redmine-2fbce6515d6f87cae8c4f02d082f208595821bdd.tar.gz redmine-2fbce6515d6f87cae8c4f02d082f208595821bdd.zip |
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
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/attachments_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/repositories_controller.rb | 4 | ||||
-rw-r--r-- | app/models/attachment.rb | 4 | ||||
-rw-r--r-- | app/views/attachments/_links.html.erb | 2 | ||||
-rw-r--r-- | app/views/attachments/image.html.erb | 3 | ||||
-rw-r--r-- | app/views/common/_image.html.erb | 1 | ||||
-rw-r--r-- | app/views/repositories/entry.html.erb | 4 |
7 files changed, 18 insertions, 2 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index a4aea5cf7..d81b3d9b2 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -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 diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index ded172a36..734b43983 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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 diff --git a/app/models/attachment.rb b/app/models/attachment.rb index b6216b428..7d577dc18 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -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 diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index a71a722ba..797f8bb43 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -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 }, diff --git a/app/views/attachments/image.html.erb b/app/views/attachments/image.html.erb new file mode 100644 index 000000000..306458366 --- /dev/null +++ b/app/views/attachments/image.html.erb @@ -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 %> diff --git a/app/views/common/_image.html.erb b/app/views/common/_image.html.erb new file mode 100644 index 000000000..ab73a2354 --- /dev/null +++ b/app/views/common/_image.html.erb @@ -0,0 +1 @@ +<%= image_tag path, :alt => alt, :class => 'filecontent image' %> diff --git a/app/views/repositories/entry.html.erb b/app/views/repositories/entry.html.erb index c9698f1d1..1f1118356 100644 --- a/app/views/repositories/entry.html.erb +++ b/app/views/repositories/entry.html.erb @@ -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" %> |