##// END OF EJS Templates
Add inline image preview/display for attachments and repository entries (#22058)....
Jean-Philippe Lang -
r14942:2fbce6515d6f
parent child
Show More
@@ -0,0 +1,3
1 <%= render :layout => 'layouts/file' do %>
2 <%= render :partial => 'common/image', :locals => {:path => download_named_attachment_url(@attachment, @attachment.filename), :alt => @attachment.filename} %>
3 <% end %>
@@ -0,0 +1,1
1 <%= image_tag path, :alt => alt, :class => 'filecontent image' %>
@@ -40,6 +40,8 class AttachmentsController < ApplicationController
40 elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
40 elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
41 @content = File.read(@attachment.diskfile, :mode => "rb")
41 @content = File.read(@attachment.diskfile, :mode => "rb")
42 render :action => 'file'
42 render :action => 'file'
43 elsif @attachment.is_image?
44 render :action => 'image'
43 else
45 else
44 download
46 download
45 end
47 end
@@ -170,7 +170,9 class RepositoriesController < ApplicationController
170
170
171 @content = @repository.cat(@path, @rev)
171 @content = @repository.cat(@path, @rev)
172 (show_error_not_found; return) unless @content
172 (show_error_not_found; return) unless @content
173 if is_raw ||
173 if !is_raw && Redmine::MimeType.is_type?('image', @path)
174 # simply render
175 elsif is_raw ||
174 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
176 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
175 ! is_entry_text_data?(@content, @path)
177 ! is_entry_text_data?(@content, @path)
176 # Force the download
178 # Force the download
@@ -237,6 +237,10 class Attachment < ActiveRecord::Base
237 Redmine::MimeType.is_type?('text', filename)
237 Redmine::MimeType.is_type?('text', filename)
238 end
238 end
239
239
240 def is_image?
241 Redmine::MimeType.is_type?('image', filename)
242 end
243
240 def is_diff?
244 def is_diff?
241 self.filename =~ /\.(patch|diff)$/i
245 self.filename =~ /\.(patch|diff)$/i
242 end
246 end
@@ -8,7 +8,7
8 </div>
8 </div>
9 <% for attachment in attachments %>
9 <% for attachment in attachments %>
10 <p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
10 <p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
11 <% if attachment.is_text? %>
11 <% if attachment.is_text? || attachment.is_image? %>
12 <%= link_to l(:button_view),
12 <%= link_to l(:button_view),
13 { :controller => 'attachments', :action => 'show',
13 { :controller => 'attachments', :action => 'show',
14 :id => attachment, :filename => attachment.filename },
14 :id => attachment, :filename => attachment.filename },
@@ -8,7 +8,11
8
8
9 <%= render :partial => 'link_to_functions' %>
9 <%= render :partial => 'link_to_functions' %>
10
10
11 <% if Redmine::MimeType.is_type?('image', @path) %>
12 <%= render :partial => 'common/image', :locals => {:path => url_for(params.merge(:action => 'raw')), :alt => @path} %>
13 <% else %>
11 <%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
14 <%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
15 <% end %>
12
16
13 <% content_for :header_tags do %>
17 <% content_for :header_tags do %>
14 <%= stylesheet_link_tag "scm" %>
18 <%= stylesheet_link_tag "scm" %>
@@ -67,6 +67,8 table.filecontent td.line-code pre {
67 table.filecontent tr:target th.line-num { background-color:#E0E0E0; color: #777; }
67 table.filecontent tr:target th.line-num { background-color:#E0E0E0; color: #777; }
68 table.filecontent tr:target td.line-code { background-color:#DDEEFF; }
68 table.filecontent tr:target td.line-code { background-color:#DDEEFF; }
69
69
70 img.filecontent.image { max-width: 100%; }
71
70 /* 12 different colors for the annonate view */
72 /* 12 different colors for the annonate view */
71 table.annotate tr.bloc-0 {background: #FFFFBF;}
73 table.annotate tr.bloc-0 {background: #FFFFBF;}
72 table.annotate tr.bloc-1 {background: #EABFFF;}
74 table.annotate tr.bloc-1 {background: #EABFFF;}
General Comments 0
You need to be logged in to leave comments. Login now