Commit 71190c41e60f62b244e91deebb3a1d13e9b7852d
1 parent
13e2837d
Exists in
master
and in
29 other branches
Efficiently listing image galleries
(ActionItem1666)
Showing
9 changed files
with
61 additions
and
4 deletions
Show diff stats
app/models/environment.rb
... | ... | @@ -653,5 +653,9 @@ class Environment < ActiveRecord::Base |
653 | 653 | settings_items :general_cache_in_minutes, :type => :integer, :default => 15 |
654 | 654 | settings_items :profile_cache_in_minutes, :type => :integer, :default => 15 |
655 | 655 | |
656 | + def image_galleries | |
657 | + portal_community ? portal_community.image_galleries : [] | |
658 | + end | |
659 | + | |
656 | 660 | end |
657 | 661 | ... | ... |
app/models/highlights_block.rb
app/models/slideshow_block.rb
app/views/box_organizer/_highlights_block.rhtml
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <% for image in @block.images do %> |
6 | 6 | <tr> |
7 | 7 | <td> |
8 | - <%= select_tag 'block[images][][image_id]', content_tag(:option) + option_groups_from_collection_for_select(@block.box.owner.articles.select{|article| article.folder? && article.display_as_gallery? } , :images, :name, :id, :name, image[:image_id].to_i), :style => "width: 100px" %></p> | |
8 | + <%= select_tag 'block[images][][image_id]', content_tag(:option) + option_groups_from_collection_for_select(@block.folder_choices, :images, :name, :id, :name, image[:image_id].to_i), :style => "width: 100px" %></p> | |
9 | 9 | </td> |
10 | 10 | <td><%= text_field_tag 'block[images][][address]', image[:address], :class => 'highlight-address', :size => 10 %></td> |
11 | 11 | <td><%= text_field_tag 'block[images][][position]', image[:position], :class => 'highlight-position', :size => 3 %></td> |
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | |
18 | 18 | <%= link_to_function(_('New highlight'), nil, :class => 'button icon-add with-text') do |page| |
19 | 19 | page.insert_html :bottom, 'highlights', content_tag('tr', |
20 | - content_tag('td', select_tag('block[images][][image_id]', content_tag(:option) + option_groups_from_collection_for_select(@block.box.owner.articles.select{|article| article.folder? && article.display_as_gallery? } , :images, :name, :id, :name), :style => "width: 100px")) + | |
20 | + content_tag('td', select_tag('block[images][][image_id]', content_tag(:option) + option_groups_from_collection_for_select(@block.folder_choices, :images, :name, :id, :name), :style => "width: 100px")) + | |
21 | 21 | content_tag('td', text_field_tag('block[images][][address]', nil, :class => 'highlight-address', :size => 10)) + |
22 | 22 | content_tag('td', text_field_tag('block[images][][position]', nil, :class => 'highlight-position', :size => 3)) + |
23 | 23 | content_tag('td', text_field_tag('block[images][][title]', nil, :class => 'highlight-position', :size => 10)) | ... | ... |
app/views/box_organizer/_slideshow_block.rhtml
1 | -<% galleries = @block.box.owner.articles.select {|article| article.folder? && article.display_as_gallery? } %> | |
2 | -<%= labelled_form_field _('Choose a gallery'), select('block', 'gallery_id', galleries.map { |item| | |
1 | +<%= labelled_form_field _('Choose a gallery'), select('block', 'gallery_id', @block.folder_choices.map { |item| | |
3 | 2 | [ _('%{gallery} (%{count} images)') % {:gallery => item.path, :count => item.images.reject{|image| image.folder?}.count}, item.id ] |
4 | 3 | }) %> |
5 | 4 | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -1093,4 +1093,21 @@ class EnvironmentTest < Test::Unit::TestCase |
1093 | 1093 | |
1094 | 1094 | assert_equal ['trusted.site.org'], Environment.default.trusted_sites_for_iframe |
1095 | 1095 | end |
1096 | + | |
1097 | + should 'provide list of galleries' do | |
1098 | + env = Environment.new | |
1099 | + portal = Community.new | |
1100 | + env.stubs(:portal_community).returns(portal) | |
1101 | + list = [] | |
1102 | + portal.expects(:image_galleries).returns(list) | |
1103 | + | |
1104 | + assert_same list, env.image_galleries | |
1105 | + end | |
1106 | + | |
1107 | + should 'profile empty list of image galleries when there is no portal community' do | |
1108 | + p = Environment.new | |
1109 | + p.stubs(:portal_community).returns(nil) | |
1110 | + assert_equal [], p.image_galleries | |
1111 | + end | |
1112 | + | |
1096 | 1113 | end | ... | ... |
test/unit/highlights_block_test.rb
... | ... | @@ -129,4 +129,15 @@ class HighlightsBlockTest < ActiveSupport::TestCase |
129 | 129 | assert_not_equal [i2,i3,i1,i4,i5], block.featured_images |
130 | 130 | end |
131 | 131 | |
132 | + [Environment, Profile].each do |klass| | |
133 | + should "choose between owner galleries when owner is #{klass.name}" do | |
134 | + owner = fast_create(klass) | |
135 | + | |
136 | + block = HighlightsBlock.new | |
137 | + block.stubs(:owner).returns(owner) | |
138 | + | |
139 | + assert_kind_of Array, block.folder_choices | |
140 | + end | |
141 | + end | |
142 | + | |
132 | 143 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -1785,6 +1785,14 @@ class ProfileTest < Test::Unit::TestCase |
1785 | 1785 | assert_equal "3 members", c.more_popular_label |
1786 | 1786 | end |
1787 | 1787 | |
1788 | + should 'provide list of galleries' do | |
1789 | + p = fast_create(Profile) | |
1790 | + f1 = Folder.create(:profile => p, :name => "folder1", :view_as => 'image_gallery') | |
1791 | + f2 = Folder.create(:profile => p, :name => "folder2", :view_as => 'folder') | |
1792 | + | |
1793 | + assert_equal [f1], p.image_galleries | |
1794 | + end | |
1795 | + | |
1788 | 1796 | private |
1789 | 1797 | |
1790 | 1798 | def assert_invalid_identifier(id) | ... | ... |
test/unit/slideshow_block_test.rb
... | ... | @@ -97,4 +97,14 @@ class SlideshowBlockTest < ActiveSupport::TestCase |
97 | 97 | assert_equal '/bli/thumb.png', block.public_filename_for(image) |
98 | 98 | end |
99 | 99 | |
100 | + should 'choose between owner image galleries' do | |
101 | + block = SlideshowBlock.new | |
102 | + owner = mock | |
103 | + block.stubs(:owner).returns(owner) | |
104 | + | |
105 | + list = [] | |
106 | + owner.expects(:image_galleries).returns(list) | |
107 | + assert_same list, block.folder_choices | |
108 | + end | |
109 | + | |
100 | 110 | end | ... | ... |