More than one ID in image rendering macros #1082

This commit is contained in:
Karel Pičman 2022-06-23 09:06:21 +02:00
parent 4749c6051a
commit b34469eb28
3 changed files with 63 additions and 31 deletions

View File

@ -155,6 +155,8 @@ Link to the preview of 5 lines from a document with id 17: `{{dmsft(17, 5)}}`
Inline picture of the file with id 8; it must be an image file such as JPEG, PNG,...: `{{dmsf_image(8)}}` Inline picture of the file with id 8; it must be an image file such as JPEG, PNG,...: `{{dmsf_image(8)}}`
Multiple inline pictures: `{{dmsf_image(8 9 10)}}`
Inline picture with custom size: `{{dmsf_image(8, size=300)}}` Inline picture with custom size: `{{dmsf_image(8, size=300)}}`
Inline picture with custom size: `{{dmsf_image(8, size=50%)}}` Inline picture with custom size: `{{dmsf_image(8, size=50%)}}`
@ -167,6 +169,8 @@ Inline picture with custom size: `{{dmsf_image(8, size=640x480)}}`
Thumbnail with height of 200px: `{{dmsftn(8)}}` Thumbnail with height of 200px: `{{dmsftn(8)}}`
Multiple thumbnails with height of 200px: `{{dmsftn(8 9 10)}}`
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 a video file such as MP4: `{{dmsf_video(9)}}` Inline video of the file with id 8; it must be a video file such as MP4: `{{dmsf_video(9)}}`

View File

@ -164,21 +164,26 @@ module RedmineDmsf
size = options[:size] size = options[:size]
width = options[:width] width = options[:width]
height = options[:height] height = options[:height]
file = DmsfFile.visible.find args[0] ids = args[0].split
unless User.current&.allowed_to?(:view_dmsf_files, file.project) html = +''
raise l(:notice_not_authorized) ids.each do |id|
end file = DmsfFile.visible.find(id)
raise 'Not supported image format' unless file.image? unless User.current&.allowed_to?(:view_dmsf_files, file.project)
url = view_dmsf_file_url(file) raise l(:notice_not_authorized)
if size&.include?('%') end
image_tag url, alt: file.title, width: size, height: size raise 'Not supported image format' unless file.image?
elsif height url = view_dmsf_file_url(file)
image_tag url, alt: file.title, width: 'auto', height: height if size&.include?('%')
elsif width html << image_tag(url, alt: file.title, width: size, height: size)
image_tag url, alt: file.title, width: width, height: 'auto' elsif height
else html << image_tag(url, alt: file.title, width: 'auto', height: height)
image_tag url, alt: file.title, size: size elsif width
html << image_tag(url, alt: file.title, width: width, height: 'auto')
else
html << (image_tag url, alt: file.title, size: size)
end
end end
html.html_safe
end end
# dmsf_video - link to a video # dmsf_video - link to a video
@ -225,23 +230,28 @@ module RedmineDmsf
size = options[:size] size = options[:size]
width = options[:width] width = options[:width]
height = options[:height] height = options[:height]
file = DmsfFile.visible.find args[0] ids = args[0].split
unless User.current&.allowed_to?(:view_dmsf_files, file.project) html = +''
raise l(:notice_not_authorized) ids.each do |id|
file = DmsfFile.visible.find(id)
unless User.current&.allowed_to?(:view_dmsf_files, file.project)
raise l(:notice_not_authorized)
end
raise 'Not supported image format' unless file.image?
url = view_dmsf_file_url(file)
if size
img = image_tag(url, alt: file.title, size: size)
elsif height
img = image_tag(url, alt: file.title, width: 'auto', height: height)
elsif width
img = image_tag(url, alt: file.title, width: width, height: 'auto')
else
img = image_tag(url, alt: 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}")
end end
raise 'Not supported image format' unless file.image? html.html_safe
url = view_dmsf_file_url(file)
if size
img = image_tag(url, alt: file.title, size: size)
elsif height
img = image_tag(url, alt: file.title, width: 'auto', height: height)
elsif width
img = image_tag(url, alt: file.title, width: width, height: 'auto')
else
img = image_tag(url, alt: file.title, width: 'auto', height: 200)
end
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}"
end end
# dmsfw - link to a document's approval workflow status # dmsfw - link to a document's approval workflow status

View File

@ -224,6 +224,13 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
assert_equal "<p>#{link}</p>", text assert_equal "<p>#{link}</p>", text
end end
# {{dmsf_image(file_id file_id)}}
def test_macro_dmsf_image_multiple
text = textilizable("{{dmsf_image(#{@file7.id} #{@file7.id})}}")
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, size: nil)
assert_equal "<p>#{link}#{link}</p>", text
end
def test_macro_dmsf_image_size def test_macro_dmsf_image_size
size = '50%' size = '50%'
text = textilizable("{{dmsf_image(#{@file7.id}, size=#{size})}}") text = textilizable("{{dmsf_image(#{@file7.id}, size=#{size})}}")
@ -327,7 +334,18 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
assert_equal "<p>#{link}</p>", text assert_equal "<p>#{link}</p>", text
end end
def test_macro_dmsftn # {{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)
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
end
# {{dmsftn(file_id size=300)}}
def test_macro_dmsftn_size
url = view_dmsf_file_url(@file7) url = view_dmsf_file_url(@file7)
size = '300' size = '300'
text = textilizable("{{dmsftn(#{@file7.id}, size=#{size})}}") text = textilizable("{{dmsftn(#{@file7.id}, size=#{size})}}")