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
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
app/views/attachments/other.html.erb
<%= 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),
app/views/common/_no_preview.html.erb
<p class="nodata">
<% if download_link %>
<%= t(:label_no_preview_alternative_html, link: download_link) %>
<% else %>
<%= l(:label_no_preview) %>
<% end %>
</p>
app/views/common/_other.html.erb
<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 %>
app/views/repositories/entry.html.erb
<% 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,
lib/redmine/mime_type.rb
'image/x-ms-bmp' => 'bmp',
'application/javascript' => 'js',
'application/pdf' => 'pdf',
'video/mp4' => 'mp4',
}.freeze
EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
public/stylesheets/scm.css
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%; }
/* 12 different colors for the annonate view */
table.annotate tr.bloc-0 td.author {border-right-color: #FFFFBF;}
(1-1/3)