Skip to content
Extraits de code Groupes Projets
Valider 301343ae rédigé par maxwell's avatar maxwell
Parcourir les fichiers

DG MS added basic album support

parent f0774045
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 145 ajouts et 84 suppressions
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
class PhotosController < ApplicationController class PhotosController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
def index
@photos = Photo.paginate :page => params[:page], :order => 'created_at DESC'
end
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])
if @photo.save if @photo.save
@photo.album.save
flash[:notice] = "Successfully uploaded photo." flash[:notice] = "Successfully uploaded photo."
redirect_to photos_url redirect_to @photo.album
else else
render :action => 'new' render :action => 'album#new'
end end
end end
...@@ -29,5 +28,6 @@ class PhotosController < ApplicationController ...@@ -29,5 +28,6 @@ class PhotosController < ApplicationController
def show def show
@photo = Photo.where(:id => params[:id]).first @photo = Photo.where(:id => params[:id]).first
@album = @photo.album
end end
end end
class Collection class Album
include MongoMapper::Document include MongoMapper::Document
key :name, String key :name, String
belongs_to :person, :class_name => 'Person' belongs_to :person, :class_name => 'Person'
#many :photos, :class_name => 'Photo', :foreign_key => :collection_id many :photos, :class_name => 'Photo', :foreign_key => :album_id
validates_presence_of :name timestamps!
validates_presence_of :name
end end
...@@ -16,7 +16,7 @@ class Person ...@@ -16,7 +16,7 @@ class Person
one :profile, :class_name => 'Profile' one :profile, :class_name => 'Profile'
many :posts, :class_name => 'Post', :foreign_key => :person_id 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! timestamps!
......
...@@ -2,4 +2,7 @@ class Photo < Post ...@@ -2,4 +2,7 @@ class Photo < Post
require 'carrierwave/orm/mongomapper' require 'carrierwave/orm/mongomapper'
include MongoMapper::Document include MongoMapper::Document
mount_uploader :image, ImageUploader mount_uploader :image, ImageUploader
key :album_id, ObjectId
one :album, :class_name => 'Album'
end end
%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
= 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'
%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
= 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
%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
= form_for Photo.new, :html => {:multipart => true} do |f| = form_for photo, :html => {:multipart => true} do |f|
= f.error_messages = f.error_messages
= f.hidden_field :album_id, :value => album.id
%p %p
= f.file_field :image = f.file_field :image
= f.submit 'post it!', :class => 'button' = f.submit 'post it!', :class => 'button'
%h1.big_text photos
= render "photos/new_photo", :photo => @photo
%ul#stream
- for photo in @photos
= render "photo", :post => photo
#pagination
= will_paginate @photos
- title "Photo" - title "Photo"
#show_photo #show_photo
= image_tag @photo.image.url = image_tag @photo.image.url
...@@ -9,4 +8,4 @@ ...@@ -9,4 +8,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 "View All", photos_path = link_to "<< back to album", object_path(@album)
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
%li{ :class => "status_message" }= link_to "status message", "#" %li{ :class => "status_message" }= link_to "status message", "#"
%li{ :class => "bookmark" }= link_to "bookmark", "#" %li{ :class => "bookmark" }= link_to "bookmark", "#"
%li{ :class => "blog" }= link_to "blog", "#" %li{ :class => "blog" }= link_to "blog", "#"
%li{ :class => "photo" }= link_to "photo", "#"
#publisher_form #publisher_form
= form_for StatusMessage.new, :remote => true do |f| = form_for StatusMessage.new, :remote => true do |f|
...@@ -38,10 +37,3 @@ ...@@ -38,10 +37,3 @@
= f.text_area :body = f.text_area :body
%p %p
= f.submit "Post" = 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'
...@@ -7,6 +7,7 @@ Diaspora::Application.routes.draw do |map| ...@@ -7,6 +7,7 @@ Diaspora::Application.routes.draw do |map|
resources :comments resources :comments
resources :requests resources :requests
resources :photos resources :photos
resources :albums
match "/images/files/*path" => "gridfs#serve" match "/images/files/*path" => "gridfs#serve"
......
...@@ -285,8 +285,7 @@ label { ...@@ -285,8 +285,7 @@ label {
#new_blog, #new_blog,
#new_bookmark, #new_bookmark,
#new_status_message, #new_status_message {
#new_photo {
display: none; } display: none; }
ul#publisher_content_pickers { ul#publisher_content_pickers {
......
...@@ -337,8 +337,7 @@ label ...@@ -337,8 +337,7 @@ label
#new_blog, #new_blog,
#new_bookmark, #new_bookmark,
#new_status_message, #new_status_message
#new_photo
:display none :display none
ul#publisher_content_pickers ul#publisher_content_pickers
......
...@@ -5,9 +5,9 @@ include RequestsHelper ...@@ -5,9 +5,9 @@ include RequestsHelper
describe RequestsHelper do describe RequestsHelper do
before do before do
@tom = Redfinger.finger('tom@tom.joindiaspora.com') #@tom = Redfinger.finger('tom@tom.joindiaspora.com')
@evan = Redfinger.finger('evan@status.net') #@evan = Redfinger.finger('evan@status.net')
@max = Redfinger.finger('mbs348@gmail.com') #@max = Redfinger.finger('mbs348@gmail.com')
end end
...@@ -24,17 +24,18 @@ describe RequestsHelper do ...@@ -24,17 +24,18 @@ describe RequestsHelper do
end end
it 'should detect how to subscribe to a diaspora or ostatus webfinger profile' do it 'should detect how to subscribe to a diaspora or ostatus webfinger profile' do
pending
subscription_mode(@tom).should == :friend subscription_mode(@tom).should == :friend
subscription_mode(@evan).should == :subscribe subscription_mode(@evan).should == :subscribe
subscription_mode(@max).should == :none subscription_mode(@max).should == :none
end end
it 'should return the correct tag and url for a given address' do 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('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' relationship_flow('evan@status.net')[:subscribe].should == 'http://evan.status.net/api/statuses/user_timeline/1.atom'
end end
end end
end end
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
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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter