]> source.dussan.org Git - redmine.git/commitdiff
Adds previews for audio / video attachments (#27336).
authorGo MAEDA <maeda@farend.jp>
Thu, 17 May 2018 13:09:43 +0000 (13:09 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 17 May 2018 13:09:43 +0000 (13:09 +0000)
Patch by Jens Kraemer.

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

app/models/attachment.rb
app/views/attachments/other.html.erb
app/views/common/_no_preview.html.erb [new file with mode: 0644]
app/views/common/_other.html.erb
app/views/repositories/entry.html.erb
lib/redmine/mime_type.rb
public/stylesheets/scm.css

index b967e5720a20f77878772611e2f3576e2d345596..47955c0b1bc43399b4ffadbfdd8f61d8711b2364 100644 (file)
@@ -250,8 +250,16 @@ class Attachment < ActiveRecord::Base
     Redmine::MimeType.of(filename) == "application/pdf"
   end
 
+  def is_video?
+    Redmine::MimeType.is_type?('video', filename)
+  end
+
+  def is_audio?
+    Redmine::MimeType.is_type?('audio', filename)
+  end
+
   def previewable?
-    is_text? || is_image?
+    is_text? || is_image? || is_video? || is_audio?
   end
 
   # Returns true if the file is readable
index 608bbf232076ceb5bd3815d627213c9ffebc2c2a..f0f732f6ffb6ffeab3145616e200de4418398c8f 100644 (file)
@@ -1,6 +1,16 @@
 <%= render :layout => 'layouts/file' do %>
-  <%= render :partial => 'common/other',
+
+  <% kind = if @attachment.is_video?
+       'video'
+     elsif @attachment.is_audio?
+       'audio'
+     end %>
+
+  <%= render :partial => "common/other",
              :locals => {
+               :kind => kind,
+               :path => download_named_attachment_url(@attachment,
+                                                      @attachment.filename),
                :download_link => link_to_attachment(
                                    @attachment,
                                    :text => l(:label_no_preview_download),
diff --git a/app/views/common/_no_preview.html.erb b/app/views/common/_no_preview.html.erb
new file mode 100644 (file)
index 0000000..3eb9a95
--- /dev/null
@@ -0,0 +1,8 @@
+<p class="nodata">
+  <% if download_link %>
+    <%= t(:label_no_preview_alternative_html, link: download_link) %>
+  <% else %>
+    <%= l(:label_no_preview) %>
+  <% end %>
+</p>
+
index 74d87a60a970dd59ab1b1ca9a784d1de30082573..bb72ec3debcba49c25212fcd2b9828f08084d4e5 100644 (file)
@@ -1,7 +1,23 @@
-<p class="nodata">
-  <% if defined? download_link %>
-    <%= t(:label_no_preview_alternative_html, link: download_link) %>
+<% download_link = nil unless defined? download_link %>
+<% kind = nil unless defined? kind %>
+<% path = nil unless defined? path %>
+
+<% if path.present? %>
+
+  <% if kind == 'video' %>
+    <%= content_tag :video, class: 'filecontent', src: path, controls: true do %>
+      <%= render partial: 'common/no_preview', locals: { download_link: download_link } %>
+    <% end %>
+  <% elsif kind == 'audio' %>
+    <%= content_tag :audio, class: 'filecontent', src: path, controls: true do %>
+      <%= render partial: 'common/no_preview', locals: { download_link: download_link } %>
+    <% end %>
   <% else %>
-    <%= l(:label_no_preview) %>
-  <% end %>
-</p>
+    <%= render partial: 'common/no_preview', locals: { download_link: download_link } %>
+   <% end %>
+
+<% else %>
+
+  <%= render partial: 'common/no_preview', locals: { download_link: download_link } %>
+
+<% end %>
index 16bebc79c91ed05bce708c10d2a94458f87514c1..eb2e1d5e4b9961b96189e0f36e5f5bbd508cb487 100644 (file)
 <% elsif @content %>
   <%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
 <% else %>
+  <% kind = if Redmine::MimeType.is_type?('video', @path)
+       'video'
+     elsif Redmine::MimeType.is_type?('audio', @path)
+       'audio'
+     end %>
   <%= render :partial => 'common/other',
              :locals => {
+               :path => (url_for(params.merge(:action => 'raw')) if @allow_download),
+               :kind => kind,
                :download_link => @repository.supports_cat? ? link_to(
                  l(:label_no_preview_download),
                  { :action => 'raw', :id => @project,
index 45e352af84fe01b65790996c5f5047bb3ddcac32..38b6409aa650be40c3eeee9c2da4b424e81dce27 100644 (file)
@@ -46,6 +46,7 @@ module Redmine
       'image/x-ms-bmp' => 'bmp',
       'application/javascript' => 'js',
       'application/pdf' => 'pdf',
+      'video/mp4' => 'mp4',
     }.freeze
 
     EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
index b582d04e5264de1483260a2c44a331fe391898ec..c177b07ccef1c9ee5f18d267dcee7fb9ee95fea2 100644 (file)
@@ -71,7 +71,7 @@ table.filecontent td.line-code pre {
 table.filecontent tr:target th.line-num { background-color:#E0E0E0; color: #777; }
 table.filecontent tr:target td.line-code { background-color:#DDEEFF; }
 
-img.filecontent { max-width: 100%; }
+img.filecontent, video.filecontent { max-width: 100%; }
 
 .previous-filename {
   font-weight: normal;