Commit 0a0c7af5245ffc8c2a632227d441868c1d32e981
Committed by
Antonio Terceiro
1 parent
1f9140cd
Exists in
master
and in
29 other branches
Navigation links to image gallery
(ActionItem1367)
Showing
8 changed files
with
135 additions
and
9 deletions
Show diff stats
app/models/uploaded_file.rb
@@ -46,14 +46,37 @@ class UploadedFile < Article | @@ -46,14 +46,37 @@ class UploadedFile < Article | ||
46 | File.read(self.full_filename) | 46 | File.read(self.full_filename) |
47 | end | 47 | end |
48 | 48 | ||
49 | - # FIXME isn't this too much including just to be able to generate some HTML? | ||
50 | - include ActionView::Helpers::TagHelper | ||
51 | 49 | ||
52 | def to_html(options = {}) | 50 | def to_html(options = {}) |
51 | + article = self | ||
53 | if image? | 52 | if image? |
54 | - tag('img', :src => public_filename(:display), :class => css_class_name, :style => 'max-width: 100%') | 53 | + lambda do |
54 | + if article.display_as_gallery? | ||
55 | + images = article.parent.images | ||
56 | + current_index = images.index(article) | ||
57 | + total_of_images = images.count | ||
58 | + | ||
59 | + link_to_previous = if current_index >= 1 | ||
60 | + link_to(_('« Previous'), images[current_index - 1].view_url, :class => 'left') | ||
61 | + else | ||
62 | + content_tag('span', _('« Previous'), :class => 'left') | ||
63 | + end | ||
64 | + | ||
65 | + link_to_next = if current_index < total_of_images - 1 | ||
66 | + link_to(_('Next »'), images[current_index + 1].view_url, :class => 'right') | ||
67 | + else | ||
68 | + content_tag('span', _('Next »'), :class => 'right') | ||
69 | + end | ||
70 | + | ||
71 | + content_tag( | ||
72 | + 'div', | ||
73 | + link_to_previous + content_tag('span', _('image %s of %d'), :class => 'total-of-images') % [current_index + 1, total_of_images] + link_to_next, | ||
74 | + :class => 'gallery-navigation' | ||
75 | + ) | ||
76 | + end.to_s + | ||
77 | + tag('img', :src => article.public_filename(:display), :class => article.css_class_name, :style => 'max-width: 100%') | ||
78 | + end | ||
55 | else | 79 | else |
56 | - article = self | ||
57 | lambda do | 80 | lambda do |
58 | content_tag('ul', content_tag('li', link_to(article.name, article.url, :class => article.css_class_name))) | 81 | content_tag('ul', content_tag('li', link_to(article.name, article.url, :class => article.css_class_name))) |
59 | end | 82 | end |
app/views/content_viewer/view_page.rhtml
@@ -72,7 +72,7 @@ | @@ -72,7 +72,7 @@ | ||
72 | 72 | ||
73 | <% if @page.parent && !@page.parent.path.blank? %> | 73 | <% if @page.parent && !@page.parent.path.blank? %> |
74 | <div id="article-parent"> | 74 | <div id="article-parent"> |
75 | - <%= link_to _('Go back'), @page.parent.url %> | 75 | + <%= button(:back, _('Go back to %s') % @page.parent.title, @page.parent.url) %> |
76 | </div> | 76 | </div> |
77 | <% end %> | 77 | <% end %> |
78 | 78 |
@@ -0,0 +1,65 @@ | @@ -0,0 +1,65 @@ | ||
1 | +Feature: gallery_navigation | ||
2 | + As a noosfero user | ||
3 | + I want to navigate over image gallery | ||
4 | + | ||
5 | + Background: | ||
6 | + Given the following users | ||
7 | + | login | | ||
8 | + | marciopunk | | ||
9 | + And the following folders | ||
10 | + | owner | name | view_as | | ||
11 | + | marciopunk | my-gallery | image_gallery | | ||
12 | + And the following files | ||
13 | + | owner | file | mime | parent | | ||
14 | + | marciopunk | rails.png | image/png | my-gallery | | ||
15 | + | marciopunk | other-pic.jpg | image/jpeg | my-gallery | | ||
16 | + | ||
17 | + Scenario: provide link to go to next image | ||
18 | + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true | ||
19 | + Then I should see "Next »" | ||
20 | + | ||
21 | + Scenario: view next image when follow next link | ||
22 | + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true | ||
23 | + When I follow "Next »" | ||
24 | + Then I should see "rails.png" within ".title" | ||
25 | + | ||
26 | + Scenario: not link to next when in last image | ||
27 | + When I am on /marciopunk/my-gallery/rails.png?view=true | ||
28 | + Then I should see "« Previous" within ".gallery-navigation a" | ||
29 | + And I should not see "Next »" within ".gallery-navigation a" | ||
30 | + | ||
31 | + Scenario: provide link to go to previous image | ||
32 | + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true | ||
33 | + Then I should see "« Previous" | ||
34 | + | ||
35 | + Scenario: view previous image when follow previous link | ||
36 | + Given I am on /marciopunk/my-gallery/rails.png?view=true | ||
37 | + When I follow "« Previous" | ||
38 | + Then I should see "other-pic.jpg" within ".title" | ||
39 | + | ||
40 | + Scenario: not link to previous when in first image | ||
41 | + When I am on /marciopunk/my-gallery/other-pic.jpg?view=true | ||
42 | + Then I should see "Next »" within ".gallery-navigation a" | ||
43 | + And I should not see "« Previous" within ".gallery-navigation a" | ||
44 | + | ||
45 | + Scenario: display number of current and total of images | ||
46 | + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true | ||
47 | + Then I should see "image 1 of 2" within ".gallery-navigation" | ||
48 | + | ||
49 | + Scenario: increment current number when follow next | ||
50 | + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true | ||
51 | + Then I should see "image 1 of 2" within ".gallery-navigation" | ||
52 | + When I follow "Next »" | ||
53 | + Then I should see "image 2 of 2" within ".gallery-navigation" | ||
54 | + | ||
55 | + Scenario: decrement current number when follow next | ||
56 | + Given I am on /marciopunk/my-gallery/rails.png?view=true | ||
57 | + Then I should see "image 2 of 2" within ".gallery-navigation" | ||
58 | + When I follow "« Previous" | ||
59 | + Then I should see "image 1 of 2" within ".gallery-navigation" | ||
60 | + | ||
61 | + Scenario: provide button to go back to gallery | ||
62 | + Given I am on /marciopunk/my-gallery/rails.png?view=true | ||
63 | + Then I should see "Go back to my-gallery" | ||
64 | + When I follow "Go back to my-gallery" | ||
65 | + Then I should be on /marciopunk/my-gallery |
features/step_definitions/noosfero_steps.rb
@@ -27,11 +27,12 @@ Given /^the following blocks$/ do |table| | @@ -27,11 +27,12 @@ Given /^the following blocks$/ do |table| | ||
27 | end | 27 | end |
28 | end | 28 | end |
29 | 29 | ||
30 | -Given /^the following (articles|events|blogs)$/ do |content, table| | 30 | +Given /^the following (articles|events|blogs|folders)$/ do |content, table| |
31 | klass = { | 31 | klass = { |
32 | 'articles' => TextileArticle, | 32 | 'articles' => TextileArticle, |
33 | 'events' => Event, | 33 | 'events' => Event, |
34 | 'blogs' => Blog, | 34 | 'blogs' => Blog, |
35 | + 'folders' => Folder, | ||
35 | }[content] || raise("Don't know how to build %s" % content) | 36 | }[content] || raise("Don't know how to build %s" % content) |
36 | table.hashes.map{|item| item.dup}.each do |item| | 37 | table.hashes.map{|item| item.dup}.each do |item| |
37 | owner_identifier = item.delete("owner") | 38 | owner_identifier = item.delete("owner") |
@@ -44,7 +45,11 @@ Given /^the following files$/ do |table| | @@ -44,7 +45,11 @@ Given /^the following files$/ do |table| | ||
44 | table.hashes.each do |item| | 45 | table.hashes.each do |item| |
45 | owner = Profile[item[:owner]] | 46 | owner = Profile[item[:owner]] |
46 | file = "/files/#{item[:file]}" | 47 | file = "/files/#{item[:file]}" |
47 | - article = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime])) | 48 | + article = UploadedFile.new(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime])) |
49 | + if item[:parent] | ||
50 | + article.parent = Article.find_by_slug(item[:parent]) | ||
51 | + end | ||
52 | + article.save! | ||
48 | if item[:homepage] | 53 | if item[:homepage] |
49 | owner.home_page = article | 54 | owner.home_page = article |
50 | owner.save! | 55 | owner.save! |
public/stylesheets/controller_content_viewer.css
@@ -50,3 +50,18 @@ div#article-parent { | @@ -50,3 +50,18 @@ div#article-parent { | ||
50 | .article-body-uploaded-file { | 50 | .article-body-uploaded-file { |
51 | text-align: center; | 51 | text-align: center; |
52 | } | 52 | } |
53 | + | ||
54 | +/************* uploaded file *****************/ | ||
55 | + | ||
56 | +#article .gallery-navigation { | ||
57 | + padding: 10px 0; | ||
58 | +} | ||
59 | +#article .gallery-navigation .left { | ||
60 | + margin-right: 10px; | ||
61 | +} | ||
62 | +#article .gallery-navigation .right { | ||
63 | + margin-left: 10px; | ||
64 | +} | ||
65 | +#article .gallery-navigation .total-of-images { | ||
66 | + font-weight: bold; | ||
67 | +} |
test/factories.rb
@@ -237,6 +237,15 @@ module Noosfero::Factory | @@ -237,6 +237,15 @@ module Noosfero::Factory | ||
237 | end | 237 | end |
238 | 238 | ||
239 | ############################################### | 239 | ############################################### |
240 | + # UploadedFile | ||
241 | + ############################################### | ||
242 | + | ||
243 | + def defaults_for_uploaded_file | ||
244 | + name = 'My uploaded file ' + factory_num_seq.to_s | ||
245 | + { :name => name, :abstract => name } | ||
246 | + end | ||
247 | + | ||
248 | + ############################################### | ||
240 | # Blog | 249 | # Blog |
241 | ############################################### | 250 | ############################################### |
242 | def create_blog | 251 | def create_blog |
2.43 KB
test/unit/blog_helper_test.rb
@@ -70,11 +70,15 @@ class BlogHelperTest < Test::Unit::TestCase | @@ -70,11 +70,15 @@ class BlogHelperTest < Test::Unit::TestCase | ||
70 | 70 | ||
71 | self.stubs(:params).returns({:npage => nil}) | 71 | self.stubs(:params).returns({:npage => nil}) |
72 | 72 | ||
73 | + display_filename = file.public_filename(:display) | ||
74 | + | ||
73 | result = display_post(file) | 75 | result = display_post(file) |
74 | - assert_tag_in_string result, :content => 'rails.png' | ||
75 | - assert_tag_in_string result, :tag => 'img', :attributes => { :src => /#{file.public_filename(:display)}/ } | 76 | + assert_match /rails.png/, result |
77 | + assert_tag_in_string result, :tag => 'img', :attributes => { :src => /#{display_filename}/ } | ||
76 | end | 78 | end |
77 | 79 | ||
80 | + protected | ||
81 | + | ||
78 | def will_paginate(arg1, arg2) | 82 | def will_paginate(arg1, arg2) |
79 | end | 83 | end |
80 | 84 | ||
@@ -82,6 +86,11 @@ class BlogHelperTest < Test::Unit::TestCase | @@ -82,6 +86,11 @@ class BlogHelperTest < Test::Unit::TestCase | ||
82 | content | 86 | content |
83 | end | 87 | end |
84 | 88 | ||
89 | + def tag(tag, args = {}) | ||
90 | + attrs = args.map{|k,v| "#{k}='#{v}'"}.join(' ') | ||
91 | + "<#{tag} #{attrs} />" | ||
92 | + end | ||
93 | + | ||
85 | def content_tag(tag, content, options = {}) | 94 | def content_tag(tag, content, options = {}) |
86 | "<#{tag}>#{content}</#{tag}>" | 95 | "<#{tag}>#{content}</#{tag}>" |
87 | end | 96 | end |