diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index 16252cc6a..f3fb165e3 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -10,10 +10,13 @@ class ContactsController < ApplicationController @all_contacts_count = current_user.contacts.count @my_contacts_count = current_user.contacts.receiving.count + @only_sharing_count = current_user.contacts.only_sharing.count - if params["a_id"] + if params[:a_id] @aspect_ = current_user.aspects.find(params["a_id"]) @contacts = @aspect_.contacts.includes(:aspects, :person => :profile).order('profiles.last_name ASC').paginate(:page => params[:page], :per_page => 25) + elsif params[:set] == "only_sharing" + @contacts = current_user.contacts.only_sharing.includes(:aspects, :person => :profile).order('profiles.last_name ASC').paginate(:page => params[:page], :per_page => 25) elsif params[:set] != "all" @contacts = current_user.contacts.receiving.includes(:aspects, :person => :profile).order('profiles.last_name ASC').paginate(:page => params[:page], :per_page => 25) else diff --git a/app/models/contact.rb b/app/models/contact.rb index 33ae11fba..486cb708f 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -27,6 +27,10 @@ class Contact < ActiveRecord::Base where(:receiving => true) } + scope :only_sharing, lambda { + sharing.where(:receiving => false) + } + before_destroy :destroy_notifications def destroy_notifications Notification.where(:target_type => "Person", diff --git a/app/views/contacts/index.html.haml b/app/views/contacts/index.html.haml index 91f018dbe..3e0fc25db 100644 --- a/app/views/contacts/index.html.haml +++ b/app/views/contacts/index.html.haml @@ -16,13 +16,13 @@ .span-5.append-1 %ul#left_nav - %li{:class => ("active" unless params["set"] == "all")} + %li{:class => ("active" if params["set"] != "all" && params["set"] != "only_sharing")} %a{:href => contacts_path, :class => ("sub_selected" if params["a_id"])} .contact_count = @my_contacts_count My Contacts - %ul#aspect_sub_nav + %ul.sub_nav - for aspect in all_aspects %li{:class => ("active" if params["a_id"].to_i == aspect.id)} %a{:href => contacts_path(:a_id => aspect.id)} @@ -32,17 +32,23 @@ %li = link_to "+ Add new aspect", "#add_aspect_pane", :class => "new_aspect", :rel => "facebox" - %li{:class => ("active" if params["set"] == "all")} - %a{:href => contacts_path(:set => "all")} + %li{:class => ("active" if params["set"] == "all" || params["set"] == "only_sharing")} + %a{:href => contacts_path(:set => "all"), :class => ("sub_selected" if params["set"] == "only_sharing")} .contact_count = @all_contacts_count All Contacts + %ul.sub_nav + %li{:class => ("active" if params["set"] == "only_sharing")} + %a{:href => contacts_path(:set => "only_sharing")} + .contact_count + = @only_sharing_count + Only sharing with me + .span-15 #people_stream.stream.contacts - if @contacts.size > 0 - for contact in @contacts - .stream_element{:id => contact.person.id} .right - if @aspect_ diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index c31cb4c2f..ea6b3b48f 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -2989,7 +2989,7 @@ ul#left_nav :weight 700 :color #666 - ul#aspect_sub_nav + ul.sub_nav :display block .contact_count @@ -3004,7 +3004,7 @@ ul#left_nav :font :size 11px - ul#aspect_sub_nav + ul.sub_nav :padding 0 :margin 0 :display none diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index a63afb92d..d6de9e878 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -68,6 +68,19 @@ describe Contact do }.by(1) end end + + describe 'only_sharing' do + it 'returns contacts with sharing true and receiving false' do + lambda { + alice.contacts.create!(:receiving => true, :sharing => true, :person => Factory(:person)) + alice.contacts.create!(:receiving => false, :sharing => true, :person => Factory(:person)) + alice.contacts.create!(:receiving => false, :sharing => true, :person => Factory(:person)) + alice.contacts.create!(:receiving => true, :sharing => false, :person => Factory(:person)) + }.should change{ + Contact.receiving.count + }.by(2) + end + end end describe '#contacts' do