Skip to content
Extraits de code Groupes Projets
Valider e63a8a4b rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Take contact.person query out of the views, only query people once in hashes_for_aspects

parent fd9d1332
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -166,13 +166,17 @@ class AspectsController < ApplicationController
end
def hashes_for_aspects aspects, contacts, opts = {}
contact_hashes = hashes_for_contacts contacts
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, :fields => [:profile]}.merge(opts))
aspect_contact_hashes = contact_hashes.select{|c|
c[:contact].aspect_ids.include?(a.id)}
hash[:contact_count] = aspect_contact_hashes.count
if opts[:limit]
hash[:contacts] = aspect_contact_hashes.slice(0,opts[:limit])
else
hash[:contacts] = aspect_contact_hashes
end
hash
end
end
......
......@@ -30,10 +30,5 @@ module AspectsHelper
remove_from_aspect_button(aspect_id, contact.person.id)
end
end
def contact_link(contact)
person = contact.person
link_to person.name, person
end
end
......@@ -4,6 +4,6 @@
%span
= t('contacts', :count => contact_count)
- if contact_count > 0
- for person in people
= person_image_link(person)
- if contact_count > 0
- for hash in contacts
= person_image_link(hash[:person])
......@@ -6,9 +6,9 @@
= include_javascripts :aspects
#edit_aspect_pane
- if @contacts.count > 0
- if @contacts.count > 0
%h4= t('.add_existing')
= render 'shared/contact_list', :aspect_id => aspect.id, :contacts => contacts, :manage => defined?(manage)
= render 'shared/contact_list', :aspect_id => aspect.id, :contact_hashes => contacts, :manage => defined?(manage)
= render 'shared/add_contact', :aspect_id => aspect.id
......
......@@ -51,17 +51,17 @@
%li!= remove_link(hash[:aspect])
%ul.dropzone{:data=>{:aspect_id=>hash[:aspect].id}}
-for person in hash[:people]
%li.person{:data=>{:guid=>person.id, :aspect_id=>hash[:aspect].id}}
-for contact_hash in hash[:contacts]
%li.person{:data=>{:guid=>contact_hash[:person].id, :aspect_id=>hash[:aspect].id}}
.delete
.x
X
.circle
= link_to person_image_tag(person), person
= link_to person_image_tag(contact_hash[:person]), contact_hash[:person]
.draggable_info
=t('.drag_to_add')
.fancybox_content
%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
= render "requests/manage_aspect_contacts", :aspect => hash[:aspect], :manage => true, :contact_hashes => hash[:contacts]
......@@ -15,7 +15,7 @@
.span-8.append-1
= render 'aspects/aspect_contacts', :contacts => @aspect_contacts, :aspect => @aspect
= render 'aspects/edit_aspect_pane', :contacts => @contacts, :aspect => @aspect
= render 'aspects/edit_aspect_pane', :contacts => @aspect_contacts, :aspect => @aspect
.span-15.last
......
......@@ -6,10 +6,10 @@
.modal_title_bar
%h4
= t('.manage_within')
%i= aspect_name
%i= aspect.name
.span-6.append-1.last
%h3= t('.existing')
= render 'shared/contact_list', :aspect_id => aspect_id, :contacts => @contacts, :manage => defined?(manage)
= render 'shared/contact_list', :aspect_id => aspect.id, :contact_hashes => contact_hashes, :manage => defined?(manage)
.span-7.last
= render 'shared/add_contact', :aspect_id => aspect_id
= render 'shared/add_contact', :aspect_id => aspect.id
......@@ -6,10 +6,10 @@
.contact_list
= search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('.all_contacts')
%ul
- for contact in contacts
- for hash in contact_hashes
%li
%span.name
= contact_link contact
= link_to hash[:person].name, hash[:person]
.right
= aspect_membership_button(aspect_id, contact)
= aspect_membership_button(aspect_id, hash[:contact])
......@@ -190,19 +190,20 @@ describe AspectsController do
@hashes.length.should == 2
@hash[:aspect].should == @aspect
end
it 'has a contact count' do
it 'has a contact_count' do
@hash[:contact_count].should == @aspect.contacts.count
end
it 'has people' do
desired_people = @aspect.contacts.map{|c| c.person.id}
gotten_people = @hash[:people].map{|p| p.id}
gotten_people.each{|p| desired_people.should include p}
it 'takes a limit on contacts returned' do
@hash[:contacts].count.should == 9
end
it 'takes a limit on people returned' do
@hash[:people].length.should == 9
it 'has a person in each hash' do
@aspect.contacts.map{|c| c.person}.include?(@hash[:contacts].first[:person]).should be_true
end
it "does not return the rsa key" do
@hash[:people].first.serialized_public_key.should be_nil
@hash[:contacts].first[:person].serialized_public_key.should be_nil
end
it 'has a contact in each hash' do
@aspect.contacts.include?(@hash[:contacts].first[:contact]).should be_true
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