From 5f01cbb178a41bbdf816c6f5c4cf3f9618c495ee Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Tue, 16 Feb 2016 22:39:36 +0100 Subject: [PATCH 1/8] added auto scaling inline image functionality --- init.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/init.rb b/init.rb index 473db794..406f9581 100644 --- a/init.rb +++ b/init.rb @@ -181,7 +181,11 @@ Redmine::Plugin.register :redmine_dmsf do end raise 'Not supported image format' unless file.image? url = url_for(:controller => :dmsf_files, :action => 'view', :id => file) - image_tag(url, :alt => file.title, :size => size) + if size.include? "%" + image_tag(url, :alt => file.title, :width => size, :height => size) + else + image_tag(url, :alt => file.title, :size => size) + end else raise "Document ID #{file_id} not found" end From 164d62b1186c18db34b1cb0340d33ced30c09e83 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Tue, 16 Feb 2016 22:56:12 +0100 Subject: [PATCH 2/8] Update README.md Added macro description for proportional scale-down feature --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4afc77ba..6af69759 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,9 @@ Search will now automatically search DMSF content when a Redmine search is perfo ####An inline picture with custom size `{{dmsf_image(8, size=300)}}` +####An inline picture with custom size +`{{dmsf_image(8, size=50%)}}` + ####An inline picture with custom size `{{dmsf_image(8, size=640x480)}}` From 66459e37a661509aaff051f68377af671fef3a3b Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Wed, 17 Feb 2016 18:13:23 +0100 Subject: [PATCH 3/8] bugfix --- init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.rb b/init.rb index 406f9581..88ce4e8c 100644 --- a/init.rb +++ b/init.rb @@ -181,7 +181,7 @@ Redmine::Plugin.register :redmine_dmsf do end raise 'Not supported image format' unless file.image? url = url_for(:controller => :dmsf_files, :action => 'view', :id => file) - if size.include? "%" + if size and size.include? "%" image_tag(url, :alt => file.title, :width => size, :height => size) else image_tag(url, :alt => file.title, :size => size) From 6efe4756d8aeef3c93511149a2e3a58e541cbd30 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Thu, 18 Feb 2016 09:21:41 +0100 Subject: [PATCH 4/8] added feature to scale down inline images with respect to aspect ratio #508 --- init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.rb b/init.rb index 406f9581..e3e25e8e 100644 --- a/init.rb +++ b/init.rb @@ -181,7 +181,7 @@ Redmine::Plugin.register :redmine_dmsf do end raise 'Not supported image format' unless file.image? url = url_for(:controller => :dmsf_files, :action => 'view', :id => file) - if size.include? "%" + if size && size.include?('%') image_tag(url, :alt => file.title, :width => size, :height => size) else image_tag(url, :alt => file.title, :size => size) From 14738e43605d7b3e55dc12b3aa72ad868c50c16b Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Sun, 21 Feb 2016 01:10:40 +0100 Subject: [PATCH 5/8] added width attribute in order to resize by width with respect to aspect ratio size attribute now sets the height with respect to aspect ratio --- init.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/init.rb b/init.rb index 88ce4e8c..29b434c5 100644 --- a/init.rb +++ b/init.rb @@ -171,20 +171,29 @@ Redmine::Plugin.register :redmine_dmsf do "{{dmsf_image(file_id, size=300)}} -- with custom title and size\n" + "{{dmsf_image(file_id, size=640x480)}}" macro :dmsf_image do |obj, args| - args, options = extract_macro_options(args, :size, :title) + args, options = extract_macro_options(args, :size, :width, :title) file_id = args.first raise 'DMSF document ID required' unless file_id.present? - size = options[:size] + size = options[:size] + width = options[:width] 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 image format' unless file.image? url = url_for(:controller => :dmsf_files, :action => 'view', :id => file) - if size and size.include? "%" - image_tag(url, :alt => file.title, :width => size, :height => size) + if size + if size.include? "%" + image_tag(url, :alt => file.title, :width => size, :height => size) + elsif size.include? "x" + image_tag(url, :alt => file.title, :size => size) + else + image_tag(url, :alt => file.title, :width => 'auto', :height => size) + end + elsif width + image_tag(url, :alt => file.title, :width => width, :height => 'auto') else - image_tag(url, :alt => file.title, :size => size) + image_tag(url, :alt => file.title, :width => 'auto', :height => size) end else raise "Document ID #{file_id} not found" From 1d8223aa953cd26815523cea24d48fa9433b1735 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Sun, 21 Feb 2016 01:26:42 +0100 Subject: [PATCH 6/8] added additional height attribute and reverted to default behaviour of size attribute --- README.md | 6 ++++++ init.rb | 17 +++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6af69759..7c75a579 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,12 @@ Search will now automatically search DMSF content when a Redmine search is perfo ####An inline picture with custom size `{{dmsf_image(8, size=50%)}}` +####An inline picture with custom height +`{{dmsf_image(8, height=300)}}` + +####An inline picture with custom width +`{{dmsf_image(8, width=300)}}` + ####An inline picture with custom size `{{dmsf_image(8, size=640x480)}}` diff --git a/init.rb b/init.rb index 29b434c5..97eb72cd 100644 --- a/init.rb +++ b/init.rb @@ -171,29 +171,26 @@ Redmine::Plugin.register :redmine_dmsf do "{{dmsf_image(file_id, size=300)}} -- with custom title and size\n" + "{{dmsf_image(file_id, size=640x480)}}" macro :dmsf_image do |obj, args| - args, options = extract_macro_options(args, :size, :width, :title) + 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 image format' unless file.image? url = url_for(:controller => :dmsf_files, :action => 'view', :id => file) - if size - if size.include? "%" - image_tag(url, :alt => file.title, :width => size, :height => size) - elsif size.include? "x" - image_tag(url, :alt => file.title, :size => size) - else - image_tag(url, :alt => file.title, :width => 'auto', :height => size) - end + if size and size.include? "%" + image_tag(url, :alt => file.title, :width => size, :height => size) + elsif height + image_tag(url, :alt => file.title, :width => 'auto', :height => height) elsif width image_tag(url, :alt => file.title, :width => width, :height => 'auto') else - image_tag(url, :alt => file.title, :width => 'auto', :height => size) + image_tag(url, :alt => file.title, :size => size) end else raise "Document ID #{file_id} not found" From 26a9e8008f22f192ee8ee26d6b7bb2b8b233d9fb Mon Sep 17 00:00:00 2001 From: Redmine Administrator Date: Sun, 21 Feb 2016 02:23:08 +0100 Subject: [PATCH 7/8] added image thumbnail macro --- README.md | 7 +++++++ init.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/README.md b/README.md index 7c75a579..818c8ad9 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,13 @@ Search will now automatically search DMSF content when a Redmine search is perfo ####An inline picture with custom size `{{dmsf_image(8, size=640x480)}}` +####A thumbnail with height of 200px +`{{dmsftn(8)}}` + +####A thumbnail with custom size +`{{dmsftn(8, size=300)}}` + + The DMSF file/revision id can be found in link for file/revision download from within Redmine. ###Linking DMSF folders from Wiki entries: diff --git a/init.rb b/init.rb index 97eb72cd..fa03e571 100644 --- a/init.rb +++ b/init.rb @@ -169,6 +169,8 @@ Redmine::Plugin.register :redmine_dmsf do desc "Wiki DMSF image:\n\n" + "{{dmsf_image(file_id)}}\n" + "{{dmsf_image(file_id, size=300)}} -- with custom title and size\n" + + "{{dmsf_image(file_id, height=300)}} -- with custom title and height (auto width)\n" + + "{{dmsf_image(file_id, width=300)}} -- with custom title and width (auto height)\n" + "{{dmsf_image(file_id, size=640x480)}}" macro :dmsf_image do |obj, args| args, options = extract_macro_options(args, :size, :width, :height, :title) @@ -196,6 +198,48 @@ Redmine::Plugin.register :redmine_dmsf do raise "Document ID #{file_id} not found" end end + + + desc "Wiki DMSF thumbnail:\n\n" + + "{{dmsftn(file_id)}}\n" + + "{{dmsftn(file_id, size=300)}} -- with custom title and size\n" + + "{{dmsftn(file_id, height=300)}} -- with custom title and height (auto width)\n" + + "{{dmsftn(file_id, width=300)}} -- with custom title and width (auto height)\n" + + "{{dmsftn(file_id, size=640x480)}}" + macro :dmsftn 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 image format' unless file.image? + url = url_for(:controller => :dmsf_files, :action => 'view', :id => file) + file_view_url = url_for(:controller => :dmsf_files, :action => 'view', :id => file, :download => args[2]) + if size and size.include? "%" + img = image_tag(url, :alt => file.title, :width => size, :height => size) + elsif size and size.include? "x" + 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, + file_view_url, :target => '_blank', + :title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version), + 'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}") + else + raise "Document ID #{file_id} not found" + end + end + end # Rubyzip configuration From 808c017bcd0d9e2fe01fca36037aed0bcb79122a Mon Sep 17 00:00:00 2001 From: chris-ibcsf Date: Mon, 22 Feb 2016 22:46:37 +0100 Subject: [PATCH 8/8] style fixes --- init.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.rb b/init.rb index 393775a6..ad53563d 100644 --- a/init.rb +++ b/init.rb @@ -220,9 +220,9 @@ Redmine::Plugin.register :redmine_dmsf do raise 'Not supported image format' unless file.image? url = url_for(:controller => :dmsf_files, :action => 'view', :id => file) file_view_url = url_for(:controller => :dmsf_files, :action => 'view', :id => file, :download => args[2]) - if size and size.include? "%" + if size && size.include?("%") img = image_tag(url, :alt => file.title, :width => size, :height => size) - elsif size and size.include? "x" + elsif size && size.include?("x") img = image_tag(url, :alt => file.title, :size => size) elsif height img = image_tag(url, :alt => file.title, :width => 'auto', :height => height)