Embed video into wiki #1164
This commit is contained in:
parent
c28741c1a5
commit
1bd6faa846
12
README.md
12
README.md
@ -152,6 +152,18 @@ Thumbnail with height of 200px: `{{dmsftn(8)}}`
|
||||
|
||||
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)}}`
|
||||
|
||||
The DMSF document/revision id can be found in document details.
|
||||
|
||||
@ -460,6 +460,9 @@ class DmsfFile < ActiveRecord::Base
|
||||
last_revision && (Redmine::MimeType.of(last_revision.disk_filename) == 'application/pdf')
|
||||
end
|
||||
|
||||
def video?
|
||||
last_revision && Redmine::MimeType.is_type?('video', last_revision.disk_filename)
|
||||
end
|
||||
|
||||
def disposition
|
||||
(image? || pdf?) ? 'inline' : 'attachment'
|
||||
|
||||
@ -178,6 +178,40 @@ Redmine::WikiFormatting::Macros.register do
|
||||
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
|
||||
desc "Wiki DMSF thumbnail:\n\n" +
|
||||
"{{dmsftn(file_id)}} -- with default height 200(auto width)\n" +
|
||||
|
||||
@ -209,6 +209,12 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest
|
||||
assert @file8.pdf?
|
||||
end
|
||||
|
||||
def test_video
|
||||
assert !@file1.video?
|
||||
@file1.last_revision.disk_filename = 'test.mp4'
|
||||
assert @file1.video?
|
||||
end
|
||||
|
||||
def test_findn_file_by_name
|
||||
assert DmsfFile.find_file_by_name(@project1, nil, 'test.txt')
|
||||
assert_nil DmsfFile.find_file_by_name(@project1, nil, 'test.odt')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user