simple filter on contacts index page (my/all contacts)

This commit is contained in:
danielgrippi 2011-06-27 12:12:50 -07:00
parent e22701a12d
commit a2609f7dac
5 changed files with 114 additions and 10 deletions

View file

@ -7,8 +7,16 @@ class ContactsController < ApplicationController
def index def index
@aspect = :manage @aspect = :manage
@all_contacts_count = current_user.contacts.count
@my_contacts_count = current_user.contacts.receiving.count
unless params[:set] == "all"
@contacts = current_user.contacts.receiving.includes(:aspects, :person => :profile).order('contacts.id DESC').paginate(:page => params[:page], :per_page => 25)
else
@contacts = current_user.contacts.includes(:aspects, :person => :profile).order('contacts.id DESC').paginate(:page => params[:page], :per_page => 25) @contacts = current_user.contacts.includes(:aspects, :person => :profile).order('contacts.id DESC').paginate(:page => params[:page], :per_page => 25)
end end
end
def sharing def sharing
@contacts = current_user.contacts.sharing.includes(:aspect_memberships) @contacts = current_user.contacts.sharing.includes(:aspect_memberships)

View file

@ -6,12 +6,34 @@
= t('.title') = t('.title')
#section_header #section_header
.right
= link_to("+ #{t('.add_a_new_aspect')}", "#add_aspect_pane", :class => "new_aspect button", :title => t('.add_a_new_aspect'), :rel => 'facebox')
%h2 %h2
=t('.title') = t('.title')
.span-15.append-1
.span-5.append-1
%ul#left_nav
%li{:class => ("active" unless params["set"] == "all")}
%a{:href => contacts_path}
.contact_count
= @my_contacts_count
My Contacts
%ul#aspect_sub_nav
- for aspect in all_aspects
%li
= aspect
%li
Add new aspect
%li{:class => ("active" if params["set"] == "all")}
%a{:href => contacts_path(:set => "all")}
.contact_count
= @all_contacts_count
All Contacts
.span-15
#people_stream.stream #people_stream.stream
- for contact in @contacts - for contact in @contacts
= render :partial => 'people/person', :locals => {:contact => contact, :person => contact.person} = render :partial => 'people/person', :locals => {:contact => contact, :person => contact.person}

View file

@ -284,6 +284,11 @@ ul.dropdown
:bottom 1px solid #ddd :bottom 1px solid #ddd
:top 1px solid #fff :top 1px solid #fff
&:first-child
:border
:top none
.youtube-player, .vimeo-player .youtube-player, .vimeo-player
:border none :border none
:height 370px :height 370px
@ -2953,3 +2958,53 @@ h1.tag
.hold-me .hold-me
:display inline-block :display inline-block
ul#left_nav
:margin 0
:padding 0
li
:position relative
a
:display block
:width 100%
:padding 3px 7px
&:hover
:background
:color lighten($blue,45%)
:text
:decoration none
li.active
a
:color #333
:font
:weight 700
.contact_count
@include border-radius(4px)
:float right
:margin-top 1px
:color #999
:background
:color #eee
:padding 0 5px
:display inline
:font
:size 11px
li.active
.contact_count
:font
:weight 700
:color #666
ul#aspect_sub_nav
:padding 0
:left 20px
:margin 0
:display none

View file

@ -6,8 +6,8 @@ require 'spec_helper'
describe ContactsController do describe ContactsController do
before do before do
sign_in :user, alice sign_in :user, bob
@controller.stub(:current_user).and_return(alice) @controller.stub(:current_user).and_return(bob)
end end
describe '#sharing' do describe '#sharing' do
@ -23,7 +23,7 @@ describe ContactsController do
it "assigns only the people sharing with you with 'share_with' flag" do it "assigns only the people sharing with you with 'share_with' flag" do
get :sharing, :id => 'share_with' get :sharing, :id => 'share_with'
assigns[:contacts].to_set.should == alice.contacts.sharing.to_set assigns[:contacts].to_set.should == bob.contacts.sharing.to_set
end end
end end
@ -41,7 +41,25 @@ describe ContactsController do
it "assigns contacts" do it "assigns contacts" do
get :index get :index
contacts = assigns(:contacts) contacts = assigns(:contacts)
contacts.to_set.should == alice.contacts.to_set contacts.to_set.should == bob.contacts.to_set
end
it "shows only contacts a user is sharing with" do
contact = bob.contacts.first
contact.update_attributes(:sharing => false)
get :index, :set => "mine"
contacts = assigns(:contacts)
contacts.to_set.should == bob.contacts.sharing.to_set
end
it "shows all contacts (sharing and receiving)" do
contact = bob.contacts.first
contact.update_attributes(:sharing => false)
get :index, :set => "all"
contacts = assigns(:contacts)
contacts.to_set.should == bob.contacts.to_set
end end
it "generates a jasmine fixture", :fixture => 'jasmine' do it "generates a jasmine fixture", :fixture => 'jasmine' do

View file

@ -34,6 +34,7 @@ describe User do
new_user.id.should_not == alice.id new_user.id.should_not == alice.id
end end
end end
describe "validation" do describe "validation" do
describe "of associated person" do describe "of associated person" do
it "fails if person is not valid" do it "fails if person is not valid" do