From 2162a2e3f9cc738d19b093f08d93c9ffde145b9c Mon Sep 17 00:00:00 2001 From: maxwell <maxwell@joindiaspora.com> Date: Mon, 8 Nov 2010 15:55:58 -0800 Subject: [PATCH] collapse person's photos and status message into their profile; also, made these nested on a person --- app/controllers/people_controller.rb | 8 +++-- app/controllers/photos_controller.rb | 32 +++++++++++++------ app/controllers/status_messages_controller.rb | 27 ++++++++++++++++ ...idebar.haml => _profile_sidebar.html.haml} | 0 app/views/people/show.html.haml | 7 ++-- app/views/photos/_index.html.haml | 23 +++++++++++++ app/views/photos/index.html.haml | 27 ---------------- app/views/shared/_author_info.html.haml | 2 +- app/views/status_messages/index.html.haml | 13 -------- config/routes.rb | 8 ++++- spec/controllers/photos_controller_spec.rb | 17 +++++----- 11 files changed, 99 insertions(+), 65 deletions(-) rename app/views/people/{_profile_sidebar.haml => _profile_sidebar.html.haml} (100%) create mode 100644 app/views/photos/_index.html.haml delete mode 100644 app/views/photos/index.html.haml delete mode 100644 app/views/status_messages/index.html.haml diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 4e31975a62..996ead2ff5 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -15,10 +15,10 @@ class PeopleController < ApplicationController end def show - @aspect = :profile @person = Person.find(params[:id].to_id) - + @post_type = :all + if @person @profile = @person.profile @contact = current_user.contact_for(@person) @@ -31,7 +31,9 @@ class PeopleController < ApplicationController end @posts = current_user.visible_posts(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' - respond_with @person + respond_with @person, :locals => {:post_type => :all} + + else flash[:error] = I18n.t 'people.show.does_not_exist' redirect_to people_path diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 8a71518cfa..780f17b5b0 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -9,16 +9,28 @@ class PhotosController < ApplicationController respond_to :json, :only => :show def index - if params[:person_id] - @person = current_user.contact_for_person_id(params[:person_id]) - @person = @person.person if @person + @aspect = :profile + @post_type = :photos + @person = Person.find(params[:person_id].to_id) + + if @person + @profile = @person.profile + @contact = current_user.contact_for(@person) + @is_contact = @person != current_user.person && @contact + + if @contact + @aspects_with_person = @contact.aspects + else + @pending_request = current_user.pending_requests.find_by_person_id(@person.id) + end + + @posts = current_user.visible_posts(:_type => 'Photo', :person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' + render 'people/show' + else - @person = current_user.person + flash[:error] = I18n.t 'people.show.does_not_exist' + redirect_to people_path end - - @photos = current_user.visible_posts(:_type => "Photo", :person_id => @person.id) - - @aspect = :photos end def create @@ -85,7 +97,7 @@ class PhotosController < ApplicationController if @photo = current_user.my_posts.where(:_id => params[:id]).first respond_with @photo else - redirect_to photos_path + redirect_to person_photos_path(current_user.person) end end @@ -100,7 +112,7 @@ class PhotosController < ApplicationController redirect_to [:edit, photo] end else - redirect_to photos_path + redirect_to person_photos_path(current_user.person) end end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 475a68784a..3f7911162a 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -21,6 +21,33 @@ class StatusMessagesController < ApplicationController render :nothing => true end + + def index + @aspect = :profile + @post_type = :status_message + + @person = Person.find(params[:person_id].to_id) + + if @person + @profile = @person.profile + @contact = current_user.contact_for(@person) + @is_contact = @person != current_user.person && @contact + + if @contact + @aspects_with_person = @contact.aspects + else + @pending_request = current_user.pending_requests.find_by_person_id(@person.id) + end + + @posts = current_user.visible_posts(:_type => 'StatusMessage', :person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' + render 'people/show' + + else + flash[:error] = I18n.t 'people.show.does_not_exist' + redirect_to people_path + end + end + def destroy @status_message = current_user.my_posts.where(:_id => params[:id]).first if @status_message diff --git a/app/views/people/_profile_sidebar.haml b/app/views/people/_profile_sidebar.html.haml similarity index 100% rename from app/views/people/_profile_sidebar.haml rename to app/views/people/_profile_sidebar.html.haml diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index e95948abab..b0b53ae18c 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -4,14 +4,17 @@ .span-4.append-1.last - = render 'profile_sidebar', :person => @person, :is_contact => @is_contact + = render :partial => 'people/profile_sidebar', :locals => {:person => @person, :is_contact => @is_contact} .span-15.last = render 'shared/author_info', :person => @person - if @contact || current_user.person == @person - if @posts.count > 0 - = render 'shared/stream', :posts => @posts + -if @post_type == :photos + = render 'photos/index', :photos => @posts + - else + = render 'shared/stream', :posts => @posts = will_paginate @posts - else diff --git a/app/views/photos/_index.html.haml b/app/views/photos/_index.html.haml new file mode 100644 index 0000000000..fc53d91f7f --- /dev/null +++ b/app/views/photos/_index.html.haml @@ -0,0 +1,23 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + +=content_for(:head) do + :javascript + $(document).ready(function(){ + $(".image_thumb img").load( function() { + $(this).fadeIn("slow"); + }); + }); + +.span-24.last + #thumbnails + - for photo in photos + .image_thumb + = link_to (image_tag photo.url(:thumb_medium)), photo_path(photo) + +/.span-24.last +/ #add_photo_pane +/ = render "photos/new_photo", :aspect_id => :all + diff --git a/app/views/photos/index.html.haml b/app/views/photos/index.html.haml deleted file mode 100644 index dc9fb9a9ac..0000000000 --- a/app/views/photos/index.html.haml +++ /dev/null @@ -1,27 +0,0 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -:javascript - $(document).ready(function(){ - $(".image_thumb img").load( function() { - $(this).fadeIn("slow"); - }); - }); - - -.span-24.last{:style=>"position:relative;"} - = render 'shared/author_info', :person => @person - %ul#breadcrumb - %li= link_to "#{@person.profile.first_name}'s Photos", person_photos_path(@person) - -.span-24.last - #thumbnails - - for photo in @photos - .image_thumb - = link_to (image_tag photo.url(:thumb_medium)), photo_path(photo) - -.span-24.last - #add_photo_pane - = render "photos/new_photo", :aspect_id => :all - diff --git a/app/views/shared/_author_info.html.haml b/app/views/shared/_author_info.html.haml index 39f91c89d0..fa63ede455 100644 --- a/app/views/shared/_author_info.html.haml +++ b/app/views/shared/_author_info.html.haml @@ -15,4 +15,4 @@ #person_nav_links = link_to t('.view_profile'), person_path(person) = link_to t('_photos'), person_photos_path(person) - = link_to 'status messages', person_photos_path(person) + = link_to 'status messages', person_status_messages_path(person) diff --git a/app/views/status_messages/index.html.haml b/app/views/status_messages/index.html.haml deleted file mode 100644 index 9bbd93abfc..0000000000 --- a/app/views/status_messages/index.html.haml +++ /dev/null @@ -1,13 +0,0 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -%h1.big_text status messages -= render "status_messages/new_status_message", :status_message => @status_message -%ul#stream - - - for status_message in @status_messages - = render "status_message", :post => status_message -#pagination - = will_paginate @status_messages - diff --git a/config/routes.rb b/config/routes.rb index 05461014a2..4b637aa90c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,9 +7,15 @@ Diaspora::Application.routes.draw do resources :status_messages, :only => [:create, :destroy, :show] resources :comments, :except => [:index] resources :requests, :except => [:edit, :update] - resources :photos + resources :photos, :except => [:index] resources :services + resources :people do + resources :status_messages + resources :photos + end + + match '/auth/:provider/callback' => 'services#create' devise_for :users, :controllers => {:registrations => "registrations", diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 02440e8ab0..8d310f8261 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -36,21 +36,21 @@ describe PhotosController do describe '#index' do it 'defaults to returning all of users pictures' do - get :index + get :index, :person_id => user.person.id.to_s assigns[:person].should == user.person - assigns[:photos].should == [photo] + assigns[:posts].should == [photo] end it 'sets the person to a friend if person_id is set' do get :index, :person_id => user2.person.id.to_s assigns[:person].should == user2.person - assigns[:photos].should == [] + assigns[:posts].should == [] end - it 'sets the aspect to photos?' do - get :index - assigns[:aspect].should == :photos + it 'sets the aspect to profile' do + get :index, :person_id => user.person.id.to_s + assigns[:aspect].should == :profile end end @@ -73,7 +73,7 @@ describe PhotosController do it 'should not let you edit a photo that is not yours' do get :edit, :id => photo2.id - response.should redirect_to(:action => :index) + response.should redirect_to(:action => :index, :person_id => user.person.id.to_s) end end @@ -106,7 +106,8 @@ describe PhotosController do it 'should redirect if you do not have access to the post' do params = { :caption => "now with lasers!"} put :update, :id => photo2.id, :photo => params - response.should redirect_to(:action => :index) + response.should redirect_to(:action => :index, :person_id => user.person.id.to_s) + end end end -- GitLab