Refactor aspectscontroller and aspect_contacts.haml
This commit is contained in:
parent
14a9bc02f9
commit
9442553504
6 changed files with 81 additions and 47 deletions
|
|
@ -14,6 +14,7 @@ class AspectsController < ApplicationController
|
|||
@aspect_hashes = hashes_for_aspects @aspects.all, @contacts
|
||||
@aspect = :all
|
||||
|
||||
@contact_hashes = hashes_for_contacts @contacts
|
||||
|
||||
if current_user.getting_started == true
|
||||
redirect_to getting_started_path
|
||||
|
|
@ -63,7 +64,7 @@ class AspectsController < ApplicationController
|
|||
unless @aspect
|
||||
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
|
||||
else
|
||||
@aspect_contacts = @aspect.contacts
|
||||
@aspect_contacts = hashes_for_contacts @aspect.contacts
|
||||
@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
|
||||
|
|
@ -140,6 +141,13 @@ class AspectsController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
def hashes_for_contacts contacts
|
||||
people = Person.all(:id.in => contacts.map{|c| c.person_id})
|
||||
people_hash = {}
|
||||
people.each{|p| people_hash[p.id] = p}
|
||||
contacts.map{|c| {:contact => c, :person => people_hash[c.person_id.to_id]}}
|
||||
end
|
||||
|
||||
def hashes_for_aspects aspects, contacts
|
||||
aspects.map do |a|
|
||||
hash = {:aspect => a}
|
||||
|
|
|
|||
36
app/views/aspects/_all_aspects_contacts.haml
Normal file
36
app/views/aspects/_all_aspects_contacts.haml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
-# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
- if @request_count > 0
|
||||
#new_request_pane{:class => "everyone"}
|
||||
%h1.new_request{:style => 'text-align:center'}
|
||||
= new_request_link(@request_count)
|
||||
|
||||
#left_pane.everyone
|
||||
%h3= t('.all_contacts')
|
||||
|
||||
.section.contact_pictures
|
||||
- for contact in @contact_hashes
|
||||
= person_image_link(contact[:person])
|
||||
|
||||
- if @contacts.count == 0
|
||||
%h4
|
||||
= t('.no_contacts')
|
||||
= form_tag(people_path, :method => 'get') do
|
||||
= text_field_tag 'q', nil, :placeholder => t('search'), :type => 'search', :results => 5
|
||||
|
||||
.section.aspect_listings
|
||||
%h3
|
||||
= link_to(t('.aspects'), aspects_manage_path)
|
||||
.right{:style=>"font-size:12px;top:7px;"}
|
||||
= link_to t('.add_aspect'), '#add_aspect_pane', :class => "add_aspect_button"
|
||||
|
||||
%ul
|
||||
- for a_hash in @aspect_hashes
|
||||
= render :partial => 'aspects/aspect', :locals => a_hash
|
||||
|
||||
.section
|
||||
%h3= t('shared.invitations.invites')
|
||||
= render "shared/invitations", :invites => @invites
|
||||
|
||||
|
|
@ -10,44 +10,18 @@
|
|||
editAspect:"#{t('aspects.show.edit_aspect')}"
|
||||
});
|
||||
|
||||
- if aspect != :all && aspect.contacts.count == 0
|
||||
- if aspect.contacts.count == 0
|
||||
:javascript
|
||||
$(document).ready(function(){
|
||||
EditPane.fadeIn();
|
||||
});
|
||||
|
||||
- if (aspect == :all) && @request_count > 0
|
||||
#new_request_pane{:class => "everyone"}
|
||||
%h1.new_request{:style => 'text-align:center'}
|
||||
= new_request_link(@request_count)
|
||||
|
||||
#left_pane{:class => ("everyone" if aspect == :all)}
|
||||
|
||||
- if aspect == :all
|
||||
%h3= t('.all_contacts')
|
||||
|
||||
#left_pane
|
||||
.section.contact_pictures
|
||||
- for contact in contacts
|
||||
= person_image_link(contact.person)
|
||||
|
||||
- if aspect == :all && @contacts.count == 0
|
||||
%h4
|
||||
= t('.no_contacts')
|
||||
= form_tag(people_path, :method => 'get') do
|
||||
= text_field_tag 'q', nil, :placeholder => t('search'), :type => 'search', :results => 5
|
||||
|
||||
-if aspect == :all
|
||||
.section.aspect_listings
|
||||
%h3
|
||||
= link_to(t('.aspects'), aspects_manage_path)
|
||||
.right{:style=>"font-size:12px;top:7px;"}
|
||||
= link_to t('.add_aspect'), '#add_aspect_pane', :class => "add_aspect_button"
|
||||
|
||||
%ul
|
||||
- for a_hash in @aspect_hashes
|
||||
= render :partial => 'aspects/aspect', :locals => a_hash
|
||||
= person_image_link(contact[:person])
|
||||
|
||||
.section
|
||||
%h3= t('.invites')
|
||||
%h3= t('shared.invitations.invites')
|
||||
= render "shared/invitations", :invites => @invites
|
||||
|
||||
|
|
|
|||
|
|
@ -21,5 +21,5 @@
|
|||
= will_paginate @posts
|
||||
|
||||
.span-8.last
|
||||
= render 'aspects/aspect_contacts', :contacts => @contacts, :aspect => @aspect
|
||||
= render 'aspects/all_aspects_contacts'
|
||||
|
||||
|
|
|
|||
|
|
@ -85,18 +85,6 @@ en:
|
|||
add_photos: "add photos"
|
||||
all_contacts: "all contacts"
|
||||
share_with_all: "share across all of your aspects"
|
||||
aspect_contacts:
|
||||
add_to: "add to %{aspect}"
|
||||
done_editing: "done editing"
|
||||
add_existing: "Add an existing contact"
|
||||
aspect_settings: "Aspect settings"
|
||||
remove_aspect: "Delete this aspect"
|
||||
confirm_remove_aspect: "Are you sure you want to delete this aspect?"
|
||||
no_contacts: "You currently have no contacts. Find your contacts here."
|
||||
aspects: "Aspects"
|
||||
add_aspect: "add aspect"
|
||||
invites: "Invites"
|
||||
all_contacts: "All contacts"
|
||||
add_contact:
|
||||
enter_a_diaspora_username: "Enter a Diaspora username:"
|
||||
your_diaspora_username_is: "Your Diaspora username is: %{diaspora_handle}"
|
||||
|
|
@ -104,6 +92,7 @@ en:
|
|||
diaspora_handle: "diaspora@handle.org"
|
||||
know_email: "Know their email address? You should invite them"
|
||||
invitations:
|
||||
invites: "Invites"
|
||||
invite_someone: "Invite someone"
|
||||
invitations_left: "(%{count} left)"
|
||||
dont_have_now: "You don't have any right now, but more invites are coming soon!"
|
||||
|
|
@ -121,6 +110,13 @@ en:
|
|||
all_contacts: "All contacts"
|
||||
cannot_remove: "Cannot remove person from last aspect. (If you want to disconnect from this person you must remove contact.)"
|
||||
aspects:
|
||||
all_aspects_contacts:
|
||||
all_contacts: "All contacts"
|
||||
add_aspect: "add aspect"
|
||||
aspects: "Aspects"
|
||||
no_contacts: "You currently have no contacts. Find your contacts here."
|
||||
aspect_contacts:
|
||||
done_editing: "done editing"
|
||||
show:
|
||||
edit_aspect: "edit aspect"
|
||||
no_contacts_message:
|
||||
|
|
@ -168,8 +164,8 @@ en:
|
|||
index:
|
||||
handle_explanation: "This is your diaspora handle. Like an email address, you can give this to people to reach you."
|
||||
edit_aspect_pane:
|
||||
remove_aspect: "Remove Aspect"
|
||||
confirm_remove_aspect: "Remove aspect?"
|
||||
remove_aspect: "Delete this aspect"
|
||||
confirm_remove_aspect: "Are you sure you want to delete this aspect?"
|
||||
add_existing: "Add an existing contact"
|
||||
users:
|
||||
edit:
|
||||
|
|
|
|||
|
|
@ -66,7 +66,9 @@ describe AspectsController do
|
|||
it "assigns aspect, aspect_contacts, and posts" do
|
||||
get :show, 'id' => @aspect.id.to_s
|
||||
assigns(:aspect).should == @aspect
|
||||
assigns(:aspect_contacts).should == @aspect.contacts
|
||||
achash = @controller.send(:hashes_for_contacts, @aspect.contacts).first
|
||||
assigns(:aspect_contacts).first[:contact].should == achash[:contact]
|
||||
assigns(:aspect_contacts).first[:person].should == achash[:person]
|
||||
assigns(:posts).should == []
|
||||
end
|
||||
it "paginates" do
|
||||
|
|
@ -153,6 +155,24 @@ describe AspectsController do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#hashes_for_contacts" do
|
||||
before do
|
||||
@people = []
|
||||
10.times {@people << Factory.create(:person)}
|
||||
@people.each{|p| @user.reload.activate_contact(p, @user.aspects.first.reload)}
|
||||
@hashes = @controller.send(:hashes_for_contacts,@user.reload.contacts)
|
||||
@hash = @hashes.first
|
||||
end
|
||||
it 'has as many hashes as contacts' do
|
||||
@hashes.length.should == @user.contacts.length
|
||||
end
|
||||
it 'has a contact' do
|
||||
@hash[:contact].should == @user.contacts.first
|
||||
end
|
||||
it 'has a person' do
|
||||
@hash[:person].should == @user.contacts.first.person
|
||||
end
|
||||
end
|
||||
describe "#hashes_for_aspects" do
|
||||
before do
|
||||
@people = []
|
||||
|
|
|
|||
Loading…
Reference in a new issue