Project

General

Profile

Patch #27336 » 0001-adds-previews-for-audio-video-attachments.patch

Jens Krämer, 2017-10-31 10:57

View differences:

app/models/attachment.rb
250 250
    Redmine::MimeType.of(filename) == "application/pdf"
251 251
  end
252 252

  
253
  def is_video?
254
    Redmine::MimeType.is_type?('video', filename)
255
  end
256

  
257
  def is_audio?
258
    Redmine::MimeType.is_type?('audio', filename)
259
  end
260

  
253 261
  def previewable?
254
    is_text? || is_image?
262
    is_text? || is_image? || is_video? || is_audio?
255 263
  end
256 264

  
257 265
  # Returns true if the file is readable
app/views/attachments/other.html.erb
1 1
<%= render :layout => 'layouts/file' do %>
2
  <%= render :partial => 'common/other',
2

  
3
  <% kind = if @attachment.is_video?
4
       'video'
5
     elsif @attachment.is_audio?
6
       'audio'
7
     end %>
8

  
9
  <%= render :partial => "common/other",
3 10
             :locals => {
11
               :kind => kind,
12
               :path => download_named_attachment_url(@attachment,
13
                                                      @attachment.filename),
4 14
               :download_link => link_to_attachment(
5 15
                                   @attachment,
6 16
                                   :text => l(:label_no_preview_download),
app/views/common/_no_preview.html.erb
1
<p class="nodata">
2
  <% if download_link %>
3
    <%= t(:label_no_preview_alternative_html, link: download_link) %>
4
  <% else %>
5
    <%= l(:label_no_preview) %>
6
  <% end %>
7
</p>
8

  
app/views/common/_other.html.erb
1
<p class="nodata">
2
  <% if defined? download_link %>
3
    <%= t(:label_no_preview_alternative_html, link: download_link) %>
1
<% download_link = nil unless defined? download_link %>
2
<% kind = nil unless defined? kind %>
3
<% path = nil unless defined? path %>
4

  
5
<% if path.present? %>
6

  
7
  <% if kind == 'video' %>
8
    <%= content_tag :video, class: 'filecontent', src: path, controls: true do %>
9
      <%= render partial: 'common/no_preview', locals: { download_link: download_link } %>
10
    <% end %>
11
  <% elsif kind == 'audio' %>
12
    <%= content_tag :audio, class: 'filecontent', src: path, controls: true do %>
13
      <%= render partial: 'common/no_preview', locals: { download_link: download_link } %>
14
    <% end %>
4 15
  <% else %>
5
    <%= l(:label_no_preview) %>
6
  <% end %>
7
</p>
16
    <%= render partial: 'common/no_preview', locals: { download_link: download_link } %>
17
   <% end %>
18

  
19
<% else %>
20

  
21
  <%= render partial: 'common/no_preview', locals: { download_link: download_link } %>
22

  
23
<% end %>
app/views/repositories/entry.html.erb
17 17
<% elsif @content %>
18 18
  <%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
19 19
<% else %>
20
  <% kind = if Redmine::MimeType.is_type?('video', @path)
21
       'video'
22
     elsif Redmine::MimeType.is_type?('audio', @path)
23
       'audio'
24
     end %>
20 25
  <%= render :partial => 'common/other',
21 26
             :locals => {
27
               :path => (url_for(params.merge(:action => 'raw')) if @allow_download),
28
               :kind => kind,
22 29
               :download_link => @repository.supports_cat? ? link_to(
23 30
                 l(:label_no_preview_download),
24 31
                 { :action => 'raw', :id => @project,
lib/redmine/mime_type.rb
46 46
      'image/x-ms-bmp' => 'bmp',
47 47
      'application/javascript' => 'js',
48 48
      'application/pdf' => 'pdf',
49
      'video/mp4' => 'mp4',
49 50
    }.freeze
50 51

  
51 52
    EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
public/stylesheets/scm.css
71 71
table.filecontent tr:target th.line-num { background-color:#E0E0E0; color: #777; }
72 72
table.filecontent tr:target td.line-code { background-color:#DDEEFF; }
73 73

  
74
img.filecontent { max-width: 100%; }
74
img.filecontent, video.filecontent { max-width: 100%; }
75 75

  
76 76
/* 12 different colors for the annonate view */
77 77
table.annotate tr.bloc-0 td.author {border-right-color: #FFFFBF;}
(1-1/3)