DG MS added basic album traversal

This commit is contained in:
maxwell 2010-07-21 14:29:58 -07:00
parent cb67a7fa1b
commit 695a93ddad
13 changed files with 88 additions and 25 deletions

1
.gitignore vendored
View file

@ -11,3 +11,4 @@ gpg/diaspora-development/*.gpg
gpg/diaspora-production/*.gpg
gpg/*/random_seed
public/uploads/*
public/public/*

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,4 @@
%li.message{:id => post.id}
= person_image_tag(post.person)
%span.from

View file

@ -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)

View file

@ -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

View file

@ -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() {

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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