more work on paginators
This commit is contained in:
@@ -11,11 +11,11 @@ module PaginationHelper
|
||||
html = "<menu>"
|
||||
|
||||
unless records.is_first_page?
|
||||
html << '<li>' + link_to("« Previous", params.merge(:page => "b#{records.first_id}")) + '</li>'
|
||||
html << '<li>' + link_to("« Previous", params.merge(:page => "b#{records.before_id}")) + '</li>'
|
||||
end
|
||||
|
||||
unless records.is_last_page?
|
||||
html << '<li>' + link_to("Next »", params.merge(:page => "a#{records.last_id}")) + '</li>'
|
||||
html << '<li>' + link_to("Next »", params.merge(:page => "a#{records.after_id}")) + '</li>'
|
||||
end
|
||||
|
||||
html << "</menu>"
|
||||
|
||||
37
app/logical/post_sets/base.rb
Normal file
37
app/logical/post_sets/base.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
module PostSets
|
||||
class Base
|
||||
def has_wiki?
|
||||
false
|
||||
end
|
||||
|
||||
def wiki_page
|
||||
nil
|
||||
end
|
||||
|
||||
def presenter
|
||||
@presenter ||= PostSetPresenter.new(self)
|
||||
end
|
||||
|
||||
def is_single_tag?
|
||||
false
|
||||
end
|
||||
|
||||
def tag
|
||||
tag_string
|
||||
end
|
||||
|
||||
def arbitrary_sql_order_clause(ids, table_name)
|
||||
if ids.empty?
|
||||
return "#{table_name}.id desc"
|
||||
end
|
||||
|
||||
conditions = []
|
||||
|
||||
ids.each_with_index do |x, n|
|
||||
conditions << "when #{x} then #{n}"
|
||||
end
|
||||
|
||||
"case #{table_name}.id " + conditions.join(" ") + " end"
|
||||
end
|
||||
end
|
||||
end
|
||||
24
app/logical/post_sets/favorite.rb
Normal file
24
app/logical/post_sets/favorite.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
module PostSets
|
||||
class Favorite < Base
|
||||
attr_reader :user, :page, :favorites, :posts
|
||||
|
||||
def initialize(params)
|
||||
@user = ::User.find(params[:id])
|
||||
@page = [params[:page].to_i, 1].max
|
||||
@favorites = ::Favorite.model_for(@user.id).for_user(@user.id).paginate(page)
|
||||
@posts = ::Post.where("id in (?)", post_ids).order(arbitrary_sql_order_clause(post_ids, "posts")).paginate("a0")
|
||||
end
|
||||
|
||||
def post_ids
|
||||
@post_ids ||= favorites.map(&:post_id)
|
||||
end
|
||||
|
||||
def offset
|
||||
(page - 1) * records_per_page
|
||||
end
|
||||
|
||||
def tag_string
|
||||
@tag_string ||= "fav:#{user.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
module PostSets
|
||||
class Post
|
||||
class Post < Base
|
||||
attr_reader :tags, :page, :posts
|
||||
|
||||
def initialize(params)
|
||||
@@ -31,13 +31,5 @@ module PostSets
|
||||
def is_single_tag?
|
||||
tags.size == 1
|
||||
end
|
||||
|
||||
def tag
|
||||
tag_string
|
||||
end
|
||||
|
||||
def presenter
|
||||
@presenter ||= PostSetPresenter.new(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,8 @@ class Favorite < ActiveRecord::Base
|
||||
TABLE_COUNT = 100
|
||||
belongs_to :post
|
||||
|
||||
scope :for_user, lambda {|user_id| where("user_id = ?", user_id)}
|
||||
|
||||
def self.model_for(user_id)
|
||||
mod = user_id.to_i % TABLE_COUNT
|
||||
Object.const_get("Favorite#{mod}")
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
</div>
|
||||
|
||||
<div id="paginator">
|
||||
<%= will_paginate(@artist_versions) %>
|
||||
<%= sequential_paginator(@artist_versions) %>
|
||||
</div>
|
||||
|
||||
<%= render "artists/secondary_links" %>
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
</table>
|
||||
|
||||
<div id="paginator">
|
||||
<%= will_paginate(@artists) %>
|
||||
<%= numbered_paginator(@artists) do |page| %>
|
||||
<%= link_to(page, artists_path(:page => page, :search => params[:search])) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="paginator">
|
||||
<%= sequential_paginator(@comments) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div id="paginator">
|
||||
<%= sequential_paginator(@posts) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<div class="clearfix"></div>
|
||||
|
||||
<div class="paginator">
|
||||
<%= @post_set.presenter.pagination_html(self) %>
|
||||
<%= sequential_paginator(@post_set.favorites) %>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
</table>
|
||||
|
||||
<div id="paginator">
|
||||
<%= will_paginate @forum_posts %>
|
||||
<%= numbered_paginator(@forum_posts) do |page| %>
|
||||
<%= link_to(page, forum_posts_path(:search => params[:search], :page => page)) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= render "forum_topics/secondary_links" %>
|
||||
@@ -1,4 +1,4 @@
|
||||
<h3>Forum</h3>
|
||||
<h1>Forum</h1>
|
||||
|
||||
<table width="100%" class="striped">
|
||||
<thead>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</table>
|
||||
|
||||
<div id="paginator">
|
||||
<%= will_paginate(@note_versions) %>
|
||||
<%= sequential_paginator(@note_versions) %>
|
||||
</div>
|
||||
|
||||
<%= render :partial => "footer" %>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</div>
|
||||
|
||||
<div id="paginator">
|
||||
<%= will_paginate(@pool_versions) %>
|
||||
<%= sequential_paginator(@pool_versions) %>
|
||||
</div>
|
||||
|
||||
<%= render :partial => "pools/secondary_links" %>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</table>
|
||||
|
||||
<div id="paginator">
|
||||
<%= will_paginate(@pools) %>
|
||||
<%= sequential_paginator(@pools) %>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
</table>
|
||||
|
||||
<div id="paginator">
|
||||
<%= will_paginate(@wiki_pages) %>
|
||||
<%= smart_paginator(@wiki_pages) do |page| %>
|
||||
<%= link_to(page, wiki_pages_path(:page => page, :search => params[:search])) %>
|
||||
<% end %>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user