]> source.dussan.org Git - redmine.git/commitdiff
Add view for "no preview" repository files (#22482).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 May 2016 08:02:23 +0000 (08:02 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 May 2016 08:02:23 +0000 (08:02 +0000)
Patch by Gregor Schmidt.

git-svn-id: http://svn.redmine.org/redmine/trunk@15397 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/repositories_controller.rb
app/views/common/_other.html.erb [new file with mode: 0644]
app/views/repositories/entry.html.erb
config/locales/de.yml
config/locales/en-GB.yml
config/locales/en.yml
test/functional/repositories_filesystem_controller_test.rb
test/functional/repositories_subversion_controller_test.rb

index 8f34c0034fc373a6800f9d2b15293aaa06fa2182..9c39ad0758a4e23fac4c1a2dceae96f2c01bf4f2 100644 (file)
@@ -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 (file)
index 0000000..fe0228a
--- /dev/null
@@ -0,0 +1 @@
+<p class="nodata"><%= l(:label_no_preview) %></p>
index d9b5be9ab2c0ab3eac006d98c595e35881a3612f..37a5db961ff559efe804b51bb4ca0c95a338ddce 100644 (file)
 
 <% 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 %>
index 3cac093f381c71a65144885ec058508a21bc843d..6b248c786bd17a3c8845e1bad830b68501a783ad 100644 (file)
@@ -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
index 4953f027fa3f723545e3662e8b88023306c2b4d0..3241d61547e73f4034c02efa8a1ce1ec8bbe576a 100644 (file)
@@ -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
index 947b2c9b04b54cbce39547bcf5566db159120210..f7c696dca3c13c4c125deb00edf2be3743979f98 100644 (file)
@@ -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
index 6d872cdf0ba7398eb93cc9f643cec77465d5e258..87c6cd26689787f24f424194fadcfb85dfff1991 100644 (file)
@@ -107,12 +107,13 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase
       end
     end
 
-    def test_show_text_file_should_send_if_too_big
+    def test_show_text_file_should_show_other_if_too_big
       with_settings :file_max_size_displayed => 1 do
         get :entry, :id => PRJ_ID,
             :path => repository_path_hash(['japanese', 'big-file.txt'])[:param]
         assert_response :success
-        assert_equal 'text/plain', @response.content_type
+        assert_equal 'text/html', @response.content_type
+        assert_select 'p.nodata'
       end
     end
 
index 41ea3ed37b4aaf0da3bec6ff022f6d637c1cd1ac..9eef38e3e3fa01c16c64b7839d7bb050f2d1700e 100644 (file)
@@ -168,7 +168,7 @@ class RepositoriesSubversionControllerTest < ActionController::TestCase
       assert_template 'entry'
     end
 
-    def test_entry_should_send_if_too_big
+    def test_entry_should_show_other_if_too_big
       assert_equal 0, @repository.changesets.count
       @repository.fetch_changesets
       @project.reload
@@ -178,8 +178,8 @@ class RepositoriesSubversionControllerTest < ActionController::TestCase
         get :entry, :id => PRJ_ID,
             :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
         assert_response :success
-        assert_equal 'attachment; filename="helloworld.c"',
-                     @response.headers['Content-Disposition']
+        assert_equal 'text/html', @response.content_type
+        assert_select 'p.nodata'
       end
     end