From 0a0c7af5245ffc8c2a632227d441868c1d32e981 Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Tue, 19 Jan 2010 11:17:12 -0300 Subject: [PATCH] Navigation links to image gallery --- app/models/uploaded_file.rb | 31 +++++++++++++++++++++++++++---- app/views/content_viewer/view_page.rhtml | 2 +- features/gallery_navigation.feature | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ features/step_definitions/noosfero_steps.rb | 9 +++++++-- public/stylesheets/controller_content_viewer.css | 15 +++++++++++++++ test/factories.rb | 9 +++++++++ test/fixtures/files/other-pic.jpg | Bin 0 -> 2485 bytes test/unit/blog_helper_test.rb | 13 +++++++++++-- 8 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 features/gallery_navigation.feature create mode 100644 test/fixtures/files/other-pic.jpg diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index 2799396..c10ef29 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -46,14 +46,37 @@ class UploadedFile < Article File.read(self.full_filename) end - # FIXME isn't this too much including just to be able to generate some HTML? - include ActionView::Helpers::TagHelper def to_html(options = {}) + article = self if image? - tag('img', :src => public_filename(:display), :class => css_class_name, :style => 'max-width: 100%') + lambda do + if article.display_as_gallery? + images = article.parent.images + current_index = images.index(article) + total_of_images = images.count + + link_to_previous = if current_index >= 1 + link_to(_('« Previous'), images[current_index - 1].view_url, :class => 'left') + else + content_tag('span', _('« Previous'), :class => 'left') + end + + link_to_next = if current_index < total_of_images - 1 + link_to(_('Next »'), images[current_index + 1].view_url, :class => 'right') + else + content_tag('span', _('Next »'), :class => 'right') + end + + content_tag( + 'div', + link_to_previous + content_tag('span', _('image %s of %d'), :class => 'total-of-images') % [current_index + 1, total_of_images] + link_to_next, + :class => 'gallery-navigation' + ) + end.to_s + + tag('img', :src => article.public_filename(:display), :class => article.css_class_name, :style => 'max-width: 100%') + end else - article = self lambda do content_tag('ul', content_tag('li', link_to(article.name, article.url, :class => article.css_class_name))) end diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index db82678..92fcd68 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -72,7 +72,7 @@ <% if @page.parent && !@page.parent.path.blank? %>
- <%= link_to _('Go back'), @page.parent.url %> + <%= button(:back, _('Go back to %s') % @page.parent.title, @page.parent.url) %>
<% end %> diff --git a/features/gallery_navigation.feature b/features/gallery_navigation.feature new file mode 100644 index 0000000..ae32851 --- /dev/null +++ b/features/gallery_navigation.feature @@ -0,0 +1,65 @@ +Feature: gallery_navigation + As a noosfero user + I want to navigate over image gallery + + Background: + Given the following users + | login | + | marciopunk | + And the following folders + | owner | name | view_as | + | marciopunk | my-gallery | image_gallery | + And the following files + | owner | file | mime | parent | + | marciopunk | rails.png | image/png | my-gallery | + | marciopunk | other-pic.jpg | image/jpeg | my-gallery | + + Scenario: provide link to go to next image + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true + Then I should see "Next »" + + Scenario: view next image when follow next link + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true + When I follow "Next »" + Then I should see "rails.png" within ".title" + + Scenario: not link to next when in last image + When I am on /marciopunk/my-gallery/rails.png?view=true + Then I should see "« Previous" within ".gallery-navigation a" + And I should not see "Next »" within ".gallery-navigation a" + + Scenario: provide link to go to previous image + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true + Then I should see "« Previous" + + Scenario: view previous image when follow previous link + Given I am on /marciopunk/my-gallery/rails.png?view=true + When I follow "« Previous" + Then I should see "other-pic.jpg" within ".title" + + Scenario: not link to previous when in first image + When I am on /marciopunk/my-gallery/other-pic.jpg?view=true + Then I should see "Next »" within ".gallery-navigation a" + And I should not see "« Previous" within ".gallery-navigation a" + + Scenario: display number of current and total of images + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true + Then I should see "image 1 of 2" within ".gallery-navigation" + + Scenario: increment current number when follow next + Given I am on /marciopunk/my-gallery/other-pic.jpg?view=true + Then I should see "image 1 of 2" within ".gallery-navigation" + When I follow "Next »" + Then I should see "image 2 of 2" within ".gallery-navigation" + + Scenario: decrement current number when follow next + Given I am on /marciopunk/my-gallery/rails.png?view=true + Then I should see "image 2 of 2" within ".gallery-navigation" + When I follow "« Previous" + Then I should see "image 1 of 2" within ".gallery-navigation" + + Scenario: provide button to go back to gallery + Given I am on /marciopunk/my-gallery/rails.png?view=true + Then I should see "Go back to my-gallery" + When I follow "Go back to my-gallery" + Then I should be on /marciopunk/my-gallery diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index e662020..9277931 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -27,11 +27,12 @@ Given /^the following blocks$/ do |table| end end -Given /^the following (articles|events|blogs)$/ do |content, table| +Given /^the following (articles|events|blogs|folders)$/ do |content, table| klass = { 'articles' => TextileArticle, 'events' => Event, 'blogs' => Blog, + 'folders' => Folder, }[content] || raise("Don't know how to build %s" % content) table.hashes.map{|item| item.dup}.each do |item| owner_identifier = item.delete("owner") @@ -44,7 +45,11 @@ Given /^the following files$/ do |table| table.hashes.each do |item| owner = Profile[item[:owner]] file = "/files/#{item[:file]}" - article = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime])) + article = UploadedFile.new(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime])) + if item[:parent] + article.parent = Article.find_by_slug(item[:parent]) + end + article.save! if item[:homepage] owner.home_page = article owner.save! diff --git a/public/stylesheets/controller_content_viewer.css b/public/stylesheets/controller_content_viewer.css index d7b0474..3567686 100644 --- a/public/stylesheets/controller_content_viewer.css +++ b/public/stylesheets/controller_content_viewer.css @@ -50,3 +50,18 @@ div#article-parent { .article-body-uploaded-file { text-align: center; } + +/************* uploaded file *****************/ + +#article .gallery-navigation { + padding: 10px 0; +} +#article .gallery-navigation .left { + margin-right: 10px; +} +#article .gallery-navigation .right { + margin-left: 10px; +} +#article .gallery-navigation .total-of-images { + font-weight: bold; +} diff --git a/test/factories.rb b/test/factories.rb index 1eb072f..fdfd7b6 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -237,6 +237,15 @@ module Noosfero::Factory end ############################################### + # UploadedFile + ############################################### + + def defaults_for_uploaded_file + name = 'My uploaded file ' + factory_num_seq.to_s + { :name => name, :abstract => name } + end + + ############################################### # Blog ############################################### def create_blog diff --git a/test/fixtures/files/other-pic.jpg b/test/fixtures/files/other-pic.jpg new file mode 100644 index 0000000..c2a94bc Binary files /dev/null and b/test/fixtures/files/other-pic.jpg differ diff --git a/test/unit/blog_helper_test.rb b/test/unit/blog_helper_test.rb index 1b23084..39a18c1 100644 --- a/test/unit/blog_helper_test.rb +++ b/test/unit/blog_helper_test.rb @@ -70,11 +70,15 @@ class BlogHelperTest < Test::Unit::TestCase self.stubs(:params).returns({:npage => nil}) + display_filename = file.public_filename(:display) + result = display_post(file) - assert_tag_in_string result, :content => 'rails.png' - assert_tag_in_string result, :tag => 'img', :attributes => { :src => /#{file.public_filename(:display)}/ } + assert_match /rails.png/, result + assert_tag_in_string result, :tag => 'img', :attributes => { :src => /#{display_filename}/ } end + protected + def will_paginate(arg1, arg2) end @@ -82,6 +86,11 @@ class BlogHelperTest < Test::Unit::TestCase content end + def tag(tag, args = {}) + attrs = args.map{|k,v| "#{k}='#{v}'"}.join(' ') + "<#{tag} #{attrs} />" + end + def content_tag(tag, content, options = {}) "<#{tag}>#{content}" end -- libgit2 0.21.2