DG MS added basic album traversal
This commit is contained in:
parent
cb67a7fa1b
commit
695a93ddad
13 changed files with 88 additions and 25 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -11,3 +11,4 @@ gpg/diaspora-development/*.gpg
|
||||||
gpg/diaspora-production/*.gpg
|
gpg/diaspora-production/*.gpg
|
||||||
gpg/*/random_seed
|
gpg/*/random_seed
|
||||||
public/uploads/*
|
public/uploads/*
|
||||||
|
public/public/*
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ class PhotosController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@photo = Photo.new(params[:photo])
|
@photo = Photo.new(params[:photo])
|
||||||
@photo.person = current_user
|
@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
|
if @photo.save
|
||||||
@photo.album.save
|
#@photo.album.save
|
||||||
flash[:notice] = "Successfully uploaded photo."
|
flash[:notice] = "Successfully uploaded photo."
|
||||||
redirect_to @photo.album
|
redirect_to @photo.album
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,15 @@ class Album
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
validates_presence_of :name
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,8 @@ class Photo < Post
|
||||||
mount_uploader :image, ImageUploader
|
mount_uploader :image, ImageUploader
|
||||||
|
|
||||||
key :album_id, ObjectId
|
key :album_id, ObjectId
|
||||||
one :album, :class_name => 'Album'
|
belongs_to :album, :class_name => 'Album'
|
||||||
|
timestamps!
|
||||||
|
|
||||||
|
validates_presence_of :album
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
class ImageUploader < CarrierWave::Uploader::Base
|
class ImageUploader < CarrierWave::Uploader::Base
|
||||||
include CarrierWave::MiniMagick
|
include CarrierWave::MiniMagick
|
||||||
|
|
||||||
storage :grid_fs
|
storage :file
|
||||||
|
|
||||||
def store_dir
|
def store_dir
|
||||||
"files/#{model.id}"
|
"public/uploads"
|
||||||
end
|
end
|
||||||
|
|
||||||
def extension_white_list
|
def extension_white_list
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
%li.message{:id => post.id}
|
%li.message{:id => post.id}
|
||||||
|
|
||||||
= person_image_tag(post.person)
|
= person_image_tag(post.person)
|
||||||
|
|
||||||
%span.from
|
%span.from
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
- title "Photo"
|
|
||||||
|
%h3= "viewing photos from album #{@album.name}"
|
||||||
|
|
||||||
#show_photo
|
#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})"
|
%h4= "comments (#{@photo.comments.count})"
|
||||||
= render "comments/comments", :post => @photo
|
= render "comments/comments", :post => @photo
|
||||||
|
|
@ -8,4 +14,4 @@
|
||||||
%p
|
%p
|
||||||
= link_to "Destroy", @photo, :confirm => 'Are you sure?', :method => :delete
|
= 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)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
CarrierWave.configure do |config|
|
CarrierWave.configure do |config|
|
||||||
config.grid_fs_database = "#diaspora-#{Rails.env}"
|
#config.grid_fs_database = "#diaspora-#{Rails.env}"
|
||||||
config.grid_fs_host = 'localhost'
|
#config.grid_fs_host = 'localhost'
|
||||||
config.grid_fs_access_url = "/images"
|
#config.grid_fs_access_url = "/images"
|
||||||
config.storage = :grid_fs
|
#config.storage = :grid_fs
|
||||||
|
config.storage = :file
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,10 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
$('a').hover(function(){
|
$('a').hover(function(){
|
||||||
|
if( $(this).children("img").length < 1 )
|
||||||
$(this).fadeTo(60, 0.5);
|
$(this).fadeTo(60, 0.5);
|
||||||
}, function(){
|
}, function(){
|
||||||
|
if( $(this).children("img").length < 1 )
|
||||||
$(this).fadeTo(80, 1);
|
$(this).fadeTo(80, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,14 +164,17 @@ form {
|
||||||
#user_name a {
|
#user_name a {
|
||||||
color: black; }
|
color: black; }
|
||||||
|
|
||||||
div.comments {
|
#stream div.comments {
|
||||||
display: none; }
|
display: none; }
|
||||||
|
|
||||||
|
#stream ul.comment_set {
|
||||||
|
padding: 0;
|
||||||
|
padding-left: 1em; }
|
||||||
|
|
||||||
ul.comment_set {
|
ul.comment_set {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
padding-left: 1em;
|
|
||||||
list-style: none;
|
list-style: none;
|
||||||
width: 90%; }
|
width: 90%; }
|
||||||
ul.comment_set li.comment {
|
ul.comment_set li.comment {
|
||||||
|
|
@ -328,7 +331,7 @@ ul#publisher_content_pickers li {
|
||||||
margin-bottom: 2em; }
|
margin-bottom: 2em; }
|
||||||
.album .name {
|
.album .name {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 6;
|
z-index: 600;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
background: rgba(0, 0, 0, 0.8);
|
background: rgba(0, 0, 0, 0.8);
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
|
|
|
||||||
|
|
@ -192,14 +192,17 @@ form
|
||||||
a
|
a
|
||||||
:color #000
|
:color #000
|
||||||
|
|
||||||
div.comments
|
#stream div.comments
|
||||||
:display none
|
:display none
|
||||||
|
|
||||||
|
#stream ul.comment_set
|
||||||
|
:padding 0
|
||||||
|
:left 1em
|
||||||
|
|
||||||
ul.comment_set
|
ul.comment_set
|
||||||
:margin 0
|
:margin 0
|
||||||
:top 1em
|
:top 1em
|
||||||
:padding 0
|
:padding 0
|
||||||
:left 1em
|
|
||||||
:list-style none
|
:list-style none
|
||||||
:width 90%
|
:width 90%
|
||||||
|
|
||||||
|
|
@ -393,7 +396,7 @@ ul#publisher_content_pickers li
|
||||||
|
|
||||||
.name
|
.name
|
||||||
:position absolute
|
:position absolute
|
||||||
:z-index 6
|
:z-index 600
|
||||||
:padding 1em
|
:padding 1em
|
||||||
:background rgba(0,0,0,0.8)
|
:background rgba(0,0,0,0.8)
|
||||||
:bottom 20px
|
:bottom 20px
|
||||||
|
|
|
||||||
|
|
@ -24,14 +24,41 @@ describe Album do
|
||||||
|
|
||||||
it 'should contain photos' do
|
it 'should contain photos' do
|
||||||
album = Album.create(:name => "test collection")
|
album = Album.create(:name => "test collection")
|
||||||
|
photo = Photo.new(:person => @user)
|
||||||
photo =Photo.new(:person => @user)
|
|
||||||
|
|
||||||
|
|
||||||
album.photos << photo
|
album.photos << photo
|
||||||
album.photos.count.should == 1
|
album.photos.count.should == 1
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ describe Photo do
|
||||||
@user = Factory.create(:user)
|
@user = Factory.create(:user)
|
||||||
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
|
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
|
||||||
@fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml'
|
@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
|
end
|
||||||
it 'should save a @photo to GridFS' do
|
it 'should save a @photo to GridFS' do
|
||||||
file = File.open(@fixture_name)
|
file = File.open(@fixture_name)
|
||||||
|
|
@ -31,6 +31,13 @@ describe Photo do
|
||||||
@photo.image = file
|
@photo.image = file
|
||||||
@photo.save.should == false
|
@photo.save.should == false
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe 'with encryption' do
|
describe 'with encryption' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue