From 3b727dc8874f775259f04a82207ae61fa0a24e3e Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 15 Dec 2010 17:45:12 -0800 Subject: [PATCH 1/2] Add share_with fancybox on search page, fix a couple of queries --- app/controllers/aspects_controller.rb | 4 +- app/controllers/people_controller.rb | 16 ++++++ app/models/profile.rb | 2 +- app/views/people/_aspect_list.haml | 23 +++------ app/views/people/_person.html.haml | 25 +++++---- app/views/people/index.html.haml | 5 +- app/views/shared/_stream_element.html.haml | 14 ++--- config/assets.yml | 2 + config/routes.rb | 4 ++ public/javascripts/view.js | 59 +++++++++++----------- public/stylesheets/sass/application.sass | 41 +++++++++++---- spec/controllers/people_controller_spec.rb | 13 ++++- 12 files changed, 130 insertions(+), 78 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 9f4ace667..cdb1d80ef 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -11,7 +11,7 @@ class AspectsController < ApplicationController def index @posts = current_user.visible_posts(:_type => "StatusMessage").paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' @post_hashes = hashes_for_posts @posts - @contacts = current_user.contacts(:pending => false) + @contacts = Contact.all(:user_id => current_user.id, :pending => false) @aspect_hashes = hashes_for_aspects @aspects.all, @contacts, :limit => 8 @aspect = :all @@ -62,7 +62,7 @@ class AspectsController < ApplicationController unless @aspect render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else - @aspect_contacts = hashes_for_contacts @aspect.contacts(:pending => false) + @aspect_contacts = hashes_for_contacts Contact.all(:user_id => current_user.id, :aspect_ids.in => [@aspect.id], :pending => false) @aspect_contacts_count = @aspect_contacts.count @posts = @aspect.posts.find_all_by__type("StatusMessage", :order => 'created_at desc').paginate :page => params[:page], :per_page => 15 diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 5fae95ea4..78d0f2662 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -113,6 +113,22 @@ class PeopleController < ApplicationController end end + def share_with + @person = Person.find(params[:id].to_id) + @contact = current_user.contact_for(@person) + @aspects_with_person = [] + + if @contact + @aspects_with_person = @contact.aspects + end + + @aspects_without_person = @aspects.reject do |aspect| + @aspects_with_person.include?(aspect) + end + + render :layout => nil + end + private def hashes_for_posts posts post_ids = posts.map{|p| p.id} diff --git a/app/models/profile.rb b/app/models/profile.rb index c87c97f46..2e66fc37e 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -34,12 +34,12 @@ class Profile validates_length_of :first_name, :maximum => 32 validates_length_of :last_name, :maximum => 32 + before_save :strip_names attr_accessible :first_name, :last_name, :image_url, :image_url_medium, :image_url_small, :birthday, :gender, :bio, :searchable, :date - def person self._parent_document end diff --git a/app/views/people/_aspect_list.haml b/app/views/people/_aspect_list.haml index 795ee47eb..06150e1b5 100644 --- a/app/views/people/_aspect_list.haml +++ b/app/views/people/_aspect_list.haml @@ -37,23 +37,14 @@ = link_to "edit aspect membership", "#", :id=> "edit_contact_aspects" .edit{:class => ("hidden" if contact)} - .contact_list#aspects_list - %ul - - for aspect in aspects_with_person - %li{:data=>{:guid=>aspect.id}} - %span.name - = link_to aspect.name, aspect - .right - = aspect_membership_button(aspect.id, contact, person) - - for aspect in aspects_without_person - %li{:data=>{:guid=>aspect.id}} - %span.name - = link_to aspect.name, aspect - .right - = aspect_membership_button(aspect.id, contact, person) + = render :partial => 'people/share_with_pane', + :locals => {:person => person, + :contact => contact, + :aspects_with_person => aspects_with_person, + :aspects_without_person => aspects_without_person} - .right - = link_to "done editing", "#", :id => "done_contact_aspects" - if contact + .right + = link_to "done editing", "#", :id => "done_contact_aspects" = link_to t('people.profile_sidebar.remove_contact'), person, :confirm => t('are_you_sure'), :method => :delete diff --git a/app/views/people/_person.html.haml b/app/views/people/_person.html.haml index d0d3eca84..6ac250463 100644 --- a/app/views/people/_person.html.haml +++ b/app/views/people/_person.html.haml @@ -4,22 +4,27 @@ %li.message{:id => person.id} + .right{:style=>"display:inline;"} + - if person.owner_id == current_user.id + = t('.thats_you') + - elsif contact && !contact.pending + = t('.already_connected') + - elsif (contact && contact.pending) || request + = t('.pending_request') + - else + - single_aspect_form ||= nil + = link_to "start sharing", + {:controller => "people", + :action => "share_with", + :id => person.id}, + :class => 'button share_with_button' + = person_image_link(person) .content %span.from =person_link(person) - .right{:style=>"display:inline;"} - - if person.owner_id == current_user.id - = t('.thats_you') - - elsif contact && !contact.pending - = t('.already_connected') - - elsif (contact && contact.pending) || request - = link_to t('.pending_request'), aspects_manage_path - - else - - single_aspect_form ||= nil - = render(:partial => request_partial(single_aspect_form), :locals => {:aspects => aspects, :destination_handle => person.diaspora_handle}) .info = person.diaspora_handle diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml index 9a7d7d886..dd6ff969f 100644 --- a/app/views/people/index.html.haml +++ b/app/views/people/index.html.haml @@ -5,6 +5,9 @@ - content_for :page_title do = t('search') +- content_for :head do + = include_javascripts :people + .span-24.last - if params[:q].blank? %h2 @@ -17,7 +20,7 @@ .span-15.append-1 - + - if @hashes.empty? %p =t('.no_one_found') diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index a3e235d78..f6a31fb31 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -3,17 +3,17 @@ -# the COPYRIGHT file. %li.message{:data=>{:guid=>post.id}} + - if person.owner_id == current_user.id + .right.controls + - reshare_aspects = aspects_without_post(aspects, post) + - unless reshare_aspects.empty? + = render 'shared/reshare', :aspects => reshare_aspects, :post => post + = link_to t('delete'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" + = person_image_link(person, :size => :thumb_small) .content .from - - if person.owner_id == current_user.id - .right - - reshare_aspects = aspects_without_post(aspects, post) - - unless reshare_aspects.empty? - = render 'shared/reshare', :aspects => reshare_aspects, :post => post - = link_to t('delete'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" - %h4 =person_link(person) diff --git a/config/assets.yml b/config/assets.yml index f9b074403..567cf0bcc 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -28,6 +28,8 @@ javascripts: - public/javascripts/vendor/jquery-ui-1.8.6.custom.min.js - public/javascripts/aspect-edit.js - public/javascripts/contact-list.js + people: + - public/javascripts/contact-list.js photos: - public/javascripts/photo-show.js diff --git a/config/routes.rb b/config/routes.rb index 067443185..093004271 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,10 @@ Diaspora::Application.routes.draw do resources :requests, :only => [:destroy, :create] resources :services resources :posts, :only => [:show], :path => '/p/' + + + + match '/people/share_with' => 'people#share_with', :as => 'share_with' resources :people do resources :status_messages resources :photos diff --git a/public/javascripts/view.js b/public/javascripts/view.js index b21d589a5..26d79e5a8 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -3,7 +3,7 @@ * the COPYRIGHT file. */ var View = { - initialize: function() { + initialize: function() { /* Buttons */ $("input[type='submit']").addClass("button"); @@ -45,7 +45,7 @@ var View = { $(this.newRequest.selector) .live("submit", this.newRequest.submit); - /* Button fancyboxes */ + /* Button fancyboxes */ $(this.fancyBoxButtons.selectors.join(", ")) .fancybox({ 'titleShow': false, @@ -67,34 +67,35 @@ var View = { .click(this.userMenu.removeFocus) .click(this.reshareButton.removeFocus); }, - + addAspectButton: { click: function() { $("#aspect_name").focus(); }, selector: ".add_aspect_button" }, - - fancyBoxButtons: { + + fancyBoxButtons: { selectors: [ ".add_aspect_button", ".manage_aspect_contacts_button", ".invite_user_button", ".add_photo_button", ".remove_person_button", - ".question_mark" + ".question_mark", + ".share_with_button" ] }, - + debug: { - click: function() { + click: function() { $("#debug_more").toggle("fast"); }, selector: "#debug_info" }, - flashes: { - animate: function() { + flashes: { + animate: function() { var $this = $(View.flashes.selector); $this.animate({ top: 0 @@ -108,10 +109,10 @@ var View = { gettingStarted: { click: function() { - var $this = $(this); - $this.animate({ + var $this = $(this); + $this.animate({ left: parseInt($this.css("left"), 30) === 0 ? -$this.outerWidth() : 0 - }, function() { + }, function() { $this.css("left", "1000px"); }); }, @@ -120,7 +121,7 @@ var View = { newRequest: { submit: function() { - $(this).hide().parent().find(".message").removeClass("hidden"); + $(this).hide().parent().find(".message").removeClass("hidden"); }, selector: ".new_request" }, @@ -135,18 +136,18 @@ var View = { }, search: { - blur: function() { + blur: function() { $(this).removeClass("active"); }, - focus: function() { + focus: function() { $(this).addClass("active"); }, selector: "#q" }, - + tooltips: { - addAspect: { - bind: function() { + addAspect: { + bind: function() { $(".add_aspect_button", "#aspect_nav").tipsy({ gravity:"w" }); @@ -154,7 +155,7 @@ var View = { }, avatars: { - bind: function() { + bind: function() { $("#left_pane img.avatar, #manage_aspect_zones img.avatar").tipsy({ live: true }); @@ -162,7 +163,7 @@ var View = { }, public_badge: { - bind: function() { + bind: function() { $(".public_badge img").tipsy({ live: true }); @@ -170,7 +171,7 @@ var View = { }, whatIsThis: { - bind: function() { + bind: function() { $(".what_is_this").tipsy({ live: true, delayIn: 400 @@ -178,9 +179,9 @@ var View = { } }, - bindAll: function() { + bindAll: function() { for(var element in this) { - if(element !== "bindAll") { + if(element !== "bindAll") { this[element].bind(); } }; @@ -197,10 +198,10 @@ var View = { }, userMenu: { - click: function() { + click: function() { $(this).toggleClass("active"); }, - removeFocus: function(evt) { + removeFocus: function(evt) { var $target = $(evt.target); if(!$target.closest("#user_menu").length) { $(View.userMenu.selector).removeClass("active"); @@ -210,7 +211,7 @@ var View = { }, webFingerForm: { - submit: function(evt) { + submit: function(evt) { $(evt.currentTarget).siblings("#loader").show(); $("#request_result li:first").hide(); }, @@ -218,7 +219,7 @@ var View = { } }; -$(function() { - /* Make sure this refers to View, not the document */ +$(function() { + /* Make sure this refers to View, not the document */ View.initialize.apply(View); }); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 732b8ba3c..571a0ae02 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -617,20 +617,22 @@ ul.comments a :padding 3px -li.message .from .right +li.message .right :display none :position absolute :right 12px - :font - :size 12px - :color #999 - a - :color #999 + + &.controls :font - :weight normal - &:hover - :text - :decoration underline + :size 12px + :color #999 + a + :color #999 + :font + :weight normal + &:hover + :text + :decoration underline li.message:hover .right @@ -2041,3 +2043,22 @@ h3,h4 .aspect_badge :top -0.2em +#share_with + :min-width 400px + :max-width 400px + + .share_with_header + :min-height 100px + + .avatar + :width 100px + :height 100px + :float left + h3,p + :padding + :left 120px + h3 + :margin 0 + +#aspects_list + :height auto diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index b3649e198..187e01288 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -14,6 +14,15 @@ describe PeopleController do sign_in :user, user end + describe '#share_with' do + before do + @person = Factory.create(:person) + end + it 'succeeds' do + get :share_with, :id => @person.id + response.should be_success + end + end describe '#hashes_from_people' do before do @everyone = [] @@ -127,14 +136,14 @@ describe PeopleController do get :show, :id => user.id response.should redirect_to people_path end - + it "renders the show page of a contact" do user2 = make_user connect_users(user, aspect, user2, user2.aspects.create(:name => 'Neuroscience')) get :show, :id => user2.person.id response.should be_success end - + it "renders the show page of a non-contact" do user2 = make_user get :show, :id => user2.person.id From e881edab96cce520b58f488360f7c8df6ee737b3 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 15 Dec 2010 18:05:18 -0800 Subject: [PATCH 2/2] Fix missing partials on last commit, you can now accept a request from the requestor's profile page --- app/controllers/aspects_controller.rb | 6 ++++++ app/views/people/_share_with_pane.html.haml | 20 ++++++++++++++++++++ app/views/people/share_with.html.haml | 18 ++++++++++++++++++ spec/controllers/aspects_controller_spec.rb | 21 +++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 app/views/people/_share_with_pane.html.haml create mode 100644 app/views/people/share_with.html.haml diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index cdb1d80ef..dda2ed1ee 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -116,6 +116,12 @@ class AspectsController < ApplicationController current_user.add_contact_to_aspect(@contact, @aspect) else current_user.send_contact_request_to(@person, @aspect) + contact = current_user.contact_for(@person) + + if request = Request.from(@person).to(current_user).first + request.destroy + contact.update_attributes(:pending => false) + end end flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success' diff --git a/app/views/people/_share_with_pane.html.haml b/app/views/people/_share_with_pane.html.haml new file mode 100644 index 000000000..fade052ad --- /dev/null +++ b/app/views/people/_share_with_pane.html.haml @@ -0,0 +1,20 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +.contact_list#aspects_list + %ul + - for aspect in aspects_with_person + %li{:data=>{:guid=>aspect.id}} + %span.name + = link_to aspect.name, aspect + .right + = aspect_membership_button(aspect.id, contact, person) + + - for aspect in aspects_without_person + %li{:data=>{:guid=>aspect.id}} + %span.name + = link_to aspect.name, aspect + .right + = aspect_membership_button(aspect.id, contact, person) + diff --git a/app/views/people/share_with.html.haml b/app/views/people/share_with.html.haml new file mode 100644 index 000000000..9d535847e --- /dev/null +++ b/app/views/people/share_with.html.haml @@ -0,0 +1,18 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +#share_with + .share_with_header + = person_image_link(@person, :size => :thumb_medium) + %h3 + = "Start sharing with #{@person.name}" + %p + = "Once #{@person.first_name} accepts, you'll start seeing each other's posts on Diaspora" + + = render :partial => 'share_with_pane', + :locals => {:person => @person, + :contact => @contact, + :aspects_with_person => @aspects_with_person, + :aspects_without_person => @aspects_without_person} + diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 4a23fabc0..0fd1ff1e7 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -227,6 +227,27 @@ describe AspectsController do end describe "#add_to_aspect" do + context 'with an incoming request' do + before do + @user3 = make_user + @user3.send_contact_request_to(@user.person, @user3.aspects.create(:name => "Walruses")) + end + it 'deletes the request' do + post 'add_to_aspect', + :format => 'js', + :person_id => @user3.person.id, + :aspect_id => @aspect1.id + Request.from(@user3).to(@user).first.should be_nil + end + it 'does not leave the contact pending' do + post 'add_to_aspect', + :format => 'js', + :person_id => @user3.person.id, + :aspect_id => @aspect1.id + @user.contact_for(@user3.person).should_not be_pending + + end + end context 'with a non-contact' do before do @person = Factory(:person)