Merge pull request #2856 from evazion/feat-comment-search

Add more options to /comments/search
This commit is contained in:
Albert Yi
2017-01-24 12:01:47 -08:00
committed by GitHub
4 changed files with 61 additions and 11 deletions

View File

@@ -43,3 +43,20 @@ form.simple_form {
}
}
form.inline-form {
display: table;
> div.input {
display: table-row;
line-height: 2em;
label {
text-align: right;
}
label, input {
display: table-cell;
padding-right: 1em;
}
}
}

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

View File

@@ -2,13 +2,16 @@
<div id="a-search">
<h1>Search Comments</h1>
<%= form_tag(comments_path, :method => :get, :class => "simple_form") do %>
<%= simple_form_for(:search, :method => :get, url: comments_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
<%= hidden_field_tag "group_by", "comment", :id => "group_by_full" %>
<%= search_field "body_matches", :label => "Body" %>
<%= search_field "creator_name", :label => "User" %>
<%= search_field "post_tags_match", :label => "Tags" %>
<%= submit_tag "Search" %>
<%= f.input :creator_name, label: "Commenter" %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :post_tags_match, label: "Tags" %>
<%= f.input :is_deleted, label: "Deleted?", collection: [["Yes", true], ["No", false]] %>
<%= f.input :is_sticky, label: "Sticky?", collection: [["Yes", true], ["No", false]] %>
<%= f.input :do_not_bump_post, label: "Bumping?", collection: [["Yes", false], ["No", true]] %>
<%= f.input :order, include_blank: false, collection: [%w(Created id_desc), %w(Updated updated_at_desc), %w(Score score_desc), %w(Post post_id_desc)] %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>