Merge pull request #3009 from evazion/fix-dmails-search
Fix #1868: Dmail search improvements: subject, searchbox
This commit is contained in:
@@ -27,9 +27,6 @@ class DmailsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
def show
|
||||
@dmail = Dmail.find(params[:id])
|
||||
check_privilege(@dmail)
|
||||
|
||||
@@ -102,6 +102,11 @@ class Dmail < ActiveRecord::Base
|
||||
where("is_deleted = ?", true)
|
||||
end
|
||||
|
||||
def title_matches(query)
|
||||
query = "*#{query}*" unless query =~ /\*/
|
||||
where("lower(dmails.title) LIKE ?", query.to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
def search_message(query)
|
||||
if query =~ /\*/ && CurrentUser.user.is_builder?
|
||||
escaped_query = query.to_escaped_for_sql_like
|
||||
@@ -131,6 +136,10 @@ class Dmail < ActiveRecord::Base
|
||||
q = where("true")
|
||||
return q if params.blank?
|
||||
|
||||
if params[:title_matches].present?
|
||||
q = q.title_matches(params[:title_matches])
|
||||
end
|
||||
|
||||
if params[:message_matches].present?
|
||||
q = q.search_message(params[:message_matches])
|
||||
end
|
||||
|
||||
8
app/views/dmails/_search.html.erb
Normal file
8
app/views/dmails/_search.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<%= simple_form_for(:search, url: dmails_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= f.hidden_field :folder, value: params[:folder] %>
|
||||
<%= f.input :title_matches, label: "Title", hint: "Use * for wildcard", input_html: { value: params[:search][:title_matches] } %>
|
||||
<%= f.input :message_matches, label: "Message", hint: "Use * for wildcard", input_html: { value: params[:search][:messages_matches] } %>
|
||||
<%= f.input :to_name, label: "To", input_html: { value: params[:search][:to_name] } %>
|
||||
<%= f.input :from_name, label: "From", input_html: { value: params[:search][:from_name] } %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
@@ -6,7 +6,6 @@
|
||||
<li><%= link_to "Sent", sent_dmails_path(set_default_folder: true) %></li>
|
||||
<li>|</li>
|
||||
<li><%= link_to "New", new_dmail_path %></li>
|
||||
<li><%= link_to "Search", search_dmails_path %></li>
|
||||
<li><%= link_to "Mark all as read", {:controller => "dmails", :action => "mark_all_as_read"}, :method => :post, :remote => true %></li>
|
||||
<li>|</li>
|
||||
<li><%= link_to "Help", wiki_pages_path(title: "help:dmail") %></li>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
<h1>Messages</h1>
|
||||
<% end %>
|
||||
|
||||
<%= render "search" %>
|
||||
|
||||
<table class="striped" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<div id="c-dmails">
|
||||
<div id="a-search">
|
||||
<h1>Search Messages</h1>
|
||||
<%= form_tag(dmails_path, :method => :get, :class => "simple_form") do %>
|
||||
<%= hidden_field_tag :folder, params[:folder] %>
|
||||
|
||||
<%= search_field "message_matches", :label => "Message" %>
|
||||
<%= search_field "to_name", :label => "To" %>
|
||||
<%= search_field "from_name", :label => "From" %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Search Messages - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
@@ -74,9 +74,14 @@ class DmailTest < ActiveSupport::TestCase
|
||||
context "search" do
|
||||
should "return results based on title contents" do
|
||||
dmail = FactoryGirl.create(:dmail, :title => "xxx", :owner => @user)
|
||||
matches = Dmail.search_message("xxx")
|
||||
assert(matches.any?)
|
||||
matches = Dmail.search_message("aaa")
|
||||
|
||||
matches = Dmail.search(title_matches: "x")
|
||||
assert_equal([dmail.id], matches.map(&:id))
|
||||
|
||||
matches = Dmail.search(message_matches: "xxx")
|
||||
assert_equal([dmail.id], matches.map(&:id))
|
||||
|
||||
matches = Dmail.search(message_matches: "aaa")
|
||||
assert(matches.empty?)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user