DG MS added basic album support

This commit is contained in:
maxwell 2010-07-20 21:28:24 -07:00
parent f07740454a
commit 301343ae01
20 changed files with 145 additions and 84 deletions

View file

@ -0,0 +1,36 @@
class AlbumsController < ApplicationController
before_filter :authenticate_user!
def index
@albums = Album.paginate :page => params[:page], :order => 'created_at DESC'
end
def create
@album = Album.new(params[:album])
@album.person = current_user
if @album.save
flash[:notice] = "Successfully created album."
redirect_to @album
else
render :action => 'new'
end
end
def new
@album = Album.new
end
def destroy
@album = Album.first(:id => params[:id])
@album.destroy
flash[:notice] = "Successfully destroyed album."
redirect_to albums_url
end
def show
@photo = Photo.new
@album = Album.first(:id => params[:id])
@album_photos = @album.photos
end
end

View file

@ -1,18 +1,17 @@
class PhotosController < ApplicationController
before_filter :authenticate_user!
def index
@photos = Photo.paginate :page => params[:page], :order => 'created_at DESC'
end
def create
@photo = Photo.new(params[:photo])
@photo.person = current_user
@photo.album = Album.first(:id => params[:photo][:album_id])
if @photo.save
@photo.album.save
flash[:notice] = "Successfully uploaded photo."
redirect_to photos_url
redirect_to @photo.album
else
render :action => 'new'
render :action => 'album#new'
end
end
@ -29,5 +28,6 @@ class PhotosController < ApplicationController
def show
@photo = Photo.where(:id => params[:id]).first
@album = @photo.album
end
end

View file

@ -1,11 +1,12 @@
class Collection
class Album
include MongoMapper::Document
key :name, String
belongs_to :person, :class_name => 'Person'
#many :photos, :class_name => 'Photo', :foreign_key => :collection_id
many :photos, :class_name => 'Photo', :foreign_key => :album_id
timestamps!
validates_presence_of :name
end

View file

@ -16,7 +16,7 @@ class Person
one :profile, :class_name => 'Profile'
many :posts, :class_name => 'Post', :foreign_key => :person_id
many :collections, :class_name => 'Collection', :foreign_key => :person_id
many :albums, :class_name => 'Album', :foreign_key => :person_id
timestamps!

View file

@ -2,4 +2,7 @@ class Photo < Post
require 'carrierwave/orm/mongomapper'
include MongoMapper::Document
mount_uploader :image, ImageUploader
key :album_id, ObjectId
one :album, :class_name => 'Album'
end

View file

@ -0,0 +1,11 @@
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
%h3= link_to post.name, object_path(post)
=link_to (image_tag post.photos.first.image.url(:thumb_medium)), object_path(post)
%div.time
= link_to(how_long_ago(post), object_path(post))
- if mine?(post)
.destroy_link
= link_to 'Delete', object_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true

View file

@ -0,0 +1,5 @@
= form_for Album.new, :remote => true do |f|
= f.error_messages
%p
= f.text_field :name, :value => "tell me something good"
= f.submit 'oh yeah!', :class => 'button'

View file

@ -0,0 +1,11 @@
%h1.big_text albums
%h3
= link_to "make a new album", new_album_path
%ul#stream
- for album in @albums
= render "album", :post => album
#pagination
= will_paginate @albums

View file

@ -0,0 +1,9 @@
= form_for @album do |f|
= f.error_messages
%p
= f.label :name
= f.text_field :name
%p
= f.submit
%p= link_to "Back to List", albums_path

View file

@ -0,0 +1,9 @@
%h3= @album.name
= render "photos/new_photo", :photo => @photo, :album => @album
- for photo in @album_photos
= link_to (image_tag photo.image.url(:thumb_medium)), object_path(photo)
%p
= link_to "Destroy", @album, :confirm => 'Are you sure?', :method => :delete
|
= link_to "View All", albums_path

View file

@ -1,5 +1,8 @@
= form_for Photo.new, :html => {:multipart => true} do |f|
= form_for photo, :html => {:multipart => true} do |f|
= f.error_messages
= f.hidden_field :album_id, :value => album.id
%p
= f.file_field :image
= f.submit 'post it!', :class => 'button'

View file

@ -1,9 +0,0 @@
%h1.big_text photos
= render "photos/new_photo", :photo => @photo
%ul#stream
- for photo in @photos
= render "photo", :post => photo
#pagination
= will_paginate @photos

View file

@ -1,5 +1,4 @@
- title "Photo"
#show_photo
= image_tag @photo.image.url
@ -9,4 +8,4 @@
%p
= link_to "Destroy", @photo, :confirm => 'Are you sure?', :method => :delete
|
= link_to "View All", photos_path
= link_to "<< back to album", object_path(@album)

View file

@ -6,7 +6,6 @@
%li{ :class => "status_message" }= link_to "status message", "#"
%li{ :class => "bookmark" }= link_to "bookmark", "#"
%li{ :class => "blog" }= link_to "blog", "#"
%li{ :class => "photo" }= link_to "photo", "#"
#publisher_form
= form_for StatusMessage.new, :remote => true do |f|
@ -38,10 +37,3 @@
= f.text_area :body
%p
= f.submit "Post"
= form_for Photo.new, :html => {:multipart => true} do |f|
= f.error_messages
%p
= f.file_field :image
%p
= f.submit 'post it!', :class => 'button'

View file

@ -7,6 +7,7 @@ Diaspora::Application.routes.draw do |map|
resources :comments
resources :requests
resources :photos
resources :albums
match "/images/files/*path" => "gridfs#serve"

View file

@ -285,8 +285,7 @@ label {
#new_blog,
#new_bookmark,
#new_status_message,
#new_photo {
#new_status_message {
display: none; }
ul#publisher_content_pickers {

View file

@ -337,8 +337,7 @@ label
#new_blog,
#new_bookmark,
#new_status_message,
#new_photo
#new_status_message
:display none
ul#publisher_content_pickers

View file

@ -5,9 +5,9 @@ include RequestsHelper
describe RequestsHelper do
before do
@tom = Redfinger.finger('tom@tom.joindiaspora.com')
@evan = Redfinger.finger('evan@status.net')
@max = Redfinger.finger('mbs348@gmail.com')
#@tom = Redfinger.finger('tom@tom.joindiaspora.com')
#@evan = Redfinger.finger('evan@status.net')
#@max = Redfinger.finger('mbs348@gmail.com')
end
@ -24,17 +24,18 @@ describe RequestsHelper do
end
it 'should detect how to subscribe to a diaspora or ostatus webfinger profile' do
pending
subscription_mode(@tom).should == :friend
subscription_mode(@evan).should == :subscribe
subscription_mode(@max).should == :none
end
it 'should return the correct tag and url for a given address' do
pending
relationship_flow('tom@tom.joindiaspora.com')[:friend].should == 'http://tom.joindiaspora.com/'
relationship_flow('evan@status.net')[:subscribe].should == 'http://evan.status.net/api/statuses/user_timeline/1.atom'
end
end
end

37
spec/models/album_spec.rb Normal file
View file

@ -0,0 +1,37 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Album do
before do
@user = Factory.create(:user)
@album = Album.new(:name => "test collection")
end
it 'should belong to a person' do
person = Factory.create(:person)
@album.person = person
@album.valid?.should be true
@album.save
person.albums.count.should == 1
end
it 'should require a name' do
@album.name = "test collection"
@album.valid?.should be true
@album.name = nil
@album.valid?.should be false
end
it 'should contain photos' do
album = Album.create(:name => "test collection")
photo =Photo.new(:person => @user)
album.photos << photo
album.photos.count.should == 1
end
end

View file

@ -1,46 +0,0 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Collection do
before do
@user = Factory.create(:user)
@collection = Collection.new(:name => "test collection")
end
it 'should belong to a person' do
person = Factory.create(:person)
@collection.person = person
@collection.valid?.should be true
@collection.save
person.collections.count.should == 1
end
it 'should require a name' do
@collection.name = "test collection"
@collection.valid?.should be true
@collection.name = nil
@collection.valid?.should be false
end
it 'should contain photos' do
collection = Collection.create(:name => "test collection")
photo = Photo.create(:person => @user)
puts photo.valid?
puts collection.valid?
puts photo.inspect
puts collection.photos.inspect
puts 'asdojasd'
puts photo.collection
puts 'asdojasd'
collection.photos.count.should == 1
end
end