Render less stuff, set fewer things, make AspectsController#index more horrifying. Maybe Vanna could help with this? Mustache definitely would.
This commit is contained in:
parent
fd0fa61d53
commit
bbf1bf00cb
9 changed files with 54 additions and 30 deletions
|
|
@ -24,7 +24,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def set_header_data
|
||||
if user_signed_in?
|
||||
if request.format.html?
|
||||
if request.format.html? && !params[:only_posts]
|
||||
@aspect = nil
|
||||
@object_aspect_ids = []
|
||||
@notification_count = Notification.for(current_user, :unread =>true).count
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ class AspectsController < ApplicationController
|
|||
else
|
||||
@aspects = current_user.aspects
|
||||
end
|
||||
@aspects = @aspects.includes(:contacts => {:person => :profile})
|
||||
|
||||
#No aspect_listings on infinite scroll
|
||||
@aspects = @aspects.includes(:contacts => {:person => :profile}) unless params[:only_posts]
|
||||
|
||||
# redirect to signup
|
||||
if (current_user.getting_started == true || @aspects.blank?) && !request.format.mobile? && !request.format.js?
|
||||
|
|
@ -25,17 +27,25 @@ class AspectsController < ApplicationController
|
|||
end
|
||||
params[:page] = params[:page] ? params[:page].to_i : 1
|
||||
|
||||
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq
|
||||
|
||||
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq unless params[:only_posts]
|
||||
|
||||
@aspect_ids = @aspects.map { |a| a.id }
|
||||
@posts = current_user.raw_visible_posts(:by_members_of => @aspect_ids, :type => 'StatusMessage', :order => session[:sort_order] + ' DESC', :page => params[:page]).includes(
|
||||
:comments, :mentions, :likes, :dislikes)
|
||||
posts = current_user.raw_visible_posts(:by_members_of => @aspect_ids,
|
||||
:type => 'StatusMessage',
|
||||
:order => session[:sort_order] + ' DESC',
|
||||
:page => params[:page]
|
||||
).includes(:comments, :mentions, :likes, :dislikes)
|
||||
|
||||
@fakes = PostsFake.new(@posts)
|
||||
@posts = PostsFake.new(posts)
|
||||
if params[:only_posts]
|
||||
render :partial => 'shared/stream', :locals => {:posts => @posts}
|
||||
else
|
||||
@contact_count = current_user.contacts.count
|
||||
|
||||
@contact_count = current_user.contacts.count
|
||||
|
||||
@aspect = :all unless params[:a_ids]
|
||||
@aspect ||= @aspects.first # used in mobile
|
||||
@aspect = :all unless params[:a_ids]
|
||||
@aspect ||= @aspects.first # used in mobile
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
= link_to_if(session[:sort_order] == 'updated_at', t('.post_time'), aspects_path(:a_ids => params[:a_ids], :sort_order => 'created_at' ))
|
||||
#main_stream.stream{:data => {:guids => aspect_ids.join(',')}}
|
||||
- if posts.length > 0
|
||||
= render 'shared/stream', :posts => fakes
|
||||
= render 'shared/stream', :posts => posts
|
||||
#pagination
|
||||
=link_to(t('more'), aspects_path(:page => (params[:page] + 1), :a_ids => params[:a_ids]), :class => 'paginate')
|
||||
- else
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@
|
|||
= render 'aspect_stream',
|
||||
:aspect => @aspect,
|
||||
:aspect_ids => @aspect_ids,
|
||||
:posts => @posts,
|
||||
:fakes => @fakes
|
||||
:posts => @posts
|
||||
|
||||
.span-7.last
|
||||
#home_user_badge
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
$('#aspect_stream_container').html("<%= escape_javascript(render('aspects/aspect_stream', :aspect => @aspect, :aspect_ids => @aspect_ids, :posts => @posts, :fakes => @fakes)) %>");
|
||||
$('#aspect_stream_container').html("<%= escape_javascript(render('aspects/aspect_stream', :aspect => @aspect, :aspect_ids => @aspect_ids, :posts => @posts)) %>");
|
||||
$('#aspect_listings').html("<%= escape_javascript(render('aspects/aspect_listings', :aspects => @aspects)) %>");
|
||||
$('a[rel*=facebox]').facebox();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
%h1
|
||||
= link_to t('.post_a_message'), '#publisher_page', :id => 'publisher_button'
|
||||
#main_stream.stream
|
||||
= render 'shared/stream', :posts => @fakes
|
||||
= render 'shared/stream', :posts => @posts
|
||||
%a.more-link.paginate{:href => aspects_path(:a_ids => params[:a_ids], :page => params[:page] + 1)}
|
||||
%h2= t("more")
|
||||
- content_for :subpages do
|
||||
|
|
|
|||
|
|
@ -24,8 +24,13 @@ class PostsFake
|
|||
end
|
||||
end
|
||||
|
||||
def models
|
||||
self.post_fakes.map{|a| a.model }
|
||||
end
|
||||
|
||||
class Fake
|
||||
attr_accessor :comments
|
||||
attr_reader :model
|
||||
def initialize(model, fakes_collection)
|
||||
@fakes_collection = fakes_collection
|
||||
@model = model
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ var InfiniteScroll = {
|
|||
// selector for the paged navigation (it will be hidden)
|
||||
nextSelector : ".paginate",
|
||||
// selector for the NEXT link (to page 2)
|
||||
itemSelector : "#main_stream .stream_element",
|
||||
itemSelector : ".stream_element",
|
||||
// selector for all items you'll retrieve
|
||||
pathParse : function( pathStr, nextPage ){
|
||||
return pathStr.replace( "page=2", "page=" + nextPage)
|
||||
var newPath = pathStr.replace("?", "?only_posts=true&");
|
||||
return newPath.replace( "page=2", "page=" + nextPage);
|
||||
},
|
||||
bufferPx: 300,
|
||||
debug: false,
|
||||
|
|
|
|||
|
|
@ -116,57 +116,66 @@ describe AspectsController do
|
|||
|
||||
it "pulls back non hidden posts" do
|
||||
get :index
|
||||
assigns[:posts].include?(@status).should be_true
|
||||
assigns[:posts].models.include?(@status).should be_true
|
||||
end
|
||||
it "does not pull back hidden posts" do
|
||||
@vis.update_attributes( :hidden => true )
|
||||
get :index
|
||||
assigns[:posts].include?(@status).should be_false
|
||||
assigns[:posts].models.include?(@status).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'infinite scroll' do
|
||||
it 'renders with the infinite scroll param' do
|
||||
get :index, :only_posts => true
|
||||
assigns[:posts].models.include?(@posts.first).should be_true
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "ordering" do
|
||||
it "orders posts by updated_at by default" do
|
||||
get :index
|
||||
assigns(:posts).should == @posts
|
||||
assigns(:posts).models.should == @posts
|
||||
end
|
||||
|
||||
it "orders posts by created_at on request" do
|
||||
get :index, :sort_order => 'created_at'
|
||||
assigns(:posts).should == @posts.reverse
|
||||
assigns(:posts).models.should == @posts.reverse
|
||||
end
|
||||
|
||||
it "remembers your sort order and lets you override the memory" do
|
||||
get :index, :sort_order => "created_at"
|
||||
assigns(:posts).should == @posts.reverse
|
||||
assigns(:posts).models.should == @posts.reverse
|
||||
get :index
|
||||
assigns(:posts).should == @posts.reverse
|
||||
assigns(:posts).models.should == @posts.reverse
|
||||
get :index, :sort_order => "updated_at"
|
||||
assigns(:posts).should == @posts
|
||||
assigns(:posts).models.should == @posts
|
||||
end
|
||||
|
||||
it "doesn't allow SQL injection" do
|
||||
get :index, :sort_order => "\"; DROP TABLE users;"
|
||||
assigns(:posts).should == @posts
|
||||
assigns(:posts).models.should == @posts
|
||||
get :index, :sort_order => "created_at"
|
||||
assigns(:posts).should == @posts.reverse
|
||||
assigns(:posts).models.should == @posts.reverse
|
||||
end
|
||||
end
|
||||
|
||||
it "returns all posts by default" do
|
||||
@alice.aspects.reload
|
||||
get :index
|
||||
assigns(:posts).length.should == 2
|
||||
assigns(:posts).models.length.should == 2
|
||||
end
|
||||
|
||||
it "can filter to a single aspect" do
|
||||
get :index, :a_ids => [@alices_aspect_2.id.to_s]
|
||||
assigns(:posts).length.should == 1
|
||||
assigns(:posts).models.length.should == 1
|
||||
end
|
||||
|
||||
it "can filter to multiple aspects" do
|
||||
get :index, :a_ids => [@alices_aspect_1.id.to_s, @alices_aspect_2.id.to_s]
|
||||
assigns(:posts).length.should == 2
|
||||
assigns(:posts).models.length.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue