Commit af119b179323bb2daaba064b23880f59229c87b3

Authored by Pedro de Lyra Pereira
Committed by Leandro Santos
1 parent 1217394d
Exists in staging

Add download button for images in gallery

Signed-off-by: Fagner Rodrigues <fagner128@gmail.com>
Signed-off-by: Gustavo Cavalcante <gustavo.cavalcante.oliveira@live.com>
Signed-off-by: Iago Rodrigues <iago006@hotmailcom>
Signed-off-by: Karine Valença <valenca.karine@gmail.com>
Signed-off-by: Murilo Duarte <muriloduartegoncalves@hotmail.com>
Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
app/helpers/article_helper.rb
... ... @@ -60,7 +60,9 @@ module ArticleHelper
60 60 'div',
61 61 check_box(:article, :display_versions) +
62 62 content_tag('label', _('I want this article to display a link to older versions'), :for => 'article_display_versions')
63   - ) : '')
  63 + ) : '') +
  64 +
  65 + (self.respond_to?(:extra_options) ? self.extra_options : "")
64 66 )
65 67 end
66 68  
... ...
app/helpers/gallery_helper.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +module GalleryHelper
  2 +
  3 + include ArticleHelper
  4 +
  5 + def extra_options
  6 + content_tag(
  7 + 'div',
  8 + check_box(:article, :allow_download) +
  9 + content_tag('label', _('Allow images from this gallery to be downloaded'), :for => 'article_allow_download')
  10 + )
  11 + end
  12 +
  13 +end
... ...
app/models/gallery.rb
1 1 class Gallery < Folder
2 2  
  3 + settings_items :allow_download, :type => :boolean, :default => false
  4 + attr_accessible :allow_download
  5 +
3 6 def self.type_name
4 7 _('Gallery')
5 8 end
... ...
app/views/file_presenter/_image.html.erb
... ... @@ -30,7 +30,10 @@
30 30  
31 31 <img src="<%= [Noosfero.root, image.public_filename(:display)].join %>" class="<%=image.css_class_name%>">
32 32  
  33 +<% if image.parent.is_a?(Gallery) && image.parent.allow_download %>
  34 + <%= link_to _('Download image'), [Noosfero.root, image.public_filename(:display)].join, download: image.filename, id: 'download-image-id', class: "button with-text icon-save" %>
  35 +<% end %>
  36 +
33 37 <div class="uploaded-file-description <%= 'empty' if image.abstract.blank? %>">
34 38 <%= image.abstract %>
35 39 </div>
36   -
... ...
public/stylesheets/zoomable-image.scss
... ... @@ -3,6 +3,7 @@
3 3 position: relative;
4 4 display: inline-block;
5 5 max-width: 100%;
  6 + margin-bottom: 10px;
6 7 }
7 8 /* IE 8 hack to avoid max-width image bug */
8 9 .msie8 #content #article .article-body .zoomable-image img {
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -604,6 +604,22 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
604 604 assert_template 'view_page'
605 605 end
606 606  
  607 + should 'display download button to images in galleries that allow downloads' do
  608 + login_as(profile.identifier)
  609 + gallery = Gallery.create!(:name => 'gallery1', :profile => profile, :allow_download => true)
  610 + image = UploadedFile.create!(:profile => profile, :parent => gallery, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'))
  611 + get :view_page, :profile => profile.identifier, :page => image.path, :view => true
  612 + assert_tag :tag => 'a', :content => 'Download image', :attributes => { :id => 'download-image-id' }
  613 + end
  614 +
  615 + should 'not display download button to images in galleries that do not allow downloads' do
  616 + login_as(profile.identifier)
  617 + gallery = Gallery.create!(:name => 'gallery1', :profile => profile, :allow_download => false)
  618 + image = UploadedFile.create!(:profile => profile, :parent => gallery, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'))
  619 + get :view_page, :profile => profile.identifier, :page => image.path, :view => true
  620 + assert_no_tag :tag => 'a', :content => 'Download image', :attributes => { :id => 'download-image-id' }
  621 + end
  622 +
607 623 should "display 'Upload files' when create children of image gallery" do
608 624 login_as(profile.identifier)
609 625 f = Gallery.create!(:name => 'gallery', :profile => profile)
... ...