This commit is contained in:
r888888888
2014-02-28 16:40:04 -08:00
parent 5d5caf5eea
commit 1f10f39d1e
13 changed files with 217 additions and 22 deletions

View File

@@ -0,0 +1,5 @@
#c-meta-searches {
section {
margin-bottom: 2em;
}
}

View File

@@ -0,0 +1,6 @@
class MetaSearchesController < ApplicationController
def tags
@meta_search = MetaSearches::Tag.new(params)
@meta_search.load_all
end
end

View File

@@ -12,14 +12,6 @@ class TagAliasesController < ApplicationController
respond_with(@tag_alias)
end
def general_search
if params[:commit] == "Search Aliases"
redirect_to tag_aliases_path(:search => {:name_matches => params[:query]})
else
redirect_to tag_implications_path(:search => {:name_matches => params[:query]})
end
end
def index
@search = TagAlias.search(params[:search])
@tag_aliases = @search.order("(case status when 'pending' then 0 when 'queued' then 1 else 2 end), antecedent_name, consequent_name").paginate(params[:page], :limit => params[:limit])

View File

@@ -139,7 +139,7 @@ protected
when "artists", "artist_versions"
/^\/artist/
when "tags"
when "tags", "meta_searches"
/^\/tags/
when "pools", "pool_versions"

View File

@@ -0,0 +1,30 @@
class MetaSearches::Tag
MAX_RESULTS = 25
attr_reader :search_params, :tags, :tag_aliases, :tag_implications
def initialize(search_params)
@search_params = search_params
end
def load_all
load_tags
load_tag_aliases
load_tag_implications
end
def load_tags
@tags = ::Tag.name_matches(name_param).limit(MAX_RESULTS)
end
def load_tag_aliases
@tag_aliases = TagAlias.name_matches(name_param).limit(MAX_RESULTS)
end
def load_tag_implications
@tag_implications = TagImplication.name_matches(name_param).limit(MAX_RESULTS)
end
def name_param
search_params[:name] || ""
end
end

View File

@@ -0,0 +1,129 @@
<div id="c-meta-searches">
<div id="a-tags">
<h1>MetaSearch Tags</h1>
<section>
<%= form_tag(meta_searches_tags_path, :method => :get) do %>
<%= text_field_tag "name", params[:name] %>
<%= submit_tag "Go" %>
<% end %>
</section>
<section>
<h2>Tags</h2>
<% if @meta_search.tags.empty? %>
<p>No results</p>
<% else %>
<table width="100%" class="striped">
<thead>
<tr>
<th>Name</th>
<th>Count</th>
<th></th>
</tr>
</thead>
<tbody>
<% @meta_search.tags.each do |tag| %>
<tr>
<td><%= tag.name %></td>
<td><%= tag.post_count %></td>
<td>
<% if tag.editable_by?(CurrentUser.user) %>
<%= link_to "edit", edit_tag_path(tag) %>
<% end %>
<% if CurrentUser.is_builder? %>
| <%= link_to "fix", new_tag_correction_path(:tag_id => tag.id) %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</section>
<section>
<h2>Tag Aliases</h2>
<% if @meta_search.tag_aliases.empty? %>
<p>No results</p>
<% else %>
<table width="100%" class="striped">
<thead>
<tr>
<th>From</th>
<th>To</th>
<th></th>
</tr>
</thead>
<tbody>
<% @meta_search.tag_aliases.each do |tag_alias| %>
<tr>
<td><%= tag_alias.antecedent_name %></td>
<td><%= tag_alias.consequent_name %></td>
<td>
<%= link_to "Show", tag_alias_path(tag_alias) %>
<% if tag_alias.deletable_by?(CurrentUser.user) %>
| <%= link_to "Delete", tag_alias_path(tag_alias), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this alias?" %>
<% end %>
<% if CurrentUser.is_admin? && tag_alias.is_pending? %>
| <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %>
<% end %>
<% if CurrentUser.is_janitor? %>
| <%= link_to "Fix", tag_alias_correction_path(:tag_alias_id => tag_alias.id) %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</section>
<section>
<h2>Tag Implications</h2>
<% if @meta_search.tag_implications.empty? %>
<p>No results</p>
<% else %>
<table width="100%" class="striped">
<thead>
<tr>
<th>From</th>
<th>To</th>
<th></th>
</tr>
</thead>
<tbody>
<% @meta_search.tag_implications.each do |tag_implication| %>
<tr>
<td><%= tag_implication.antecedent_name %></td>
<td><%= tag_implication.consequent_name %></td>
<td>
<%= link_to "Show", tag_implication_path(tag_implication) %>
<% if tag_implication.deletable_by?(CurrentUser.user) %>
| <%= link_to "Delete", tag_implication_path(tag_implication), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this implication?" %>
<% end %>
<% if CurrentUser.user.is_admin? && tag_implication.is_pending? %>
| <%= link_to "Approve", approve_tag_implication_path(tag_implication), :remote => true, :method => :post %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</section>
</div>
</div>
<%= render "tags/secondary_links" %>
<% content_for(:page_title) do %>
MetaSearch - Tags - <%= Danbooru.config.app_name %>
<% end %>

View File

@@ -1,6 +1,7 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Listing", tag_aliases_path %></li>
<li><%= link_to "MetaSearch", meta_searches_tags_path %></li>
<% if CurrentUser.is_admin? %>
<li><%= link_to "New", new_tag_alias_path %></li>
<% else %>

View File

@@ -1,10 +1,9 @@
<div id="c-tag-aliases">
<div id="a-index">
<div class="search">
<%= form_tag(general_search_tag_aliases_path, :method => :get) do %>
<%= text_field_tag "query", params[:query], :value => params[:search][:name_matches] %>
<%= submit_tag "Search Aliases" %>
<%= submit_tag "Search Implications" %>
<%= form_tag(tag_aliases_path, :method => :get) do %>
<%= text_field :search, :name_matches, :value => params[:search][:name_matches] %>
<%= submit_tag "Search" %>
<% end %>
</div>

View File

@@ -1,6 +1,7 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Listing", tag_implications_path %></li>
<li><%= link_to "MetaSearch", meta_searches_tags_path %></li>
<% if CurrentUser.is_admin? %>
<li><%= link_to "New", new_tag_implication_path %></li>
<% else %>

View File

@@ -1,10 +1,9 @@
<div id="c-tag-implications">
<div id="a-index">
<div class="search">
<%= form_tag(general_search_tag_aliases_path, :method => :get) do %>
<%= text_field_tag "query", params[:query], :value => params[:search][:name_matches] %>
<%= submit_tag "Search Implications" %>
<%= submit_tag "Search Aliases" %>
<%= form_tag(tag_implications_path, :method => :get) do %>
<%= text_field :search, :name_matches, :value => params[:search][:name_matches] %>
<%= submit_tag "Search" %>
<% end %>
</div>

View File

@@ -2,8 +2,7 @@
<menu>
<li><%= render "tags/quick_search" %></li>
<li><%= link_to "Listing", tags_path %></li>
<li><%= link_to "Aliases", tag_aliases_path %></li>
<li><%= link_to "Implications", tag_implications_path %></li>
<li><%= link_to "MetaSearch", meta_searches_tags_path %></li>
<li><%= link_to "Cheatsheet", wiki_pages_path(:search => {:title => "help:cheatsheet"}) %></li>
<li><%= link_to "Help", wiki_pages_path(:search => {:title => "help:tags"}) %></li>
<% if @tag %>

View File

@@ -202,9 +202,6 @@ Danbooru::Application.routes.draw do
member do
post :approve
end
collection do
get :general_search
end
end
resource :tag_alias_request, :only => [:new, :create]
resources :tag_implications do
@@ -370,6 +367,7 @@ Danbooru::Application.routes.draw do
match "/static/contact" => "static#contact", :as => "contact"
match "/static/benchmark" => "static#benchmark"
match "/static/name_change" => "static#name_change", :as => "name_change"
match "/meta_searches/tags" => "meta_searches#tags", :as => "meta_searches_tags"
root :to => "posts#index"
end

View File

@@ -0,0 +1,36 @@
require "test_helper"
module MetaSearches
class TagTest < ActionMailer::TestCase
context "The tag metasearcg" do
setup do
CurrentUser.user = FactoryGirl.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
FactoryGirl.create(:tag, :name => "xxx")
FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
end
should "find the tag" do
meta_search = Tag.new(:name => "xxx")
meta_search.load_all
assert_equal(1, meta_search.tags.size)
assert_equal("xxx", meta_search.tags.first.name)
end
should "find the alias" do
meta_search = Tag.new(:name => "aaa")
meta_search.load_all
assert_equal(1, meta_search.tag_aliases.size)
assert_equal("aaa", meta_search.tag_aliases.first.antecedent_name)
end
should "find the implication" do
meta_search = Tag.new(:name => "ccc")
meta_search.load_all
assert_equal(1, meta_search.tag_implications.size)
assert_equal("ccc", meta_search.tag_implications.first.antecedent_name)
end
end
end
end