diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb new file mode 100644 index 000000000..716bcd002 --- /dev/null +++ b/app/controllers/albums_controller.rb @@ -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 diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index b7106959f..4e033db98 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -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 diff --git a/app/models/collection.rb b/app/models/album.rb similarity index 59% rename from app/models/collection.rb rename to app/models/album.rb index 6139d5765..8738a9870 100644 --- a/app/models/collection.rb +++ b/app/models/album.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index be06c0b26..3193c1866 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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! diff --git a/app/models/photo.rb b/app/models/photo.rb index 70e65cb64..f0e8d62b8 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -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 diff --git a/app/views/albums/_album.html.haml b/app/views/albums/_album.html.haml new file mode 100644 index 000000000..ad014fe45 --- /dev/null +++ b/app/views/albums/_album.html.haml @@ -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 diff --git a/app/views/albums/_new_album.haml b/app/views/albums/_new_album.haml new file mode 100644 index 000000000..3c94179cb --- /dev/null +++ b/app/views/albums/_new_album.haml @@ -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' diff --git a/app/views/albums/index.html.haml b/app/views/albums/index.html.haml new file mode 100644 index 000000000..47f11bd0b --- /dev/null +++ b/app/views/albums/index.html.haml @@ -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 + diff --git a/app/views/albums/new.html.haml b/app/views/albums/new.html.haml new file mode 100644 index 000000000..74c3b6175 --- /dev/null +++ b/app/views/albums/new.html.haml @@ -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 diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml new file mode 100644 index 000000000..2102044c4 --- /dev/null +++ b/app/views/albums/show.html.haml @@ -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 diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index 945679d5b..fd7e58b8a 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -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' diff --git a/app/views/photos/index.html.haml b/app/views/photos/index.html.haml deleted file mode 100644 index 04abb3bd2..000000000 --- a/app/views/photos/index.html.haml +++ /dev/null @@ -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 - diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 780fef673..b861e1fa2 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -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) diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index ccb15f9a7..724ad3413 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -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' diff --git a/config/routes.rb b/config/routes.rb index b211cc7b2..2496e257b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ Diaspora::Application.routes.draw do |map| resources :comments resources :requests resources :photos + resources :albums match "/images/files/*path" => "gridfs#serve" diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index e7037c671..a22c283b6 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -285,8 +285,7 @@ label { #new_blog, #new_bookmark, -#new_status_message, -#new_photo { +#new_status_message { display: none; } ul#publisher_content_pickers { diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 1d9d85fa2..3b4b833a7 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -337,8 +337,7 @@ label #new_blog, #new_bookmark, -#new_status_message, -#new_photo +#new_status_message :display none ul#publisher_content_pickers diff --git a/spec/helpers/requests_helper_spec.rb b/spec/helpers/requests_helper_spec.rb index dd8341217..248f5876d 100644 --- a/spec/helpers/requests_helper_spec.rb +++ b/spec/helpers/requests_helper_spec.rb @@ -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 diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb new file mode 100644 index 000000000..068ba4ab6 --- /dev/null +++ b/spec/models/album_spec.rb @@ -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 diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb deleted file mode 100644 index fd80f2d7b..000000000 --- a/spec/models/collection_spec.rb +++ /dev/null @@ -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