Little bug in PDF image export (Redmine 3.4.6) #903
This commit is contained in:
parent
b34469eb28
commit
bc1aa81845
@ -38,6 +38,7 @@ require File.dirname(__FILE__) + '/redmine_dmsf/patches/user_patch'
|
||||
require File.dirname(__FILE__) + '/redmine_dmsf/patches/issue_patch'
|
||||
require File.dirname(__FILE__) + '/redmine_dmsf/patches/role_patch'
|
||||
require File.dirname(__FILE__) + '/redmine_dmsf/patches/queries_controller_patch'
|
||||
require File.dirname(__FILE__) + '/redmine_dmsf/patches/pdf_patch'
|
||||
|
||||
# A workaround for obsolete 'alias_method' usage in RedmineUp's plugins
|
||||
if (RedmineDmsf::Plugin.present?(:redmine_questions) || Redmine::Plugin.installed?(:redmine_contacts) ||
|
||||
|
||||
@ -172,15 +172,17 @@ module RedmineDmsf
|
||||
raise l(:notice_not_authorized)
|
||||
end
|
||||
raise 'Not supported image format' unless file.image?
|
||||
url = view_dmsf_file_url(file)
|
||||
member = Member.find_by(user_id: User.current.id, project_id: file.project.id)
|
||||
filename = file.last_revision.formatted_name(member)
|
||||
url = static_dmsf_file_url(file, filename: filename)
|
||||
if size&.include?('%')
|
||||
html << image_tag(url, alt: file.title, width: size, height: size)
|
||||
html << image_tag(url, alt: filename, title: file.title, width: size, height: size)
|
||||
elsif height
|
||||
html << image_tag(url, alt: file.title, width: 'auto', height: height)
|
||||
html << image_tag(url, alt: filename, title: file.title, width: 'auto', height: height)
|
||||
elsif width
|
||||
html << image_tag(url, alt: file.title, width: width, height: 'auto')
|
||||
html << image_tag(url, alt: filename, title: file.title, width: width, height: 'auto')
|
||||
else
|
||||
html << (image_tag url, alt: file.title, size: size)
|
||||
html << (image_tag url, alt: filename, title: file.title, size: size)
|
||||
end
|
||||
end
|
||||
html.html_safe
|
||||
@ -205,15 +207,17 @@ module RedmineDmsf
|
||||
raise l(:notice_not_authorized)
|
||||
end
|
||||
raise 'Not supported video format' unless file.video?
|
||||
url = view_dmsf_file_url(file)
|
||||
member = Member.find_by(user_id: User.current.id, project_id: file.project.id)
|
||||
filename = file.last_revision.formatted_name(member)
|
||||
url = static_dmsf_file_url(file, filename: filename)
|
||||
if size&.include?('%')
|
||||
video_tag url, controls: true, alt: file.title, width: size, height: size
|
||||
video_tag url, controls: true, alt: filename, title: file.title, width: size, height: size
|
||||
elsif height
|
||||
video_tag url, controls: true, alt: file.title, width: 'auto', height: height
|
||||
video_tag url, controls: true, alt: filename, title: file.title, width: 'auto', height: height
|
||||
elsif width
|
||||
video_tag url, controls: true, alt: file.title, width: width, height: 'auto'
|
||||
video_tag url, controls: true, alt: filename, title: file.title, width: width, height: 'auto'
|
||||
else
|
||||
video_tag url, controls: true, alt: file.title, size: size
|
||||
video_tag url, controls: true, alt: filename, title: file.title, size: size
|
||||
end
|
||||
end
|
||||
|
||||
@ -238,15 +242,17 @@ module RedmineDmsf
|
||||
raise l(:notice_not_authorized)
|
||||
end
|
||||
raise 'Not supported image format' unless file.image?
|
||||
url = view_dmsf_file_url(file)
|
||||
member = Member.find_by(user_id: User.current.id, project_id: file.project.id)
|
||||
filename = file.last_revision.formatted_name(member)
|
||||
url = static_dmsf_file_url(file, filename: filename)
|
||||
if size
|
||||
img = image_tag(url, alt: file.title, size: size)
|
||||
img = image_tag(url, alt: filename, title: file.title, size: size)
|
||||
elsif height
|
||||
img = image_tag(url, alt: file.title, width: 'auto', height: height)
|
||||
img = image_tag(url, alt: filename, title: file.title, width: 'auto', height: height)
|
||||
elsif width
|
||||
img = image_tag(url, alt: file.title, width: width, height: 'auto')
|
||||
img = image_tag(url, alt: filename, title: file.title, width: width, height: 'auto')
|
||||
else
|
||||
img = image_tag(url, alt: file.title, width: 'auto', height: 200)
|
||||
img = image_tag(url, alt: filename, title: file.title, width: 'auto', height: 200)
|
||||
end
|
||||
html << link_to( img, url, target: '_blank', title: h(file.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{url}")
|
||||
|
||||
52
lib/redmine_dmsf/patches/pdf_patch.rb
Normal file
52
lib/redmine_dmsf/patches/pdf_patch.rb
Normal file
@ -0,0 +1,52 @@
|
||||
# encoding: utf-8
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright © 2011-22 Karel Pičman <karel.picman@kontron.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# Redmine's PDF export patch to view DMS images
|
||||
|
||||
require 'redmine/export/pdf'
|
||||
|
||||
module RedmineDmsf
|
||||
module Patches
|
||||
module PdfPatch
|
||||
|
||||
##################################################################################################################
|
||||
# Overriden methods
|
||||
|
||||
def get_image_filename(attrname)
|
||||
if attrname =~ /\/dmsf\/files\/(\d+)\//
|
||||
file = DmsfFile.find_by(id: $1)
|
||||
file&.last_revision ? file.last_revision.disk_file : nil
|
||||
else
|
||||
super attrname
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Apply the patch
|
||||
if Redmine::Plugin.installed?(:easy_extensions)
|
||||
RedmineExtensions::PatchManager.register_patch_to_be_first 'Redmine::Export::PDF::ITCPDF',
|
||||
'RedmineDmsf::Patches::PdfPatch', prepend: true, first: true
|
||||
else
|
||||
Redmine::Export::PDF::ITCPDF.prepend RedmineDmsf::Patches::PdfPatch
|
||||
end
|
||||
@ -219,54 +219,59 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
||||
|
||||
# {{dmsf_image(file_id)}}
|
||||
def test_macro_dmsf_image
|
||||
url = static_dmsf_file_url(@file7, @file7.last_revision.name)
|
||||
text = textilizable("{{dmsf_image(#{@file7.id})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, size: nil)
|
||||
link = image_tag(url, alt: @file7.name, title: @file7.title, size: nil)
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
# {{dmsf_image(file_id file_id)}}
|
||||
def test_macro_dmsf_image_multiple
|
||||
url = static_dmsf_file_url(@file7, @file7.last_revision.name)
|
||||
text = textilizable("{{dmsf_image(#{@file7.id} #{@file7.id})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, size: nil)
|
||||
link = image_tag(url, alt: @file7.name, title: @file7.title, size: nil)
|
||||
assert_equal "<p>#{link}#{link}</p>", text
|
||||
end
|
||||
|
||||
def test_macro_dmsf_image_size
|
||||
size = '50%'
|
||||
url = static_dmsf_file_url(@file7, @file7.last_revision.name)
|
||||
text = textilizable("{{dmsf_image(#{@file7.id}, size=#{size})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, width: size, height: size)
|
||||
link = image_tag(url, alt: @file7.name, title: @file7.title, width: size, height: size)
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
size = '300'
|
||||
text = textilizable("{{dmsf_image(#{@file7.id}, size=#{size})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, width: size, height: size)
|
||||
link = image_tag(url, alt: @file7.name, title: @file7.title, width: size, height: size)
|
||||
# TODO: arguments src and with and height are swapped
|
||||
#assert_equal "<p>#{link}</p>", text
|
||||
size = '640x480'
|
||||
text = textilizable("{{dmsf_image(#{@file7.id}, size=#{size})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, width: '640', height: '480')
|
||||
link = image_tag(url, alt: @file7.name, title: @file7.title, width: '640', height: '480')
|
||||
# TODO: arguments src and with and height are swapped
|
||||
#assert_equal "<p>#{link}</p>", text
|
||||
height = '480'
|
||||
text = textilizable("{{dmsf_image(#{@file7.id}, height=#{height})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, width: 'auto', height: height)
|
||||
link = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: height)
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
width = '480'
|
||||
text = textilizable("{{dmsf_image(#{@file7.id}, width=#{height})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, width: width, height: 'auto')
|
||||
link = image_tag(url, alt: @file7.name, title: @file7.title, width: width, height: 'auto')
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
def test_macro_dmsf_image_no_permissions
|
||||
@manager_role.remove_permission! :view_dmsf_files
|
||||
url = static_dmsf_file_url(@file7, @file7.last_revision.name)
|
||||
text = textilizable("{{dmsf_image(#{@file7.id})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, size: nil)
|
||||
link = image_tag(url, alt: @file7.name, title: @file7.title, size: nil)
|
||||
assert_not_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
def test_macro_dmsf_image_dmsf_off
|
||||
@project1.disable_module! :dmsf
|
||||
url = static_dmsf_file_url(@file7, @file7.last_revision.name)
|
||||
text = textilizable("{{dmsf_image(#{@file7.id})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, size: nil)
|
||||
link = image_tag(url, alt: @file7.name, title: @file7.title, size: nil)
|
||||
assert_not_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
@ -278,44 +283,48 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
||||
# {{dmsf_video(file_id)}}
|
||||
def test_macro_dmsf_video
|
||||
text = textilizable("{{dmsf_video(#{@file6.id})}}")
|
||||
link = video_tag(view_dmsf_file_url(@file6), controls: true, alt: @file6.title)
|
||||
url = static_dmsf_file_url(@file6, @file6.last_revision.name)
|
||||
link = video_tag(url, controls: true, alt: @file6.name, title: @file6.title)
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
def test_macro_dmsf_image_size
|
||||
def test_macro_dmsf_video_size
|
||||
size = '50%'
|
||||
url = static_dmsf_file_url(@file6, @file6.last_revision.name)
|
||||
text = textilizable("{{dmsf_video(#{@file6.id}, size=#{size})}}")
|
||||
link = video_tag(view_dmsf_file_url(@file6), controls: true, alt: @file6.title, width: size, height: size)
|
||||
link = video_tag(url, controls: true, alt: @file6.name, title: @file6.title, width: size, height: size)
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
size = '300'
|
||||
text = textilizable("{{dmsf_video(#{@file6.id}, size=#{size})}}")
|
||||
link = video_tag(view_dmsf_file_url(@file6), controls: true, alt: @file6.title, width: size, height: size)
|
||||
link = video_tag(url, controls: true, alt: @file6.name, title: @file6.title, width: size, height: size)
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
size = '640x480'
|
||||
text = textilizable("{{dmsf_video(#{@file6.id}, size=#{size})}}")
|
||||
link = video_tag(view_dmsf_file_url(@file6), controls: true, alt: @file6.title, width: '640', height: '480')
|
||||
link = video_tag(url, controls: true, alt: @file6.name, title: @file6.title, width: '640', height: '480')
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
height = '480'
|
||||
text = textilizable("{{dmsf_video(#{@file6.id}, height=#{height})}}")
|
||||
link = video_tag(view_dmsf_file_url(@file6), controls: true, alt: @file6.title, width: 'auto', height: height)
|
||||
link = video_tag(url, controls: true, alt: @file6.name, title: @file6.title, width: 'auto', height: height)
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
width = '480'
|
||||
text = textilizable("{{dmsf_video(#{@file6.id}, width=#{height})}}")
|
||||
link = video_tag(view_dmsf_file_url(@file6), controls: true, alt: @file6.title, width: width, height: 'auto')
|
||||
link = video_tag(url, controls: true, alt: @file6.name, title: @file6.title, width: width, height: 'auto')
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
def test_macro_dmsf_image_no_permissions
|
||||
def test_macro_dmsf_video_no_permissions
|
||||
@manager_role.remove_permission! :view_dmsf_files
|
||||
text = textilizable("{{dmsf_video(#{@file6.id})}}")
|
||||
link = video_tag(view_dmsf_file_url(@file6), controls: true, alt: @file6.title)
|
||||
url = static_dmsf_file_url(@file6, @file6.last_revision.name)
|
||||
link = video_tag(url, controls: true, alt: @file6.name, title: @file6.title)
|
||||
assert_not_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
def test_macro_dmsf_image_dmsf_off
|
||||
def test_macro_dmsf_video_dmsf_off
|
||||
@project1.disable_module! :dmsf
|
||||
text = textilizable("{{dmsf_video(#{@file6.id})}}")
|
||||
link = video_tag(view_dmsf_file_url(@file6), controls: true, alt: @file6.title)
|
||||
url = static_dmsf_file_url(@file6, @file6.last_revision.name)
|
||||
link = video_tag(url, controls: true, alt: @file6.name, title: @file6.title)
|
||||
assert_not_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
@ -327,8 +336,8 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
||||
# {{dmsftn(file_id)}}
|
||||
def test_macro_dmsftn
|
||||
text = textilizable("{{dmsftn(#{@file7.id})}}")
|
||||
url = view_dmsf_file_url(@file7)
|
||||
img = image_tag(url, alt: @file7.title, width: 'auto', height: 200)
|
||||
url = static_dmsf_file_url(@file7, @file7.last_revision.name)
|
||||
img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 200)
|
||||
link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}")
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
@ -337,8 +346,8 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
||||
# {{dmsftn(file_id file_id)}}
|
||||
def test_macro_dmsftn_multiple
|
||||
text = textilizable("{{dmsftn(#{@file7.id} #{@file7.id})}}")
|
||||
url = view_dmsf_file_url(@file7)
|
||||
img = image_tag(url, alt: @file7.title, width: 'auto', height: 200)
|
||||
url = static_dmsf_file_url(@file7, @file7.last_revision.name)
|
||||
img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 200)
|
||||
link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}")
|
||||
assert_equal "<p>#{link}#{link}</p>", text
|
||||
@ -346,29 +355,29 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
||||
|
||||
# {{dmsftn(file_id size=300)}}
|
||||
def test_macro_dmsftn_size
|
||||
url = view_dmsf_file_url(@file7)
|
||||
url = static_dmsf_file_url(@file7, @file7.last_revision.name)
|
||||
size = '300'
|
||||
text = textilizable("{{dmsftn(#{@file7.id}, size=#{size})}}")
|
||||
img = image_tag(url, alt: @file7.title, size: size)
|
||||
img = image_tag(url, alt: @file7.name, title: @file7.title, size: size)
|
||||
link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}")
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
size = '640x480'
|
||||
text = textilizable("{{dmsftn(#{@file7.id}, size=#{size})}}")
|
||||
img = image_tag(url, alt: @file7.title, width: 640, height: 480)
|
||||
img = image_tag(url, alt: @file7.name, title: @file7.title, width: 640, height: 480)
|
||||
link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}")
|
||||
# TODO: arguments src and with and height are swapped
|
||||
#assert_equal "<p>#{link}</p>", text
|
||||
height = '480'
|
||||
text = textilizable("{{dmsftn(#{@file7.id}, height=#{height})}}")
|
||||
img = image_tag(url, alt: @file7.title, width: 'auto', height: 480)
|
||||
img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 480)
|
||||
link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}")
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
width = '640'
|
||||
text = textilizable("{{dmsftn(#{@file7.id}, width=#{width})}}")
|
||||
img = image_tag(url, alt: @file7.title, width: 640, height: 'auto')
|
||||
img = image_tag(url, alt: @file7.name, title: @file7.title, width: 640, height: 'auto')
|
||||
link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}")
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
@ -378,7 +387,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
||||
@manager_role.remove_permission! :view_dmsf_files
|
||||
text = textilizable("{{dmsftn(#{@file7.id})}}")
|
||||
url = view_dmsf_file_url(@file7)
|
||||
img = image_tag(url, alt: @file7.title, width: 'auto', height: 200)
|
||||
img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 200)
|
||||
link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}")
|
||||
assert_not_equal "<p>#{link}</p>", text
|
||||
@ -388,7 +397,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
||||
@project1.disable_module! :dmsf
|
||||
text = textilizable("{{dmsftn(#{@file7.id})}}")
|
||||
url = view_dmsf_file_url(@file7)
|
||||
img = image_tag(url, alt: @file7.title, width: 'auto', height: 200)
|
||||
img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 200)
|
||||
link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}")
|
||||
assert_not_equal "<p>#{link}</p>", text
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user