Embed video into wiki #1164

This commit is contained in:
karel.picman@lbcfree.net 2020-08-21 09:42:21 +02:00
parent c28741c1a5
commit 1bd6faa846
4 changed files with 55 additions and 0 deletions

View File

@ -152,6 +152,18 @@ Thumbnail with height of 200px: `{{dmsftn(8)}}`
Thumbnail with custom size: `{{dmsftn(8, size=300)}}` Thumbnail with custom size: `{{dmsftn(8, size=300)}}`
Inline video of the file with id 8; it must be an image file such as MP4: `{{dmsf_video(9)}}`
Inline video with custom size: `{{dmsf_video(9, size=300)}}`
Inline video with custom size: `{{dmsf_video(9, size=50%)}}`
Inline video with custom height: `{{dmsf_video(9, height=300)}}`
Inline video with custom width: `{{dmsf_video(9, width=300)}}`
Inline video with custom size: `{{dmsf_video(9, size=640x480)}}`
Approval workflow status of a document with id 8: `{{dmsfw(8)}}` Approval workflow status of a document with id 8: `{{dmsfw(8)}}`
The DMSF document/revision id can be found in document details. The DMSF document/revision id can be found in document details.

View File

@ -460,6 +460,9 @@ class DmsfFile < ActiveRecord::Base
last_revision && (Redmine::MimeType.of(last_revision.disk_filename) == 'application/pdf') last_revision && (Redmine::MimeType.of(last_revision.disk_filename) == 'application/pdf')
end end
def video?
last_revision && Redmine::MimeType.is_type?('video', last_revision.disk_filename)
end
def disposition def disposition
(image? || pdf?) ? 'inline' : 'attachment' (image? || pdf?) ? 'inline' : 'attachment'

View File

@ -178,6 +178,40 @@ Redmine::WikiFormatting::Macros.register do
end end
end end
# dmsf_video - link to a video
desc "Wiki DMSF image:\n\n" +
"{{dmsf_video(file_id)}}\n" +
"{{dmsf_video(file_id, size=300)}} -- with and size 300x300\n" +
"{{dmsf_video(file_id, height=300)}} -- with height (auto width)\n" +
"{{dmsf_video(file_id, width=300)}} -- with width (auto height)\n" +
"{{dmsf_video(file_id, size=640x480)}} -- with and size 640x480"
macro :dmsf_video do |obj, args|
args, options = extract_macro_options(args, :size, :width, :height, :title)
file_id = args.first
raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
width = options[:width]
height = options[:height]
if file = DmsfFile.find_by(id: file_id)
unless User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
raise l(:notice_not_authorized)
end
raise 'Not supported video format' unless file.video?
url = url_for(controller: :dmsf_files, action: 'view', id: file)
if size && size.include?('%')
video_tag url, controls: true, alt: file.title, width: size, height: size
elsif height
video_tag url, controls: true, alt: file.title, width: 'auto', height: height
elsif width
video_tag url, controls: true, alt: file.title, width: width, height: 'auto'
else
video_tag url, controls: true, alt: file.title, size: size
end
else
raise "Document ID #{file_id} not found"
end
end
# dmsftn - link to an image thumbnail # dmsftn - link to an image thumbnail
desc "Wiki DMSF thumbnail:\n\n" + desc "Wiki DMSF thumbnail:\n\n" +
"{{dmsftn(file_id)}} -- with default height 200(auto width)\n" + "{{dmsftn(file_id)}} -- with default height 200(auto width)\n" +

View File

@ -209,6 +209,12 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest
assert @file8.pdf? assert @file8.pdf?
end end
def test_video
assert !@file1.video?
@file1.last_revision.disk_filename = 'test.mp4'
assert @file1.video?
end
def test_findn_file_by_name def test_findn_file_by_name
assert DmsfFile.find_file_by_name(@project1, nil, 'test.txt') assert DmsfFile.find_file_by_name(@project1, nil, 'test.txt')
assert_nil DmsfFile.find_file_by_name(@project1, nil, 'test.odt') assert_nil DmsfFile.find_file_by_name(@project1, nil, 'test.odt')