Skip to content

Commit

Permalink
Added pagination to the followers
Browse files Browse the repository at this point in the history
Pagination is now availabile on the users list view
  • Loading branch information
LindseyB committed Mar 24, 2011
1 parent 1d3c9da commit eb87083
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
8 changes: 8 additions & 0 deletions public/css/internal.css
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,14 @@ body {
.user-list .even {
background: #e5e5e5;
}
#next_button {
float: right;
margin-right: 0.5em;
}
#prev_button {
float: left;
margin-left: 0.5em;
}
#sites {
width: 350px;
float: left;
Expand Down
41 changes: 39 additions & 2 deletions rstatus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,49 @@ class Rstatus < Sinatra::Base

# This lets us see who is following.
get '/users/:name/following' do
@users = User.first(:username => params[:name]).following
params[:page] ||= 1
params[:per_page] ||= 20
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i
feeds = User.first(:username => params[:name]).following

@users = feeds.paginate(:page => params[:page], :per_page => params[:per_page])

@next_page = nil
@prev_page = nil

if params[:page]*params[:per_page] < feeds.count
@next_page = "?#{Rack::Utils.build_query :page => params[:page] + 1}"
end

if params[:page] > 1
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1}"
end

haml :"users/list", :locals => {:title => "Following"}
end

get '/users/:name/followers' do
@users = User.first(:username => params[:name]).followers
params[:page] ||= 1
params[:per_page] ||= 20
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i
feeds = User.first(:username => params[:name]).following

@users = feeds.paginate(:page => params[:page], :per_page => params[:per_page])

@next_page = nil
@prev_page = nil

if params[:page]*params[:per_page] < feeds.count
@next_page = "?#{Rack::Utils.build_query :page => params[:page] + 1}"
end

if params[:page] > 1
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1}"
end


haml :"users/list", :locals => {:title => "Followers"}
end

Expand Down
9 changes: 9 additions & 0 deletions views/users/list.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
%input{:type => "hidden", :name => "url", :value => "/feeds/#{@author.feed.id}"}
%input.button.follow{:type => "submit", :value => "Follow", :id => "follow-#{@author.feed.id}"}

- unless @prev_page.nil?
%a.button{:href => @prev_page, :id => "prev_button"}
&laquo; Previous

- unless @next_page.nil?
%a.button{:href => @next_page, :id => "next_button"}
Next &raquo;


:javascript
$(document).ready(function(){
$(".unfollow").click(function(){
Expand Down

0 comments on commit eb87083

Please sign in to comment.