touched up AspectsController#index for readability's sake
This commit is contained in:
parent
4ab112645f
commit
36a9e1643e
2 changed files with 18 additions and 20 deletions
|
|
@ -12,13 +12,11 @@ class AspectsController < ApplicationController
|
||||||
|
|
||||||
helper_method :tags, :tag_followings
|
helper_method :tags, :tag_followings
|
||||||
helper_method :all_aspects_selected?
|
helper_method :all_aspects_selected?
|
||||||
|
helper_method :selected_people
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:a_ids]
|
|
||||||
@aspects = current_user.aspects.where(:id => params[:a_ids])
|
|
||||||
else
|
|
||||||
@aspects = current_user.aspects
|
@aspects = current_user.aspects
|
||||||
end
|
@aspects = @aspects.where(:id => params[:a_ids]) if params[:a_ids]
|
||||||
|
|
||||||
# redirect to aspects creation
|
# redirect to aspects creation
|
||||||
if @aspects.blank?
|
if @aspects.blank?
|
||||||
|
|
@ -27,14 +25,6 @@ class AspectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
@aspect_ids = @aspects.map { |a| a.id }
|
@aspect_ids = @aspects.map { |a| a.id }
|
||||||
|
|
||||||
unless params[:only_posts]
|
|
||||||
all_selected_people = Person.joins(:contacts => :aspect_memberships).
|
|
||||||
where(:contacts => {:user_id => current_user.id},
|
|
||||||
:aspect_memberships => {:aspect_id => @aspect_ids})
|
|
||||||
@selected_people = all_selected_people.select("DISTINCT people.*").includes(:profile)
|
|
||||||
end
|
|
||||||
|
|
||||||
@posts = current_user.visible_posts(:by_members_of => @aspect_ids,
|
@posts = current_user.visible_posts(:by_members_of => @aspect_ids,
|
||||||
:type => ['StatusMessage','Reshare', 'ActivityStreams::Photo'],
|
:type => ['StatusMessage','Reshare', 'ActivityStreams::Photo'],
|
||||||
:order => session[:sort_order] + ' DESC',
|
:order => session[:sort_order] + ' DESC',
|
||||||
|
|
@ -44,13 +34,21 @@ class AspectsController < ApplicationController
|
||||||
if params[:only_posts]
|
if params[:only_posts]
|
||||||
render :partial => 'shared/stream', :locals => {:posts => @posts}
|
render :partial => 'shared/stream', :locals => {:posts => @posts}
|
||||||
else
|
else
|
||||||
@contact_count = @selected_people.count
|
@contact_count = selected_people(@aspect_ids).count
|
||||||
|
|
||||||
@aspect = :all unless params[:a_ids]
|
# aspects.first is used for mobile
|
||||||
@aspect ||= @aspects.first # used in mobile
|
# the :all is currently used for view switching logic
|
||||||
|
@aspect = (params[:a_ids] ? @aspects.first : :all)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@aspect = current_user.aspects.create(params[:aspect])
|
@aspect = current_user.aspects.create(params[:aspect])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,6 @@
|
||||||
:posts => @posts
|
:posts => @posts
|
||||||
|
|
||||||
.span-5.rightBar.last
|
.span-5.rightBar.last
|
||||||
= render 'selected_contacts', :people => @selected_people.sample(20), :count => @contact_count
|
= render 'selected_contacts', :people => selected_people(@aspect_ids).sample(20), :count => @contact_count
|
||||||
|
|
||||||
= render 'shared/right_sections'
|
= render 'shared/right_sections'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue