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
@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)
end
end
def sharing
@contacts = current_user.contacts.sharing.includes(:aspect_memberships)

View file

@ -6,12 +6,34 @@
= t('.title')
#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
= 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
- for contact in @contacts
= render :partial => 'people/person', :locals => {:contact => contact, :person => contact.person}

View file

@ -284,6 +284,11 @@ ul.dropdown
:bottom 1px solid #ddd
:top 1px solid #fff
&:first-child
:border
:top none
.youtube-player, .vimeo-player
:border none
:height 370px
@ -2953,3 +2958,53 @@ h1.tag
.hold-me
: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
before do
sign_in :user, alice
@controller.stub(:current_user).and_return(alice)
sign_in :user, bob
@controller.stub(:current_user).and_return(bob)
end
describe '#sharing' do
@ -23,7 +23,7 @@ describe ContactsController do
it "assigns only the people sharing with you with 'share_with' flag" do
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
@ -41,7 +41,25 @@ describe ContactsController do
it "assigns contacts" do
get :index
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
it "generates a jasmine fixture", :fixture => 'jasmine' do

View file

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