Commit e375376d3332e836a2a3b553d75a64b948954273
1 parent
b78f3b28
Exists in
staging
and in
41 other branches
[gallery block] display images from a gallery
The images are displayed like a slideshow with groups of images
Showing
10 changed files
with
367 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,41 @@ | @@ -0,0 +1,41 @@ | ||
| 1 | +class GalleryBlock < Block | ||
| 2 | + | ||
| 3 | + attr_accessible :gallery_id, :groups_of, :speed, :interval | ||
| 4 | + | ||
| 5 | + settings_items :gallery_id, :type => :integer | ||
| 6 | + settings_items :groups_of, :type => :integer, :default => 3 | ||
| 7 | + settings_items :speed, :type => :integer, :default => 1000 | ||
| 8 | + | ||
| 9 | + settings_items :interval, :type => 'integer', :default => 10 | ||
| 10 | + | ||
| 11 | + before_save do |block| | ||
| 12 | + block.groups_of = block.groups_of.to_i | ||
| 13 | + end | ||
| 14 | + | ||
| 15 | + def self.description | ||
| 16 | + _('Gallery block') | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + def gallery | ||
| 20 | + if self.owner.kind_of? Environment | ||
| 21 | + article = owner.articles.find_by_id(self.gallery_id) | ||
| 22 | + if article && article.gallery? | ||
| 23 | + article | ||
| 24 | + end | ||
| 25 | + else | ||
| 26 | + owner.image_galleries.find_by_id(self.gallery_id) | ||
| 27 | + end | ||
| 28 | + end | ||
| 29 | + | ||
| 30 | + def images | ||
| 31 | + gallery ? gallery.images : [] | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | + def content(args={}) | ||
| 35 | + block = self | ||
| 36 | + proc do | ||
| 37 | + render :file => 'gallery_block', :locals => { :block => block } | ||
| 38 | + end | ||
| 39 | + end | ||
| 40 | + | ||
| 41 | +end |
| @@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
| 1 | +class GalleryBlockPlugin < Noosfero::Plugin | ||
| 2 | + def self.plugin_name | ||
| 3 | + 'Gallery Block' | ||
| 4 | + end | ||
| 5 | + | ||
| 6 | + def self.plugin_description | ||
| 7 | + _('Includes a block to display images from a gallery.') | ||
| 8 | + end | ||
| 9 | + | ||
| 10 | + def self.extra_blocks | ||
| 11 | + { | ||
| 12 | + GalleryBlock => {:type => [Community, Environment]} | ||
| 13 | + } | ||
| 14 | + end | ||
| 15 | + | ||
| 16 | + def stylesheet? | ||
| 17 | + true | ||
| 18 | + end | ||
| 19 | + | ||
| 20 | +end |
| @@ -0,0 +1,72 @@ | @@ -0,0 +1,72 @@ | ||
| 1 | +# SOME DESCRIPTIVE TITLE. | ||
| 2 | +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||
| 3 | +# This file is distributed under the same license as the PACKAGE package. | ||
| 4 | +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
| 5 | +# | ||
| 6 | +#, fuzzy | ||
| 7 | +msgid "" | ||
| 8 | +msgstr "" | ||
| 9 | +"Project-Id-Version: 1.3~rc1-15-gae6cf26\n" | ||
| 10 | +"POT-Creation-Date: 2015-10-30 20:29-0000\n" | ||
| 11 | +"PO-Revision-Date: 2015-08-20 16:45-0000\n" | ||
| 12 | +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
| 13 | +"Language-Team: LANGUAGE <LL@li.org>\n" | ||
| 14 | +"Language: \n" | ||
| 15 | +"MIME-Version: 1.0\n" | ||
| 16 | +"Content-Type: text/plain; charset=UTF-8\n" | ||
| 17 | +"Content-Transfer-Encoding: 8bit\n" | ||
| 18 | +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" | ||
| 19 | + | ||
| 20 | +#: plugins/gallery_block/lib/gallery_block.rb:16 | ||
| 21 | +msgid "Gallery block" | ||
| 22 | +msgstr "" | ||
| 23 | + | ||
| 24 | +#: plugins/gallery_block/lib/gallery_block_plugin.rb:7 | ||
| 25 | +msgid "Includes a block to display images from a gallery." | ||
| 26 | +msgstr "" | ||
| 27 | + | ||
| 28 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:4 | ||
| 29 | +msgid "Fill in with the gallery ID:" | ||
| 30 | +msgstr "" | ||
| 31 | + | ||
| 32 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:6 | ||
| 33 | +msgid "Choose a gallery" | ||
| 34 | +msgstr "" | ||
| 35 | + | ||
| 36 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:7 | ||
| 37 | +msgid "%{gallery} (%{count} images)" | ||
| 38 | +msgstr "" | ||
| 39 | + | ||
| 40 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:11 | ||
| 41 | +msgid "Transition speed (in seconds)" | ||
| 42 | +msgstr "" | ||
| 43 | + | ||
| 44 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13 | ||
| 45 | +msgid "Image transition:" | ||
| 46 | +msgstr "" | ||
| 47 | + | ||
| 48 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13 | ||
| 49 | +msgid "No automatic transition" | ||
| 50 | +msgstr "" | ||
| 51 | + | ||
| 52 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13 | ||
| 53 | +msgid "Every 1 second" | ||
| 54 | +msgid_plural "Every %d seconds" | ||
| 55 | +msgstr[0] "" | ||
| 56 | +msgstr[1] "" | ||
| 57 | + | ||
| 58 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:15 | ||
| 59 | +msgid "In groups of" | ||
| 60 | +msgstr "" | ||
| 61 | + | ||
| 62 | +#: plugins/gallery_block/views/gallery_block.html.erb:4 | ||
| 63 | +msgid "Previous" | ||
| 64 | +msgstr "" | ||
| 65 | + | ||
| 66 | +#: plugins/gallery_block/views/gallery_block.html.erb:27 | ||
| 67 | +msgid "Next" | ||
| 68 | +msgstr "" | ||
| 69 | + | ||
| 70 | +#: plugins/gallery_block/views/gallery_block.html.erb:43 | ||
| 71 | +msgid "Please, edit this block and choose some gallery" | ||
| 72 | +msgstr "" |
| @@ -0,0 +1,72 @@ | @@ -0,0 +1,72 @@ | ||
| 1 | +# SOME DESCRIPTIVE TITLE. | ||
| 2 | +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||
| 3 | +# This file is distributed under the same license as the PACKAGE package. | ||
| 4 | +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
| 5 | +# | ||
| 6 | +#, fuzzy | ||
| 7 | +msgid "" | ||
| 8 | +msgstr "" | ||
| 9 | +"Project-Id-Version: 1.3~rc1-15-gae6cf26\n" | ||
| 10 | +"POT-Creation-Date: 2015-10-30 20:29-0000\n" | ||
| 11 | +"PO-Revision-Date: 2015-08-20 16:45-0000\n" | ||
| 12 | +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
| 13 | +"Language-Team: LANGUAGE <LL@li.org>\n" | ||
| 14 | +"Language: \n" | ||
| 15 | +"MIME-Version: 1.0\n" | ||
| 16 | +"Content-Type: text/plain; charset=UTF-8\n" | ||
| 17 | +"Content-Transfer-Encoding: 8bit\n" | ||
| 18 | +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" | ||
| 19 | + | ||
| 20 | +#: plugins/gallery_block/lib/gallery_block.rb:16 | ||
| 21 | +msgid "Gallery block" | ||
| 22 | +msgstr "Bloco de galeria" | ||
| 23 | + | ||
| 24 | +#: plugins/gallery_block/lib/gallery_block_plugin.rb:7 | ||
| 25 | +msgid "Includes a block to display images from a gallery." | ||
| 26 | +msgstr "Inclui um bloco para mostrar imagens de uma galeria." | ||
| 27 | + | ||
| 28 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:4 | ||
| 29 | +msgid "Fill in with the gallery ID:" | ||
| 30 | +msgstr "Preencha com o ID de uma galeria:" | ||
| 31 | + | ||
| 32 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:6 | ||
| 33 | +msgid "Choose a gallery" | ||
| 34 | +msgstr "Escolha uma galeria" | ||
| 35 | + | ||
| 36 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:7 | ||
| 37 | +msgid "%{gallery} (%{count} images)" | ||
| 38 | +msgstr "%{gallery} (%{count} imagens)" | ||
| 39 | + | ||
| 40 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:11 | ||
| 41 | +msgid "Transition speed (in seconds)" | ||
| 42 | +msgstr "Velocidade de transição (em segundos)" | ||
| 43 | + | ||
| 44 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13 | ||
| 45 | +msgid "Image transition:" | ||
| 46 | +msgstr "Transição de imagem:" | ||
| 47 | + | ||
| 48 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13 | ||
| 49 | +msgid "No automatic transition" | ||
| 50 | +msgstr "Sem transição automática" | ||
| 51 | + | ||
| 52 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:13 | ||
| 53 | +msgid "Every 1 second" | ||
| 54 | +msgid_plural "Every %d seconds" | ||
| 55 | +msgstr[0] "A cada segundo" | ||
| 56 | +msgstr[1] "A cada %d segundos" | ||
| 57 | + | ||
| 58 | +#: plugins/gallery_block/views/box_organizer/_gallery_block.html.erb:15 | ||
| 59 | +msgid "In groups of" | ||
| 60 | +msgstr "Em grupos de" | ||
| 61 | + | ||
| 62 | +#: plugins/gallery_block/views/gallery_block.html.erb:4 | ||
| 63 | +msgid "Previous" | ||
| 64 | +msgstr "Anterior" | ||
| 65 | + | ||
| 66 | +#: plugins/gallery_block/views/gallery_block.html.erb:27 | ||
| 67 | +msgid "Next" | ||
| 68 | +msgstr "Próximo" | ||
| 69 | + | ||
| 70 | +#: plugins/gallery_block/views/gallery_block.html.erb:43 | ||
| 71 | +msgid "Please, edit this block and choose some gallery" | ||
| 72 | +msgstr "Por favor, edite esse bloco e escolha alguma galeria" |
| @@ -0,0 +1,77 @@ | @@ -0,0 +1,77 @@ | ||
| 1 | +.gallery-items { | ||
| 2 | + width: 100%; | ||
| 3 | + display: table; | ||
| 4 | + margin: 0 auto; | ||
| 5 | + text-align: center; | ||
| 6 | +} | ||
| 7 | +.gallery-items ul { | ||
| 8 | + display: table-row; | ||
| 9 | +} | ||
| 10 | +.gallery-item { | ||
| 11 | + list-style-type: none; | ||
| 12 | + display: table-cell !important; | ||
| 13 | + vertical-align: middle; | ||
| 14 | +} | ||
| 15 | +.gallery-item div { | ||
| 16 | + margin: 0 auto; | ||
| 17 | +} | ||
| 18 | +.gallery-list { | ||
| 19 | + padding: 0; | ||
| 20 | + margin: 0px; | ||
| 21 | +} | ||
| 22 | +.gallery-block-arrow { | ||
| 23 | + float: left; | ||
| 24 | + width: 16px; | ||
| 25 | + background-repeat: no-repeat; | ||
| 26 | + height: 160px; | ||
| 27 | + background-position: center; | ||
| 28 | +} | ||
| 29 | +.gallery-block-arrow span { | ||
| 30 | + display: none; | ||
| 31 | +} | ||
| 32 | +.gallery-block-container { | ||
| 33 | + width: 82%; | ||
| 34 | +} | ||
| 35 | +.box-2 .gallery-block-container, .box-3 .gallery-block-container { | ||
| 36 | + width: 78%; | ||
| 37 | +} | ||
| 38 | +.gallery-group { | ||
| 39 | + width: 100%; | ||
| 40 | + margin: 0 auto; | ||
| 41 | + text-align: center; | ||
| 42 | +} | ||
| 43 | +.gallery-block-container, .gallery-group { | ||
| 44 | + overflow: hidden; | ||
| 45 | + float: left; | ||
| 46 | + height: 160px; | ||
| 47 | + position: relative; | ||
| 48 | + background-color: #FFF !important; | ||
| 49 | +} | ||
| 50 | +.gallery-group ul { | ||
| 51 | + padding: 0; | ||
| 52 | + padding-left: 4px; | ||
| 53 | +} | ||
| 54 | +.gallery-block-footer { | ||
| 55 | + clear: both; | ||
| 56 | +} | ||
| 57 | +.gallery-image-info { | ||
| 58 | + position: absolute; | ||
| 59 | + top: 0; | ||
| 60 | + z-index: 9999; | ||
| 61 | + height: 125px; | ||
| 62 | + overflow: hidden; | ||
| 63 | + font-size: 11px; | ||
| 64 | + background-color: #fff; | ||
| 65 | + opacity: 0.7; | ||
| 66 | + border: 1px solid #333; | ||
| 67 | + padding: 5px; | ||
| 68 | + text-align: left; | ||
| 69 | +} | ||
| 70 | +.box-2 .gallery-image-info, .box-3 .gallery-image-info { | ||
| 71 | + width: 110px; | ||
| 72 | + margin-left: 50%; | ||
| 73 | + left: -60px; | ||
| 74 | +} | ||
| 75 | +#content .gallery-image-info h3 { | ||
| 76 | + font-size: 11px; | ||
| 77 | +} |
| @@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
| 1 | +require 'test_helper' | ||
| 2 | + | ||
| 3 | +class GalleryBlockTest < ActiveSupport::TestCase | ||
| 4 | + | ||
| 5 | + def setup | ||
| 6 | + @community = fast_create(Community) | ||
| 7 | + end | ||
| 8 | + attr_reader :community | ||
| 9 | + | ||
| 10 | + should 'refer to a gallery' do | ||
| 11 | + gallery = fast_create(Gallery, :profile_id => community.id) | ||
| 12 | + gallery_block = create(GalleryBlock, :gallery_id => gallery.id) | ||
| 13 | + gallery_block.stubs(:owner).returns(community) | ||
| 14 | + assert_equal gallery, gallery_block.gallery | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + should 'default interval between transitions is 10 seconds' do | ||
| 18 | + block = GalleryBlock.new | ||
| 19 | + assert_equal 10, block.interval | ||
| 20 | + end | ||
| 21 | + | ||
| 22 | +end |
plugins/gallery_block/views/box_organizer/_gallery_block.html.erb
0 → 100644
| @@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
| 1 | +<div id="gallery_block_plugin"> | ||
| 2 | + | ||
| 3 | + <% if @block.owner.kind_of? Environment %> | ||
| 4 | + <%= labelled_form_field(_('Fill in with the gallery ID:'), text_field(:block, 'gallery_id')) %> | ||
| 5 | + <% else %> | ||
| 6 | + <%= labelled_form_field _('Choose a gallery'), select('block', 'gallery_id', @block.owner.image_galleries.map { |item| | ||
| 7 | + [ _('%{gallery} (%{count} images)') % {:gallery => item.path, :count => item.images.reject{|image| image.folder?}.count}, item.id ] | ||
| 8 | +}) %> | ||
| 9 | + <% end %> | ||
| 10 | + | ||
| 11 | + <%= labelled_form_field(_('Transition speed (in seconds)'), select('block', 'speed', (1..10).to_a.collect{|i| [i, i*1000] })) %> | ||
| 12 | + | ||
| 13 | + <%= 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]}) %> | ||
| 14 | + | ||
| 15 | + <%= labelled_form_field(_('In groups of'), select('block', 'groups_of', (1..10).to_a)) %> | ||
| 16 | + | ||
| 17 | +</div> |
| @@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
| 1 | +<%= block_title(block.title) %> | ||
| 2 | + | ||
| 3 | +<% unless block.images.blank? %> | ||
| 4 | + <%= link_to content_tag(:span, _('Previous')), '#', :class => 'gallery-block-prev gallery-block-arrow icon-left' %> | ||
| 5 | + <div class="gallery-block-container"> | ||
| 6 | + <ul class="gallery-list"> | ||
| 7 | + <% block.images.in_groups_of(block.groups_of).each do |group| %> | ||
| 8 | + <li class="gallery-group"> | ||
| 9 | + <div class="gallery-items"> | ||
| 10 | + <ul> | ||
| 11 | + <% group.reject{ |x| x.nil? }.each_with_index do |p, i| %> | ||
| 12 | + <li class="gallery-item"> | ||
| 13 | + <%= link_to image_tag(p.public_filename(:thumb), :alt => p.name, :title => p.name), p.view_url, :class => 'gallery-image' %> | ||
| 14 | + <div class="gallery-image-info position-<%= i + 1 %>" style="display: none"> | ||
| 15 | + <div class="gallery-image-text"> | ||
| 16 | + <h3><%= p.name %></h3> | ||
| 17 | + </div> | ||
| 18 | + </div> | ||
| 19 | + </li> | ||
| 20 | + <% end %> | ||
| 21 | + </ul> | ||
| 22 | + </div> | ||
| 23 | + </li> | ||
| 24 | + <% end %> | ||
| 25 | + </ul> | ||
| 26 | + </div> | ||
| 27 | + <%= link_to content_tag(:span, _('Next')), '#', :class => 'gallery-block-next gallery-block-arrow icon-right' %> | ||
| 28 | + <script type="text/javascript"> | ||
| 29 | + (function($) { | ||
| 30 | + var options = { | ||
| 31 | + fx : 'scrollHorz', | ||
| 32 | + timeout: 0, | ||
| 33 | + prev: '#block-<%= block.id %> .gallery-block-prev', | ||
| 34 | + next: '#block-<%= block.id %> .gallery-block-next', | ||
| 35 | + speed: 2000, | ||
| 36 | + timeout: <%= block.interval * 1000 %> | ||
| 37 | + } | ||
| 38 | + $('#block-<%= block.id %> .gallery-list').cycle(options); | ||
| 39 | + })(jQuery); | ||
| 40 | + </script> | ||
| 41 | + <p class="gallery-block-footer"></p> | ||
| 42 | +<% else %> | ||
| 43 | + <em><%= _('Please, edit this block and choose some gallery') %></em> | ||
| 44 | +<% end %> |