/comments?group_by=comment: add is_sticky/is_deleted/do_not_bump_post/order params.

This commit is contained in:
evazion
2017-01-23 20:42:48 -06:00
parent 6430a9b0a4
commit caaff24112
2 changed files with 35 additions and 5 deletions

View File

@@ -90,7 +90,7 @@ private
end
def index_by_comment
@comments = Comment.search(params[:search]).order("comments.id DESC").paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
@comments = Comment.search(params[:search]).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
respond_with(@comments) do |format|
format.html {render :action => "index_by_comment"}
format.xml do

View File

@@ -56,6 +56,22 @@ class Comment < ActiveRecord::Base
where("comments.is_deleted = false")
end
def sticky
where("comments.is_sticky = true")
end
def unsticky
where("comments.is_sticky = false")
end
def bumping
where("comments.do_not_bump_post = false")
end
def nonbumping
where("comments.do_not_bump_post = true")
end
def post_tags_match(query)
PostQueryBuilder.new(query).build(self.joins(:post)).reorder("")
end
@@ -96,10 +112,24 @@ class Comment < ActiveRecord::Base
q = q.for_creator(params[:creator_id].to_i)
end
if params[:is_deleted] == "true"
q = q.deleted
elsif params[:is_deleted] == "false"
q = q.undeleted
q = q.deleted if params[:is_deleted] == "true"
q = q.undeleted if params[:is_deleted] == "false"
q = q.sticky if params[:is_sticky] == "true"
q = q.unsticky if params[:is_sticky] == "false"
q = q.nonbumping if params[:do_no_bump_post] == "true"
q = q.bumping if params[:do_not_bump_post] == "false"
case params[:order]
when "post_id", "post_id_desc"
q = q.order("comments.post_id DESC")
when "score", "score_desc"
q = q.order("comments.score DESC")
when "updated_at", "updated_at_desc"
q = q.order("comments.updated_at DESC")
else
q = q.order("comments.id DESC")
end
q