From c3e8c44515eba64b54c4484dcd91dd55c7f1e770 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Mon, 11 Apr 2016 15:51:20 +0200 Subject: [PATCH 2/5] =?UTF-8?q?Add=20view=20for=20=E2=80=9Cno-preview?= =?UTF-8?q?=E2=80=9D=20repository=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 28 +++++++++++++++------------- app/views/common/_other.html.erb | 1 + app/views/repositories/entry.html.erb | 4 +++- config/locales/de.yml | 1 + config/locales/en-GB.yml | 1 + config/locales/en.yml | 1 + 6 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 app/views/common/_other.html.erb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 734b439..ffb4dc5 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 0000000..fe0228a --- /dev/null +++ b/app/views/common/_other.html.erb @@ -0,0 +1 @@ +

<%= l(:label_no_preview) %>

diff --git a/app/views/repositories/entry.html.erb b/app/views/repositories/entry.html.erb index d9b5be9..37a5db9 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 %> diff --git a/config/locales/de.yml b/config/locales/de.yml index ced177e..a7a61e0 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -655,6 +655,7 @@ de: label_next: Weiter label_no_change_option: (Keine Änderung) label_no_data: Nichts anzuzeigen + label_no_preview: Keine Vorschau verfügbar label_no_issues_in_project: keine Tickets im Projekt label_nobody: Niemand label_none: kein diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index fb425bb..44f5d20 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -531,6 +531,7 @@ en-GB: label_attribute: Attribute label_attribute_plural: Attributes label_no_data: No data to display + label_no_preview: No preview available label_change_status: Change status label_history: History label_attachment: File diff --git a/config/locales/en.yml b/config/locales/en.yml index c198851..b8bb871 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -617,6 +617,7 @@ en: label_attribute: Attribute label_attribute_plural: Attributes label_no_data: No data to display + label_no_preview: No preview available label_change_status: Change status label_history: History label_attachment: File -- 2.8.0