Take nested queried out of aspects manage

This commit is contained in:
Raphael 2010-12-07 00:20:52 -08:00
parent d3483c1cd5
commit f421f1327c
3 changed files with 18 additions and 17 deletions

View file

@ -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
@aspect_hashes = hashes_for_aspects @aspects.all, @contacts
@aspect_hashes = hashes_for_aspects @aspects.all, @contacts, :limit => 8
@aspect = :all
@contact_hashes = hashes_for_contacts @contacts
@ -78,6 +78,7 @@ class AspectsController < ApplicationController
def manage
@aspect = :manage
@remote_requests = current_user.requests_for_me
@aspect_hashes = hashes_for_aspects @aspects, @contacts
end
def update
@ -148,14 +149,14 @@ class AspectsController < ApplicationController
contacts.map{|c| {:contact => c, :person => people_hash[c.person_id.to_id]}}
end
def hashes_for_aspects aspects, contacts
def hashes_for_aspects aspects, contacts, opts = {}
aspects.map do |a|
hash = {:aspect => a}
aspect_contacts = contacts.select{|c|
c.aspect_ids.include?(a.id)}
hash[:contact_count] = aspect_contacts.count
person_ids = aspect_contacts.map{|c| c.person_id}
hash[:people] = Person.all(:id.in => person_ids, :limit => 8)
hash[:people] = Person.all({:id.in => person_ids}.merge(opts))
hash
end
end

View file

@ -33,30 +33,30 @@
= render 'shared/invitations', :invites => @invites
.span-19.last
- for aspect in @aspects
.aspect.span-9{:data=>{:guid=>aspect.id}}
- for hash in @aspect_hashes
.aspect.span-9{:data=>{:guid=>hash[:aspect].id}}
.aspect_name
%span.edit_name_field
%h3{:contenteditable=>true}
= aspect.name
= hash[:aspect].name
%span.tip click to edit
%ul.tools
%li= link_to t('.add_a_new_contact'), "#manage_aspect_contacts_pane_#{aspect.id}", :class => 'manage_aspect_contacts_button'
%li!= remove_link(aspect)
%li= link_to t('.add_a_new_contact'), "#manage_aspect_contacts_pane_#{hash[:aspect].id}", :class => 'manage_aspect_contacts_button'
%li!= remove_link(hash[:aspect])
%ul.dropzone{:data=>{:aspect_id=>aspect.id}}
-for contact in aspect.contacts
%li.person{:data=>{:guid=>contact.person.id, :aspect_id=>aspect.id}}
%ul.dropzone{:data=>{:aspect_id=>hash[:aspect].id}}
-for person in hash[:people]
%li.person{:data=>{:guid=>person.id, :aspect_id=>hash[:aspect].id}}
.delete
.x
X
.circle
= link_to person_image_tag(contact.person), contact.person
= link_to person_image_tag(person), person
.draggable_info
=t('.drag_to_add')
.fancybox_content
%div{:id => "manage_aspect_contacts_pane_#{aspect.id}"}
= render "requests/manage_aspect_contacts", :aspect_name => aspect.name, :aspect_id => aspect.id, :manage => true
%div{:id => "manage_aspect_contacts_pane_#{hash[:aspect].id}"}
= render "requests/manage_aspect_contacts", :aspect_name => hash[:aspect].name, :aspect_id => hash[:aspect].id, :manage => true

View file

@ -179,7 +179,7 @@ describe AspectsController do
10.times {@people << Factory.create(:person)}
@people.each{|p| @user.reload.activate_contact(p, @user.aspects.first.reload)}
@user.reload
@hashes = @controller.send(:hashes_for_aspects, @user.aspects, @user.contacts)
@hashes = @controller.send(:hashes_for_aspects, @user.aspects, @user.contacts, :limit => 9)
@hash = @hashes.first
@aspect = @user.aspects.first
end
@ -195,8 +195,8 @@ describe AspectsController do
gotten_people = @hash[:people].map{|p| p.diaspora_handle}
gotten_people.each{|p| desired_people.should include p}
end
it 'has at most 8 people' do
@hash[:people].length.should == 8
it 'takes a limit on people returned' do
@hash[:people].length.should == 9
end
end