added popular exploration, added order:rank
This commit is contained in:
21
app/presenters/post_set_presenters/base.rb
Normal file
21
app/presenters/post_set_presenters/base.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
module PostSetPresenters
|
||||
class Base
|
||||
def posts
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def post_previews_html(template)
|
||||
html = ""
|
||||
|
||||
if posts.empty?
|
||||
return template.render(:partial => "post_sets/blank")
|
||||
end
|
||||
|
||||
posts.each do |post|
|
||||
html << PostPresenter.preview(post)
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
module PostSetPresenters
|
||||
class Favorite
|
||||
class Favorite < Base
|
||||
attr_accessor :favorite_set, :tag_set_presenter
|
||||
delegate :favorites, :posts, :to => :favorite_set
|
||||
delegate :favorites, :to => :favorite_set
|
||||
|
||||
def initialize(favorite_set)
|
||||
@favorite_set = favorite_set
|
||||
@@ -15,19 +15,9 @@ module PostSetPresenters
|
||||
def tag_list_html(template)
|
||||
tag_set_presenter.tag_list_html(template)
|
||||
end
|
||||
|
||||
def post_previews_html(template)
|
||||
html = ""
|
||||
|
||||
if favorites.empty?
|
||||
return template.render(:partial => "post_sets/blank")
|
||||
end
|
||||
|
||||
favorites.each do |favorite|
|
||||
html << PostPresenter.preview(favorite.post)
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
|
||||
def posts
|
||||
favorites.map(&:post)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
module PostSetPresenters
|
||||
class Pool
|
||||
attr_reader :tag_set_presenter, :pool_set
|
||||
class Pool < Base
|
||||
attr_reader :tag_set_presenter, :post_set
|
||||
delegate :posts, :to => :post_set
|
||||
|
||||
def initialize(pool_set)
|
||||
@pool_set = pool_set
|
||||
def initialize(post_set)
|
||||
@post_set = post_set
|
||||
@tag_set_presenter = TagSetPresenter.new(
|
||||
RelatedTagCalculator.calculate_from_sample_to_array(
|
||||
pool_set.tag_string
|
||||
post_set.tag_string
|
||||
).map {|x| x[0]}
|
||||
)
|
||||
end
|
||||
@@ -14,19 +15,5 @@ module PostSetPresenters
|
||||
def tag_list_html(template)
|
||||
tag_set_presenter.tag_list_html(template)
|
||||
end
|
||||
|
||||
def post_previews_html(template)
|
||||
html = ""
|
||||
|
||||
if pool_set.posts.empty?
|
||||
return template.render(:partial => "post_sets/blank")
|
||||
end
|
||||
|
||||
pool_set.posts.each do |post|
|
||||
html << PostPresenter.preview(post)
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
34
app/presenters/post_set_presenters/popular.rb
Normal file
34
app/presenters/post_set_presenters/popular.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
module PostSetPresenters
|
||||
class Popular < Base
|
||||
attr_accessor :post_set, :tag_set_presenter
|
||||
delegate :posts, :date, :to => :post_set
|
||||
|
||||
def initialize(post_set)
|
||||
@post_set = post_set
|
||||
end
|
||||
|
||||
def prev_day
|
||||
date - 1
|
||||
end
|
||||
|
||||
def next_day
|
||||
date + 1
|
||||
end
|
||||
|
||||
def prev_week
|
||||
date - 7
|
||||
end
|
||||
|
||||
def next_week
|
||||
date + 7
|
||||
end
|
||||
|
||||
def prev_month
|
||||
1.month.ago(date)
|
||||
end
|
||||
|
||||
def next_month
|
||||
1.month.since(date)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
module PostSetPresenters
|
||||
class Post
|
||||
class Post < Base
|
||||
attr_accessor :post_set, :tag_set_presenter
|
||||
delegate :posts, :to => :post_set
|
||||
|
||||
def initialize(post_set)
|
||||
@post_set = post_set
|
||||
@@ -18,26 +19,8 @@ module PostSetPresenters
|
||||
RelatedTagCalculator.calculate_from_sample_to_array(post_set.tag_string).map(&:first)
|
||||
end
|
||||
|
||||
def posts
|
||||
post_set.posts
|
||||
end
|
||||
|
||||
def tag_list_html(template)
|
||||
tag_set_presenter.tag_list_html(template)
|
||||
end
|
||||
|
||||
def post_previews_html(template)
|
||||
html = ""
|
||||
|
||||
if posts.empty?
|
||||
return template.render(:partial => "post_sets/blank")
|
||||
end
|
||||
|
||||
posts.each do |post|
|
||||
html << PostPresenter.preview(post)
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
107
app/presenters/user_presenter.rb
Normal file
107
app/presenters/user_presenter.rb
Normal file
@@ -0,0 +1,107 @@
|
||||
class UserPresenter
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def level
|
||||
user.level_string
|
||||
end
|
||||
|
||||
def ban_reason
|
||||
if user.is_banned?
|
||||
"#{user.ban.reason}; expires #{user.ban.expires_at}"
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def tag_subscriptions(template)
|
||||
user.subscriptions.map do |subscription|
|
||||
template.link_to(subscription.name, template.tag_subscription_path(subscription))
|
||||
end.join("; ")
|
||||
end
|
||||
|
||||
def upload_limit
|
||||
deleted_count = Post.for_user(user.id).deleted.count
|
||||
pending_count = Post.for_user(user.id).pending.count
|
||||
approved_count = Post.where("is_flagged = false and is_pending = false and user_id = ?", user.id).count
|
||||
|
||||
if user.base_upload_limit
|
||||
limit = user.base_upload_limit - pending_count
|
||||
string = "base:#{user.base_upload_limit} - pending:#{pending_count}"
|
||||
else
|
||||
limit = 10 + (approved_count / 10) - (deleted_count / 4) - pending_count
|
||||
string = "base:10 + approved:(#{approved_count} / 10) - deleted:(#{deleted_count}) / 4 - pending:#{pending_count}"
|
||||
end
|
||||
|
||||
if limit > 20
|
||||
limit = 20
|
||||
string += " = capped:20"
|
||||
elsif limit < 0
|
||||
limit = 0
|
||||
string += " = capped:0"
|
||||
else
|
||||
string += " = #{limit}"
|
||||
end
|
||||
|
||||
return string
|
||||
end
|
||||
|
||||
def uploads(template)
|
||||
template.link_to(Post.for_user(user.id).count, template.posts_path(:tags => "uploader:#{user.name}"))
|
||||
end
|
||||
|
||||
def deleted_uploads(template)
|
||||
template.link_to(Post.for_user(user.id).deleted.count, template.posts_path(:tags => "status:deleted uploader:#{user.name}"))
|
||||
end
|
||||
|
||||
def favorites(template)
|
||||
template.link_to(Favorite.for_user(user.id).count, template.favorites_path(:user_id => user.id))
|
||||
end
|
||||
|
||||
def comments(template)
|
||||
template.link_to(Comment.for_user(user.id).count, template.comments_path(:search => {:creator_id_eq => user.id}))
|
||||
end
|
||||
|
||||
def post_versions(template)
|
||||
template.link_to(PostVersion.for_user(user.id).count, template.post_versions_path(:search => {:updater_id_eq => user.id}))
|
||||
end
|
||||
|
||||
def note_versions(template)
|
||||
template.link_to(NoteVersion.for_user(user.id).count, template.note_versions_path(:search => {:updater_id_eq => user.id}))
|
||||
end
|
||||
|
||||
def wiki_page_versions(template)
|
||||
template.link_to(WikiPageVersion.for_user(user.id).count, template.wiki_page_versions_path(:search => {:updater_id_eq => user.id}))
|
||||
end
|
||||
|
||||
def forum_posts(template)
|
||||
template.link_to(ForumPost.for_user(user.id).count, template.forum_posts_path(:search => {:creator_id_eq => user.id}))
|
||||
end
|
||||
|
||||
def pool_versions(template)
|
||||
template.link_to(PoolVersion.for_user(user.id).count, template.pool_versions_path(:search => {:updater_id_eq => user.id}))
|
||||
end
|
||||
|
||||
def inviter(template)
|
||||
if user.inviter_id
|
||||
template.link_to(user.inviter.name, template.user_path(user.inviter_id))
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def approvals(template)
|
||||
template.link_to(Post.where("approver_id = ?", user.id).count, template.posts_path(:tags => "approver:#{user.name}"))
|
||||
end
|
||||
|
||||
def feedbacks(template)
|
||||
positive = UserFeedback.for_user(user.id).positive.count
|
||||
neutral = UserFeedback.for_user(user.id).neutral.count
|
||||
negative = UserFeedback.for_user(user.id).negative.count
|
||||
|
||||
template.link_to("positive:#{positive} neutral:#{neutral} negative:#{negative}", user_feedbacks_path(:search => {:user_id_rq => user.id}))
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user