From 1bd6faa846a9b28cd871f34e6d0cd38df18b68e7 Mon Sep 17 00:00:00 2001 From: "karel.picman@lbcfree.net" Date: Fri, 21 Aug 2020 09:42:21 +0200 Subject: [PATCH] Embed video into wiki #1164 --- README.md | 12 ++++++++++++ app/models/dmsf_file.rb | 3 +++ lib/redmine_dmsf/macros.rb | 34 ++++++++++++++++++++++++++++++++++ test/unit/dmsf_file_test.rb | 6 ++++++ 4 files changed, 55 insertions(+) diff --git a/README.md b/README.md index b3e6feee..2b8f9b00 100644 --- a/README.md +++ b/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. diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index bb5955b5..44be7f9f 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -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' diff --git a/lib/redmine_dmsf/macros.rb b/lib/redmine_dmsf/macros.rb index 3e31d8f7..58e7556c 100644 --- a/lib/redmine_dmsf/macros.rb +++ b/lib/redmine_dmsf/macros.rb @@ -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" + diff --git a/test/unit/dmsf_file_test.rb b/test/unit/dmsf_file_test.rb index 6bdbdbd6..fd7c1548 100644 --- a/test/unit/dmsf_file_test.rb +++ b/test/unit/dmsf_file_test.rb @@ -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')