Skip to content
Extraits de code Groupes Projets
contacts_controller.rb 1,45 ko
Newer Older
danielgrippi's avatar
danielgrippi a validé
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class ContactsController < ApplicationController
  before_filter :authenticate_user!
Raphael Sofaer's avatar
Raphael Sofaer a validé
  def index
    @contacts = case params[:set]
    when "only_sharing"
      current_user.contacts.only_sharing
    when "all"
      current_user.contacts
      if params[:a_id]
        @aspect = current_user.aspects.find(params[:a_id])
        @aspect.contacts
      else
        current_user.contacts.receiving
      end
    end

    respond_to do |format|
      format.html { @contacts = sort_and_paginate_profiles(@contacts) }
      format.mobile { @contacts = sort_and_paginate_profiles(@contacts) }
      format.json {
        @people = Person.for_json.joins(:contacts => :aspect_memberships).
          where(:contacts => { :user_id => current_user.id },
                :aspect_memberships => { :aspect_id => params[:aspect_ids] })

Raphael Sofaer's avatar
Raphael Sofaer a validé
  end

  def sharing
    @contacts = current_user.contacts.sharing.includes(:aspect_memberships)
    render :layout => false
  def featured
    @featured = true
  private

  def sort_and_paginate_profiles contacts
    contacts.
      includes(:aspects, :person => :profile).
      order('profiles.last_name ASC').
      paginate(:page => params[:page], :per_page => 25)
  end