Take another shot at fixing pagination
This commit is contained in:
parent
4037ce48c5
commit
746a0c38b3
4 changed files with 12 additions and 10 deletions
|
|
@ -23,11 +23,15 @@ class AspectsController < ApplicationController
|
|||
redirect_to getting_started_path
|
||||
return
|
||||
end
|
||||
params[:page] = params[:page] ? params[:page].to_i : 1
|
||||
|
||||
|
||||
|
||||
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq
|
||||
@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).paginate(:page => params[:page], :per_page => 15, :order => "posts.#{session[:sort_order]} DESC")
|
||||
:comments, :mentions, :likes, :dislikes)
|
||||
|
||||
@fakes = PostsFake.new(@posts)
|
||||
|
||||
@contact_count = current_user.contacts.count
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@
|
|||
= render 'shared/publisher', :aspect => aspect, :aspect_ids => aspect_ids
|
||||
#sort_by
|
||||
= t('.sort_by')
|
||||
= link_to_if(session[:sort_order] == 'created_at', t('.activity'), aspects_path(:a_ids => params[:a_ids], :sort_order => 'updated_at'))
|
||||
= link_to_if(session[:sort_order] == 'created_at', t('.activity'), aspects_path(:a_ids => params[:a_ids], :sort_order => 'updated_at'))
|
||||
|
|
||||
= 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
|
||||
%a.paginate
|
||||
= t("more")
|
||||
=link_to(t('more'), aspects_path(:a_ids => params[:a_ids], :page => params[:page] + 1), :class => 'paginate')
|
||||
- else
|
||||
= render 'aspects/no_posts_message', :post_count => posts.length
|
||||
= will_paginate posts
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ module Diaspora
|
|||
def raw_visible_posts(opts = {})
|
||||
opts = opts.dup
|
||||
opts[:type] ||= ['StatusMessage', 'Photo']
|
||||
opts[:limit] ||= 20
|
||||
opts[:limit] ||= 15
|
||||
opts[:order] ||= 'updated_at DESC'
|
||||
opts[:hidden] ||= false
|
||||
order_with_table = 'posts.' + opts[:order]
|
||||
opts[:offset] = opts[:page] ? opts[:limit] * opts[:page] - 1 : 0
|
||||
opts[:offset] = opts[:page].nil? || opts[:page] == 1 ? 0 : opts[:limit] * (opts[:page] - 1)
|
||||
select_clause ='posts.id, posts.updated_at AS updated_at, posts.created_at AS created_at'
|
||||
|
||||
posts_from_others = Post.joins(:contacts).where( :post_visibilities => {:hidden => opts[:hidden]}, :contacts => {:user_id => self.id})
|
||||
|
|
@ -37,7 +37,7 @@ module Diaspora
|
|||
all_posts = "(#{posts_from_others.to_sql}) UNION (#{posts_from_self.to_sql}) ORDER BY #{opts[:order]} LIMIT #{opts[:limit]}"
|
||||
post_ids = Post.connection.execute(all_posts).map{|r| r.first}
|
||||
|
||||
Post.where(:id => post_ids, :pending => false, :type => opts[:type]).select('DISTINCT posts.*').limit(opts[:limit]).order(order_with_table).offset(opts[:offset])
|
||||
Post.where(:id => post_ids, :pending => false, :type => opts[:type]).select('DISTINCT posts.*').limit(opts[:limit]).order(order_with_table)
|
||||
end
|
||||
|
||||
def visible_photos
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ $(document).ready(function() {
|
|||
var scrolled = 0;
|
||||
|
||||
$('#main_stream').infinitescroll({
|
||||
navSelector : ".pagination",
|
||||
navSelector : ".paginate",
|
||||
// selector for the paged navigation (it will be hidden)
|
||||
nextSelector : ".pagination a.next_page",
|
||||
nextSelector : ".paginate",
|
||||
// selector for the NEXT link (to page 2)
|
||||
itemSelector : "#main_stream .stream_element",
|
||||
// selector for all items you'll retrieve
|
||||
|
|
|
|||
Loading…
Reference in a new issue