Add search page

- Fix issue with updater_name erroring out
- Add search options is_new and name_changed
This commit is contained in:
BrokenEagle
2020-01-07 01:34:47 +00:00
parent 9182a4f556
commit ad1e22af0b
7 changed files with 61 additions and 3 deletions

View File

@@ -12,6 +12,9 @@ class PoolVersionsController < ApplicationController
respond_with(@pool_versions)
end
def search
end
def diff
@pool_version = PoolArchive.find(params[:id])

View File

@@ -21,14 +21,34 @@ class PoolArchive < ApplicationRecord
where_array_includes_any(:added_post_ids, [post_id]).or(where_array_includes_any(:removed_post_ids, [post_id]))
end
def name_matches(name)
name = normalize_name_for_search(name)
name = "*#{name}*" unless name =~ /\*/
where_ilike(:name, name)
end
def search(params)
q = super
q = q.search_attributes(params, :pool_id, :post_ids, :added_post_ids, :removed_post_ids, :updater, :description, :description_changed, :name, :name_changed, :version, :is_active, :is_deleted, :category)
q = q.search_attributes(params, :pool_id, :post_ids, :added_post_ids, :removed_post_ids, :updater_id, :description, :description_changed, :name, :name_changed, :version, :is_active, :is_deleted, :category)
if params[:post_id]
q = q.for_post_id(params[:post_id].to_i)
end
if params[:name_matches].present?
q = q.name_matches(params[:name_matches])
end
if params[:updater_name].present?
q = q.where(updater_id: User.name_to_id(params[:updater_name]))
end
if params[:is_new].to_s.truthy?
q = q.where(version: 1)
elsif params[:is_new].to_s.falsy?
q = q.where("version != 1")
end
q.apply_default_order(params)
end
end
@@ -61,6 +81,14 @@ class PoolArchive < ApplicationRecord
sqs_service.send_message(msg, message_group_id: "pool:#{pool.id}")
end
def self.normalize_name(name)
name.gsub(/[_[:space:]]+/, "_").gsub(/\A_|_\z/, "")
end
def self.normalize_name_for_search(name)
normalize_name(name).mb_chars.downcase
end
def build_diff(other = previous)
diff = {}

View File

@@ -0,0 +1,5 @@
<% content_for(:secondary_links) do %>
<%= quick_search_form_for(:name_matches, pool_versions_path, "pools", autocomplete: "pool") %>
<%= subnav_link_to "Listing", pool_versions_path %>
<%= subnav_link_to "Search", search_pool_versions_path %>
<% end %>

View File

@@ -32,7 +32,7 @@
</div>
</div>
<%= render "pools/secondary_links" %>
<%= render "secondary_links" %>
<% content_for(:page_title) do %>
Pool Version Comparison - <%= @pool_version.name %> - <%= Danbooru.config.app_name %>

View File

@@ -8,4 +8,4 @@
</div>
</div>
<%= render "pools/secondary_links" %>
<%= render "secondary_links" %>

View File

@@ -0,0 +1,19 @@
<div id="c-pool-versions">
<div id="a-search">
<h1>Search Changes</h1>
<%= search_form_for(pool_versions_path) do |f| %>
<%= f.input :updater_name, label: "Updater", input_html: { value: params.dig(:search, :updater_name), "data-autocomplete": "user" } %>
<%= f.input :name_matches, label: "Pool", input_html: { value: params.dig(:search, :name_matches), "data-autocomplete": "pool" } %>
<%= f.input :category, label: "Category", collection: [["Series", "series"], ["Collection", "collection"]], include_blank: true %>
<%= f.input :is_new, label: "New?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<%= f.input :name_changed, label: "Name changed?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<%= f.input :description_changed, label: "Description changed?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<%= f.input :is_active, label: "Active?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<%= f.input :is_banned, label: "Deleted?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -191,6 +191,9 @@ Rails.application.routes.draw do
member do
get :diff
end
collection do
get :search
end
end
resources :post_replacements, :only => [:index, :new, :create, :update]
resources :post_votes, only: [:index]