Newer
Older
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
before_filter :authenticate_user!
Sarah Mei
a validé
before_filter :save_sort_order, :only => :index
before_filter :ensure_page, :only => :index
respond_to :json, :only => [:show, :create]
Ilyaaaaaaaaaaaaa Zhitomirskiy
a validé
helper_method :tags, :tag_followings
helper_method :all_aspects_selected?
helper_method :selected_people
Daniel Grippi & Raphael Sofaer
a validé
@aspects = current_user.aspects
@aspects = @aspects.where(:id => params[:a_ids]) if params[:a_ids]
@aspect_ids = @aspects.map { |a| a.id }
Raphael Sofaer
a validé
@posts = current_user.visible_posts(:by_members_of => @aspect_ids,
:type => ['StatusMessage','Reshare', 'ActivityStreams::Photo'],
:order => session[:sort_order] + ' DESC',
:max_time => params[:max_time].to_i
Raphael Sofaer
a validé
).includes(:mentions => {:person => :profile}, :author => :profile)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @posts}
else
@contact_count = selected_people(@aspect_ids).count
# aspects.first is used for mobile
# the :all is currently used for view switching logic
@aspect = (params[:a_ids] ? @aspects.first : :all)
end
Sarah Mei
a validé
def selected_people(aspect_ids)
@selected_people ||= Person.joins(:contacts => :aspect_memberships).
where(:contacts => {:user_id => current_user.id},
:aspect_memberships => {:aspect_id => @aspect_ids}).
select("DISTINCT people.*").includes(:profile)
end
danielvincent
a validé
@aspect = current_user.aspects.create(params[:aspect])
flash[:notice] = I18n.t('aspects.create.success', :name => @aspect.name)
if current_user.getting_started
redirect_to :back
elsif request.env['HTTP_REFERER'].include?("contacts")
redirect_to :back
elsif params[:aspect][:person_id].present?
@person = Person.where(:id => params[:aspect][:person_id]).first
if @contact = current_user.contact_for(@person)
@contact.aspects << @aspect
else
@contact = current_user.share_with(@person, @aspect)
end
danielgrippi
a validé
redirect_to contacts_path(:a_id => @aspect.id)
respond_to do |format|
format.js { render :text => I18n.t('aspects.create.failure'), :status => 422 }
format.html do
flash[:error] = I18n.t('aspects.create.failure')
redirect_to :back
end
end
@remote = params[:remote] == "true"
format.html { render :layout => false }
@aspect = current_user.aspects.where(:id => params[:id]).first
Sarah Mei
a validé
flash[:notice] = I18n.t 'aspects.destroy.success', :name => @aspect.name
Sarah Mei
a validé
flash[:error] = I18n.t 'aspects.destroy.failure', :name => @aspect.name
Gonzalo Rodriguez
a validé
end
if request.referer.include?('contacts')
redirect_to contacts_path
else
@aspect = current_user.aspects.where(:id => params[:id]).first
if @aspect
redirect_to aspects_path('a_ids[]' => @aspect.id)
else
redirect_to aspects_path
end
@aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => {:person => :profile}).first
@contacts_in_aspect = @aspect.contacts.includes(:aspect_memberships, :person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
if @contacts_in_aspect.empty?
danielgrippi
a validé
@contacts_not_in_aspect = current_user.contacts.includes(:aspect_memberships, :person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
danielgrippi
a validé
@contacts_not_in_aspect = current_user.contacts.where(c[:id].not_in(@contacts_in_aspect.map(&:id))).includes(:aspect_memberships, :person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@aspect_ids = [@aspect.id]
danielvincent
a validé
render :layout => false
end
def update
@aspect = current_user.aspects.where(:id => params[:id]).first
Sarah Mei
a validé
if @aspect.update_attributes!(params[:aspect])
flash[:notice] = I18n.t 'aspects.update.success', :name => @aspect.name
Sarah Mei
a validé
flash[:error] = I18n.t 'aspects.update.failure', :name => @aspect.name
def toggle_contact_visibility
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
if @aspect.contacts_visible?
@aspect.contacts_visible = false
else
@aspect.contacts_visible = true
end
@aspect.save
end
Sarah Mei
a validé
def ensure_page
params[:max_time] ||= Time.now + 1
end
def all_aspects_selected?
@aspect == :all
end
Ilyaaaaaaaaaaaaa Zhitomirskiy
a validé
def tag_followings
if current_user
if @tag_followings == nil
@tag_followings = current_user.tag_followings
end
@tag_followings
end
end
def tags
@tags ||= current_user.followed_tags
Ilyaaaaaaaaaaaaa Zhitomirskiy
a validé
end
private
Sarah Mei
a validé
def save_sort_order
if params[:sort_order].present?
session[:sort_order] = (params[:sort_order] == 'created_at') ? 'created_at' : 'updated_at'
elsif session[:sort_order].blank?
session[:sort_order] = 'updated_at'
else
session[:sort_order] = (session[:sort_order] == 'created_at') ? 'created_at' : 'updated_at'
end
end