diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-08 08:02:23 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-08 08:02:23 +0000 |
commit | 3d2c198c0f889e73ae2a16a068c41948b40cefff (patch) | |
tree | c764f9e787428d113cc37201f93e2c0e719e259d /app | |
parent | d8d23fbb6b23f15c6c5cc0a65ebfdf99c06e1a9b (diff) | |
download | redmine-3d2c198c0f889e73ae2a16a068c41948b40cefff.tar.gz redmine-3d2c198c0f889e73ae2a16a068c41948b40cefff.zip |
Add view for "no preview" repository files (#22482).
Patch by Gregor Schmidt.
git-svn-id: http://svn.redmine.org/redmine/trunk@15397 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/repositories_controller.rb | 28 | ||||
-rw-r--r-- | app/views/common/_other.html.erb | 1 | ||||
-rw-r--r-- | app/views/repositories/entry.html.erb | 4 |
3 files changed, 19 insertions, 14 deletions
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 8f34c0034..9c39ad075 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -168,24 +168,26 @@ class RepositoriesController < ApplicationController # If the entry is a dir, show the browser (show; return) if @entry.is_dir? - @content = @repository.cat(@path, @rev) - (show_error_not_found; return) unless @content - 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) + if is_raw # Force the download send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) } send_type = Redmine::MimeType.of(@path) send_opt[:type] = send_type.to_s if send_type - send_opt[:disposition] = (Redmine::MimeType.is_type?('image', @path) && !is_raw ? 'inline' : 'attachment') - send_data @content, send_opt + send_opt[:disposition] = (Redmine::MimeType.is_type?('image', @path) ? 'inline' : 'attachment') + send_data @repository.cat(@path, @rev), send_opt else - # Prevent empty lines when displaying a file with Windows style eol - # TODO: UTF-16 - # Is this needs? AttachmentsController reads file simply. - @content.gsub!("\r\n", "\n") + if !@entry.size || @entry.size <= Setting.file_max_size_displayed.to_i.kilobyte + content = @repository.cat(@path, @rev) + (show_error_not_found; return) unless content + + if content.size <= Setting.file_max_size_displayed.to_i.kilobyte && + is_entry_text_data?(content, @path) + # TODO: UTF-16 + # Prevent empty lines when displaying a file with Windows style eol + # Is this needed? AttachmentsController simply reads file. + @content = content.gsub("\r\n", "\n") + end + end @changeset = @repository.find_changeset_by_name(@rev) end end diff --git a/app/views/common/_other.html.erb b/app/views/common/_other.html.erb new file mode 100644 index 000000000..fe0228a50 --- /dev/null +++ b/app/views/common/_other.html.erb @@ -0,0 +1 @@ +<p class="nodata"><%= l(:label_no_preview) %></p> diff --git a/app/views/repositories/entry.html.erb b/app/views/repositories/entry.html.erb index d9b5be9ab..37a5db961 100644 --- a/app/views/repositories/entry.html.erb +++ b/app/views/repositories/entry.html.erb @@ -10,8 +10,10 @@ <% if Redmine::MimeType.is_type?('image', @path) %> <%= render :partial => 'common/image', :locals => {:path => url_for(params.merge(:action => 'raw')), :alt => @path} %> -<% else %> +<% elsif @content %> <%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %> +<% else %> + <%= render :partial => 'common/other' %> <% end %> <% content_for :header_tags do %> |