diff --git a/.gitignore b/.gitignore index 721b1f830..c85a7cba5 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ gpg/diaspora-development/*.gpg gpg/diaspora-production/*.gpg gpg/*/random_seed public/uploads/* +public/public/* diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 4e033db98..deaa38deb 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -4,10 +4,10 @@ class PhotosController < ApplicationController def create @photo = Photo.new(params[:photo]) @photo.person = current_user - @photo.album = Album.first(:id => params[:photo][:album_id]) + #@photo.album = Album.first(:id => params[:photo][:album_id]) if @photo.save - @photo.album.save + #@photo.album.save flash[:notice] = "Successfully uploaded photo." redirect_to @photo.album else diff --git a/app/models/album.rb b/app/models/album.rb index 8738a9870..914da9837 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -9,4 +9,15 @@ class Album timestamps! validates_presence_of :name + + def prev_photo(photo) + n_photo = self.photos.where(:created_at.lt => photo.created_at).sort(:created_at.desc).first + n_photo ? n_photo : self.photos.sort(:created_at.desc).first + end + + def next_photo(photo) + p_photo = self.photos.where(:created_at.gt => photo.created_at).sort(:created_at.asc).first + p_photo ? p_photo : self.photos.sort(:created_at.desc).last + end + end diff --git a/app/models/photo.rb b/app/models/photo.rb index f0e8d62b8..59a72f4cd 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -4,5 +4,8 @@ class Photo < Post mount_uploader :image, ImageUploader key :album_id, ObjectId - one :album, :class_name => 'Album' + belongs_to :album, :class_name => 'Album' + timestamps! + + validates_presence_of :album end diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 2d9b1aa77..a1b9201a1 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -1,10 +1,10 @@ class ImageUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick - storage :grid_fs + storage :file def store_dir - "files/#{model.id}" + "public/uploads" end def extension_white_list diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index dddd8e7f1..8ee7948bf 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -1,5 +1,4 @@ %li.message{:id => post.id} - = person_image_tag(post.person) %span.from diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index b861e1fa2..f96369087 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -1,6 +1,12 @@ -- title "Photo" + +%h3= "viewing photos from album #{@album.name}" + #show_photo - = image_tag @photo.image.url + = link_to (image_tag @photo.image.url), photo_path(@album.next_photo(@photo)) + +#photo_pagination + = link_to "<< previous", photo_path(@album.prev_photo(@photo)) + = link_to "next >>", photo_path(@album.next_photo(@photo)) %h4= "comments (#{@photo.comments.count})" = render "comments/comments", :post => @photo @@ -8,4 +14,4 @@ %p = link_to "Destroy", @photo, :confirm => 'Are you sure?', :method => :delete | - = link_to "<< back to album", object_path(@album) + = link_to "<< back to album", album_path(@album) diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index 271f2334e..ea3c837d5 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -1,6 +1,7 @@ CarrierWave.configure do |config| - config.grid_fs_database = "#diaspora-#{Rails.env}" - config.grid_fs_host = 'localhost' - config.grid_fs_access_url = "/images" - config.storage = :grid_fs + #config.grid_fs_database = "#diaspora-#{Rails.env}" + #config.grid_fs_host = 'localhost' + #config.grid_fs_access_url = "/images" + #config.storage = :grid_fs + config.storage = :file end diff --git a/public/javascripts/view.js b/public/javascripts/view.js index ea84b25f3..7eddc731d 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -24,9 +24,11 @@ $(document).ready(function(){ }); $('a').hover(function(){ - $(this).fadeTo(60, 0.5); + if( $(this).children("img").length < 1 ) + $(this).fadeTo(60, 0.5); }, function(){ - $(this).fadeTo(80, 1); + if( $(this).children("img").length < 1 ) + $(this).fadeTo(80, 1); }); $('#debug_info').click(function() { diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index a8084559f..bd1de6ff0 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -164,14 +164,17 @@ form { #user_name a { color: black; } -div.comments { +#stream div.comments { display: none; } +#stream ul.comment_set { + padding: 0; + padding-left: 1em; } + ul.comment_set { margin: 0; margin-top: 1em; padding: 0; - padding-left: 1em; list-style: none; width: 90%; } ul.comment_set li.comment { @@ -328,7 +331,7 @@ ul#publisher_content_pickers li { margin-bottom: 2em; } .album .name { position: absolute; - z-index: 6; + z-index: 600; padding: 1em; background: rgba(0, 0, 0, 0.8); bottom: 20px; diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 87faf499c..947229982 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -192,14 +192,17 @@ form a :color #000 -div.comments +#stream div.comments :display none +#stream ul.comment_set + :padding 0 + :left 1em + ul.comment_set :margin 0 :top 1em :padding 0 - :left 1em :list-style none :width 90% @@ -393,7 +396,7 @@ ul#publisher_content_pickers li .name :position absolute - :z-index 6 + :z-index 600 :padding 1em :background rgba(0,0,0,0.8) :bottom 20px diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 068ba4ab6..cb5ac690f 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -24,14 +24,41 @@ describe Album do it 'should contain photos' do album = Album.create(:name => "test collection") - - photo =Photo.new(:person => @user) - + photo = Photo.new(:person => @user) album.photos << photo album.photos.count.should == 1 end + describe 'traversing' do + before do + @album = Album.create(:name => "test collection") + @photo_one = Photo.create(:person => @user, :created_at => Time.now) + @photo_two = Photo.create(:person => @user, :created_at => Time.now-1) + @photo_three = Photo.create(:person => @user, :created_at => Time.now-2) + + @album.photos += [@photo_one, @photo_two, @photo_three] + end + + it 'should retrieve the next photo relative to a given photo' do + @album.next_photo(@photo_two).id.should == @photo_three.id + end + + it 'should retrieve the previous photo relative to a given photo' do + @album.prev_photo(@photo_two).id.should == @photo_one.id + end + + describe 'wrapping' do + it 'does next photo of last to first' do + @album.next_photo(@photo_three).id.should == @photo_one.id + end + + it 'does previous photo of first to last' do + @album.prev_photo(@photo_one).id.should == @photo_three.id + end + end + end + end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index feb320cbd..c5ab80c75 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -5,7 +5,7 @@ describe Photo do @user = Factory.create(:user) @fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg' @fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml' - @photo = Photo.new(:person => @user) + @photo = Photo.new(:person => @user, :album => Album.create(:name => "foo")) end it 'should save a @photo to GridFS' do file = File.open(@fixture_name) @@ -31,6 +31,13 @@ describe Photo do @photo.image = file @photo.save.should == false end + + + it 'must have an album' do + photo = Photo.create(:person => @user) + photo.valid?.should be false + Photo.first.album.name.should == 'foo' + end end describe 'with encryption' do