diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 034eef546..76f513fdc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index f6b72300c..4d59643c3 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -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 diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index 2dad6c40d..382d17cae 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -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 diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 667b7053c..1603a62ce 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -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 diff --git a/app/views/aspects/index.js.erb b/app/views/aspects/index.js.erb index 02fc82740..58451a81f 100644 --- a/app/views/aspects/index.js.erb +++ b/app/views/aspects/index.js.erb @@ -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(); diff --git a/app/views/aspects/index.mobile.haml b/app/views/aspects/index.mobile.haml index ff1473093..92c31211c 100644 --- a/app/views/aspects/index.mobile.haml +++ b/app/views/aspects/index.mobile.haml @@ -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 diff --git a/lib/fake.rb b/lib/fake.rb index fe51a8f4c..77050ff10 100644 --- a/lib/fake.rb +++ b/lib/fake.rb @@ -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 diff --git a/public/javascripts/infinite_scroll.js b/public/javascripts/infinite_scroll.js index 5ab83fa8d..0bc18808c 100644 --- a/public/javascripts/infinite_scroll.js +++ b/public/javascripts/infinite_scroll.js @@ -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, diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 3826a7ae5..684f07869 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -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