Added photos, profile editing

This commit is contained in:
Raphael 2010-07-16 17:26:06 -07:00
parent 9165ac413a
commit fa46fb31f4
19 changed files with 112 additions and 13 deletions

1
.gitignore vendored
View file

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

View file

@ -31,7 +31,7 @@ gem 'em-websocket'
#File uploading
gem 'carrierwave', :git => 'git://github.com/rsofaer/carrierwave.git' , :branch => 'master' #Untested mongomapper branch
gem 'image_science'
gem 'mini_magick'
group :test do
gem 'rspec', '>= 2.0.0.beta.17'

2
README
View file

@ -1 +1 @@
broner
bronenate

View file

@ -0,0 +1,14 @@
class GridfsController < ActionController::Metal
def serve
gridfs_path = env["PATH_INFO"].gsub("/images/", "")
begin
gridfs_file = Mongo::GridFileSystem.new(MongoMapper.database).open(gridfs_path, 'r')
self.response_body = gridfs_file.read
self.content_type = gridfs_file.content_type
rescue
self.status = :file_not_found
self.content_type = 'text/plain'
self.response_body = "File totally imaginary #{gridfs_path}"
end
end
end

View file

@ -3,12 +3,10 @@ class PhotosController < ApplicationController
def index
@photos = Photo.paginate :page => params[:page], :order => 'created_at DESC'
end
def create
@photo = Photo.new(params[:photo])
@photo.person = current_user
if @photo.save
flash[:notice] = "Successfully uploaded photo."
@ -31,6 +29,5 @@ class PhotosController < ApplicationController
def show
@photo = Photo.where(:id => params[:id]).first
end
end

View file

@ -5,7 +5,22 @@ class UsersController < ApplicationController
@users = User.sort(:created_at.desc).all
end
def show
@user= Person.where(:id => params[:id]).first
@user= Person.first(:id => params[:id])
@user_profile = @user.profile
end
def edit
@user = User.first(:id => params[:id])
@profile = @user.profile
end
def update
@user = User.where(:id => params[:id]).first
if @user.update_attributes(params[:user])
flash[:notice] = "Successfully updated user."
redirect_to @user
else
render :action => 'edit'
end
end
end

View file

@ -4,7 +4,7 @@ class User < Person
:recoverable, :rememberable, :trackable, :validatable
before_validation :assign_key
before_validation_on_create :assign_key
validates_presence_of :profile
before_validation :do_bad_things

View file

@ -1,5 +1,5 @@
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::ImageScience
include CarrierWave::MiniMagick
storage :grid_fs

View file

@ -44,6 +44,9 @@
.span-24.last
.span-3.append-1.last
= link_to owner_picture, root_path
= link_to "Edit your profile", edit_user_path(current_user)
%br
%br
= render 'people/sidebar' if user_signed_in?
.span-20.last

View file

@ -1,4 +1,3 @@
%h3 your people
%ul#friend_stream.nav
- for friend in @friends
%li= link_to friend.real_name, person_path(friend)

View file

@ -0,0 +1,5 @@
= form_for Photo.new, :remote => true do |f|
= f.error_messages
%p
= f.file_field :image
= f.submit 'post it!', :class => 'button'

View file

@ -0,0 +1,3 @@
%li.message{:id => post.id}
= link_to (image_tag post.image.url(:small_thumb)), photo_path(post)

View file

@ -0,0 +1,9 @@
%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

@ -0,0 +1,9 @@
- title "New Photo"
= form_for( @photo, :html => {:multipart => true}) do |f|
= f.error_messages
%p
= f.file_field :image
= f.submit 'post it!', :class => 'button'
%p= link_to "Back to List", photos_path

View file

@ -0,0 +1,10 @@
- title "Photo"
%p
%strong Photo:
= image_tag @photo.image.url
%p
= link_to "Destroy", @photo, :confirm => 'Are you sure?', :method => :delete
|
= link_to "View All", photos_path

View file

@ -0,0 +1,25 @@
- title "Edit Profile"
= form_for @user do |f|
= f.error_messages
= f.fields_for :profile do |p|
%p
= p.label :first_name
= p.text_field :first_name, :value => @profile.first_name
%p
= p.label :last_name
= p.text_field :last_name, :value => @profile.last_name
%p
= f.label :email
= f.text_field :email
%p
= f.label :url
= f.text_field :url
%p
= f.submit
%p
= link_to "Show", user_path(@user)

View file

@ -1,6 +1,6 @@
CarrierWave.configure do |config|
config.grid_fs_database = "#diaspora-#{Rails.env}"
config.grid_fs_host = 'localhost'
config.grid_fs_access_url = "/GridFS"
config.grid_fs_access_url = "/images"
config.storage = :grid_fs
end

View file

@ -2,11 +2,14 @@ Diaspora::Application.routes.draw do |map|
resources :blogs
resources :bookmarks
resources :people
resources :users
resources :status_messages
resources :comments
resources :requests
resources :photos
match "/images/files/*path" => "gridfs#serve"
match 'warzombie', :to => "dashboards#warzombie"
match 'zombiefriends', :to => "dashboards#zombiefriends"
match 'zombiefriendaccept', :to => "dashboards#zombiefriendaccept"

View file

@ -1,13 +1,19 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Photo do
it 'should upload a photo to GridFS' do
it 'should save a photo to GridFS' do
photo = Photo.new
file = File.open('/spec/fixtures/bp.jpeg')
fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
file = File.open(fixture_name)
photo.image = file
photo.save.should == true
binary = photo.image.read
fixture_binary = File.open(fixture_name).read
binary.should == fixture_binary
end
it 'should create thumbnails' do
pending('need to figure this out... tearing issue')
end
end