Skip to content

Commit

Permalink
[gallery block] display images from a gallery
Browse files Browse the repository at this point in the history
The images are displayed like a slideshow with groups of images
  • Loading branch information
danielafeitosa committed Oct 30, 2015
1 parent b78f3b2 commit e375376
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 0 deletions.
41 changes: 41 additions & 0 deletions plugins/gallery_block/lib/gallery_block.rb
@@ -0,0 +1,41 @@
class GalleryBlock < Block

attr_accessible :gallery_id, :groups_of, :speed, :interval

settings_items :gallery_id, :type => :integer
settings_items :groups_of, :type => :integer, :default => 3
settings_items :speed, :type => :integer, :default => 1000

settings_items :interval, :type => 'integer', :default => 10

before_save do |block|
block.groups_of = block.groups_of.to_i
end

def self.description
_('Gallery block')
end

def gallery
if self.owner.kind_of? Environment
article = owner.articles.find_by_id(self.gallery_id)
if article && article.gallery?
article
end
else
owner.image_galleries.find_by_id(self.gallery_id)
end
end

def images
gallery ? gallery.images : []
end

def content(args={})
block = self
proc do
render :file => 'gallery_block', :locals => { :block => block }
end
end

end
20 changes: 20 additions & 0 deletions plugins/gallery_block/lib/gallery_block_plugin.rb
@@ -0,0 +1,20 @@
class GalleryBlockPlugin < Noosfero::Plugin
def self.plugin_name
'Gallery Block'
end

def self.plugin_description
_('Includes a block to display images from a gallery.')
end

def self.extra_blocks
{
GalleryBlock => {:type => [Community, Environment]}
}
end

def stylesheet?
true
end

end
72 changes: 72 additions & 0 deletions plugins/gallery_block/po/gallery_block.pot
@@ -0,0 +1,72 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: 1.3~rc1-15-gae6cf26\n"
"POT-Creation-Date: 2015-10-30 20:29-0000\n"
"PO-Revision-Date: 2015-08-20 16:45-0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: plugins/gallery_block/lib/gallery_block.rb:16
msgid "Gallery block"
msgstr ""

#: plugins/gallery_block/lib/gallery_block_plugin.rb:7
msgid "Includes a block to display images from a gallery."
msgstr ""

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:4
msgid "Fill in with the gallery ID:"
msgstr ""

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:6
msgid "Choose a gallery"
msgstr ""

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:7
msgid "%{gallery} (%{count} images)"
msgstr ""

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:11
msgid "Transition speed (in seconds)"
msgstr ""

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13
msgid "Image transition:"
msgstr ""

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13
msgid "No automatic transition"
msgstr ""

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13
msgid "Every 1 second"
msgid_plural "Every %d seconds"
msgstr[0] ""
msgstr[1] ""

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:15
msgid "In groups of"
msgstr ""

#: plugins/gallery_block/views/gallery_block.html.erb:4
msgid "Previous"
msgstr ""

#: plugins/gallery_block/views/gallery_block.html.erb:27
msgid "Next"
msgstr ""

#: plugins/gallery_block/views/gallery_block.html.erb:43
msgid "Please, edit this block and choose some gallery"
msgstr ""
72 changes: 72 additions & 0 deletions plugins/gallery_block/po/pt/gallery_block.po
@@ -0,0 +1,72 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: 1.3~rc1-15-gae6cf26\n"
"POT-Creation-Date: 2015-10-30 20:29-0000\n"
"PO-Revision-Date: 2015-08-20 16:45-0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: plugins/gallery_block/lib/gallery_block.rb:16
msgid "Gallery block"
msgstr "Bloco de galeria"

#: plugins/gallery_block/lib/gallery_block_plugin.rb:7
msgid "Includes a block to display images from a gallery."
msgstr "Inclui um bloco para mostrar imagens de uma galeria."

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:4
msgid "Fill in with the gallery ID:"
msgstr "Preencha com o ID de uma galeria:"

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:6
msgid "Choose a gallery"
msgstr "Escolha uma galeria"

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:7
msgid "%{gallery} (%{count} images)"
msgstr "%{gallery} (%{count} imagens)"

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:11
msgid "Transition speed (in seconds)"
msgstr "Velocidade de transição (em segundos)"

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13
msgid "Image transition:"
msgstr "Transição de imagem:"

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13
msgid "No automatic transition"
msgstr "Sem transição automática"

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13
msgid "Every 1 second"
msgid_plural "Every %d seconds"
msgstr[0] "A cada segundo"
msgstr[1] "A cada %d segundos"

#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:15
msgid "In groups of"
msgstr "Em grupos de"

#: plugins/gallery_block/views/gallery_block.html.erb:4
msgid "Previous"
msgstr "Anterior"

#: plugins/gallery_block/views/gallery_block.html.erb:27
msgid "Next"
msgstr "Próximo"

#: plugins/gallery_block/views/gallery_block.html.erb:43
msgid "Please, edit this block and choose some gallery"
msgstr "Por favor, edite esse bloco e escolha alguma galeria"
77 changes: 77 additions & 0 deletions plugins/gallery_block/public/style.css
@@ -0,0 +1,77 @@
.gallery-items {
width: 100%;
display: table;
margin: 0 auto;
text-align: center;
}
.gallery-items ul {
display: table-row;
}
.gallery-item {
list-style-type: none;
display: table-cell !important;
vertical-align: middle;
}
.gallery-item div {
margin: 0 auto;
}
.gallery-list {
padding: 0;
margin: 0px;
}
.gallery-block-arrow {
float: left;
width: 16px;
background-repeat: no-repeat;
height: 160px;
background-position: center;
}
.gallery-block-arrow span {
display: none;
}
.gallery-block-container {
width: 82%;
}
.box-2 .gallery-block-container, .box-3 .gallery-block-container {
width: 78%;
}
.gallery-group {
width: 100%;
margin: 0 auto;
text-align: center;
}
.gallery-block-container, .gallery-group {
overflow: hidden;
float: left;
height: 160px;
position: relative;
background-color: #FFF !important;
}
.gallery-group ul {
padding: 0;
padding-left: 4px;
}
.gallery-block-footer {
clear: both;
}
.gallery-image-info {
position: absolute;
top: 0;
z-index: 9999;
height: 125px;
overflow: hidden;
font-size: 11px;
background-color: #fff;
opacity: 0.7;
border: 1px solid #333;
padding: 5px;
text-align: left;
}
.box-2 .gallery-image-info, .box-3 .gallery-image-info {
width: 110px;
margin-left: 50%;
left: -60px;
}
#content .gallery-image-info h3 {
font-size: 11px;
}
22 changes: 22 additions & 0 deletions plugins/gallery_block/test/unit/gallery_block_test.rb
@@ -0,0 +1,22 @@
require 'test_helper'

class GalleryBlockTest < ActiveSupport::TestCase

def setup
@community = fast_create(Community)
end
attr_reader :community

should 'refer to a gallery' do
gallery = fast_create(Gallery, :profile_id => community.id)
gallery_block = create(GalleryBlock, :gallery_id => gallery.id)
gallery_block.stubs(:owner).returns(community)
assert_equal gallery, gallery_block.gallery
end

should 'default interval between transitions is 10 seconds' do
block = GalleryBlock.new
assert_equal 10, block.interval
end

end
17 changes: 17 additions & 0 deletions plugins/gallery_block/views/box_organizer/_gallery_block.html.erb
@@ -0,0 +1,17 @@
<div id="gallery_block_plugin">

<% if @block.owner.kind_of? Environment %>
<%= labelled_form_field(_('Fill in with the gallery ID:'), text_field(:block, 'gallery_id')) %>
<% else %>
<%= labelled_form_field _('Choose a gallery'), select('block', 'gallery_id', @block.owner.image_galleries.map { |item|
[ _('%{gallery} (%{count} images)') % {:gallery => item.path, :count => item.images.reject{|image| image.folder?}.count}, item.id ]
}) %>
<% end %>
<%= labelled_form_field(_('Transition speed (in seconds)'), select('block', 'speed', (1..10).to_a.collect{|i| [i, i*1000] })) %>
<%= labelled_form_field _('Image transition:'), select('block', 'interval', [[_('No automatic transition'), 0]] + [1, 2, 3, 4, 5, 10, 20, 30, 60].map {|item| [n_('Every 1 second', 'Every %d seconds', item) % item, item]}) %>
<%= labelled_form_field(_('In groups of'), select('block', 'groups_of', (1..10).to_a)) %>

</div>
1 change: 1 addition & 0 deletions plugins/gallery_block/views/environment_design
44 changes: 44 additions & 0 deletions plugins/gallery_block/views/gallery_block.html.erb
@@ -0,0 +1,44 @@
<%= block_title(block.title) %>
<% unless block.images.blank? %>
<%= link_to content_tag(:span, _('Previous')), '#', :class => 'gallery-block-prev gallery-block-arrow icon-left' %>
<div class="gallery-block-container">
<ul class="gallery-list">
<% block.images.in_groups_of(block.groups_of).each do |group| %>
<li class="gallery-group">
<div class="gallery-items">
<ul>
<% group.reject{ |x| x.nil? }.each_with_index do |p, i| %>
<li class="gallery-item">
<%= link_to image_tag(p.public_filename(:thumb), :alt => p.name, :title => p.name), p.view_url, :class => 'gallery-image' %>
<div class="gallery-image-info position-<%= i + 1 %>" style="display: none">
<div class="gallery-image-text">
<h3><%= p.name %></h3>
</div>
</div>
</li>
<% end %>
</ul>
</div>
</li>
<% end %>
</ul>
</div>
<%= link_to content_tag(:span, _('Next')), '#', :class => 'gallery-block-next gallery-block-arrow icon-right' %>
<script type="text/javascript">
(function($) {
var options = {
fx : 'scrollHorz',
timeout: 0,
prev: '#block-<%= block.id %> .gallery-block-prev',
next: '#block-<%= block.id %> .gallery-block-next',
speed: 2000,
timeout: <%= block.interval * 1000 %>
}
$('#block-<%= block.id %> .gallery-list').cycle(options);
})(jQuery);
</script>
<p class="gallery-block-footer"></p>
<% else %>
<em><%= _('Please, edit this block and choose some gallery') %></em>
<% end %>
1 change: 1 addition & 0 deletions plugins/gallery_block/views/profile_design

0 comments on commit e375376

Please sign in to comment.