From af119b179323bb2daaba064b23880f59229c87b3 Mon Sep 17 00:00:00 2001 From: Pedro de Lyra Date: Tue, 16 Aug 2016 19:17:01 -0300 Subject: [PATCH] Add download button for images in gallery --- app/helpers/article_helper.rb | 4 +++- app/helpers/gallery_helper.rb | 13 +++++++++++++ app/models/gallery.rb | 3 +++ app/views/file_presenter/_image.html.erb | 5 ++++- public/stylesheets/zoomable-image.scss | 1 + test/functional/content_viewer_controller_test.rb | 16 ++++++++++++++++ 6 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 app/helpers/gallery_helper.rb diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index ff82b2a..1c4824f 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -60,7 +60,9 @@ module ArticleHelper 'div', check_box(:article, :display_versions) + content_tag('label', _('I want this article to display a link to older versions'), :for => 'article_display_versions') - ) : '') + ) : '') + + + (self.respond_to?(:extra_options) ? self.extra_options : "") ) end diff --git a/app/helpers/gallery_helper.rb b/app/helpers/gallery_helper.rb new file mode 100644 index 0000000..08573db --- /dev/null +++ b/app/helpers/gallery_helper.rb @@ -0,0 +1,13 @@ +module GalleryHelper + + include ArticleHelper + + def extra_options + content_tag( + 'div', + check_box(:article, :allow_download) + + content_tag('label', _('Allow images from this gallery to be downloaded'), :for => 'article_allow_download') + ) + end + +end diff --git a/app/models/gallery.rb b/app/models/gallery.rb index 2940182..7919ae8 100644 --- a/app/models/gallery.rb +++ b/app/models/gallery.rb @@ -1,5 +1,8 @@ class Gallery < Folder + settings_items :allow_download, :type => :boolean, :default => false + attr_accessible :allow_download + def self.type_name _('Gallery') end diff --git a/app/views/file_presenter/_image.html.erb b/app/views/file_presenter/_image.html.erb index 97fc352..2f07700 100644 --- a/app/views/file_presenter/_image.html.erb +++ b/app/views/file_presenter/_image.html.erb @@ -30,7 +30,10 @@ +<% if image.parent.is_a?(Gallery) && image.parent.allow_download %> + <%= link_to _('Download image'), [Noosfero.root, image.public_filename(:display)].join, download: image.filename, id: 'download-image-id', class: "button with-text icon-save" %> +<% end %> +
<%= image.abstract %>
- diff --git a/public/stylesheets/zoomable-image.scss b/public/stylesheets/zoomable-image.scss index b6a59f8..9a0ad30 100644 --- a/public/stylesheets/zoomable-image.scss +++ b/public/stylesheets/zoomable-image.scss @@ -3,6 +3,7 @@ position: relative; display: inline-block; max-width: 100%; + margin-bottom: 10px; } /* IE 8 hack to avoid max-width image bug */ .msie8 #content #article .article-body .zoomable-image img { diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 86e6ba3..de31957 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -604,6 +604,22 @@ class ContentViewerControllerTest < ActionController::TestCase assert_template 'view_page' end + should 'display download button to images in galleries that allow downloads' do + login_as(profile.identifier) + gallery = Gallery.create!(:name => 'gallery1', :profile => profile, :allow_download => true) + image = UploadedFile.create!(:profile => profile, :parent => gallery, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg')) + get :view_page, :profile => profile.identifier, :page => image.path, :view => true + assert_tag :tag => 'a', :content => 'Download image', :attributes => { :id => 'download-image-id' } + end + + should 'not display download button to images in galleries that do not allow downloads' do + login_as(profile.identifier) + gallery = Gallery.create!(:name => 'gallery1', :profile => profile, :allow_download => false) + image = UploadedFile.create!(:profile => profile, :parent => gallery, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg')) + get :view_page, :profile => profile.identifier, :page => image.path, :view => true + assert_no_tag :tag => 'a', :content => 'Download image', :attributes => { :id => 'download-image-id' } + end + should "display 'Upload files' when create children of image gallery" do login_as(profile.identifier) f = Gallery.create!(:name => 'gallery', :profile => profile) -- libgit2 0.21.2