[Git][noosfero/noosfero][master] Add download button for images in gallery
Leandro Nunes
gitlab at mg.gitlab.com
Fri Sep 2 10:05:19 BRT 2016
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
af119b17 by Pedro de Lyra at 2016-09-02T09:54:08-03:00
Add download button for images in gallery
Signed-off-by: Fagner Rodrigues <fagner128 at gmail.com>
Signed-off-by: Gustavo Cavalcante <gustavo.cavalcante.oliveira at live.com>
Signed-off-by: Iago Rodrigues <iago006 at hotmailcom>
Signed-off-by: Karine Valença <valenca.karine at gmail.com>
Signed-off-by: Murilo Duarte <muriloduartegoncalves at hotmail.com>
Signed-off-by: Pedro de Lyra <pedrodelyra at gmail.com>
- - - - -
6 changed files:
- app/helpers/article_helper.rb
- + app/helpers/gallery_helper.rb
- app/models/gallery.rb
- app/views/file_presenter/_image.html.erb
- public/stylesheets/zoomable-image.scss
- test/functional/content_viewer_controller_test.rb
Changes:
=====================================
app/helpers/article_helper.rb
=====================================
--- 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
=====================================
app/helpers/gallery_helper.rb
=====================================
--- /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
=====================================
app/models/gallery.rb
=====================================
--- 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
=====================================
app/views/file_presenter/_image.html.erb
=====================================
--- a/app/views/file_presenter/_image.html.erb
+++ b/app/views/file_presenter/_image.html.erb
@@ -30,7 +30,10 @@
<img src="<%= [Noosfero.root, image.public_filename(:display)].join %>" class="<%=image.css_class_name%>">
+<% 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 %>
+
<div class="uploaded-file-description <%= 'empty' if image.abstract.blank? %>">
<%= image.abstract %>
</div>
-
=====================================
public/stylesheets/zoomable-image.scss
=====================================
--- 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 {
=====================================
test/functional/content_viewer_controller_test.rb
=====================================
--- 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)
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/af119b179323bb2daaba064b23880f59229c87b3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160902/64943ec8/attachment-0001.html>
More information about the Noosfero-dev
mailing list