fixes #1227
This commit is contained in:
5
app/assets/stylesheets/specific/meta_searches.css.scss
Normal file
5
app/assets/stylesheets/specific/meta_searches.css.scss
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#c-meta-searches {
|
||||||
|
section {
|
||||||
|
margin-bottom: 2em;
|
||||||
|
}
|
||||||
|
}
|
||||||
6
app/controllers/meta_searches_controller.rb
Normal file
6
app/controllers/meta_searches_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class MetaSearchesController < ApplicationController
|
||||||
|
def tags
|
||||||
|
@meta_search = MetaSearches::Tag.new(params)
|
||||||
|
@meta_search.load_all
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -12,14 +12,6 @@ class TagAliasesController < ApplicationController
|
|||||||
respond_with(@tag_alias)
|
respond_with(@tag_alias)
|
||||||
end
|
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
|
def index
|
||||||
@search = TagAlias.search(params[:search])
|
@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])
|
@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])
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ protected
|
|||||||
when "artists", "artist_versions"
|
when "artists", "artist_versions"
|
||||||
/^\/artist/
|
/^\/artist/
|
||||||
|
|
||||||
when "tags"
|
when "tags", "meta_searches"
|
||||||
/^\/tags/
|
/^\/tags/
|
||||||
|
|
||||||
when "pools", "pool_versions"
|
when "pools", "pool_versions"
|
||||||
|
|||||||
30
app/logical/meta_searches/tag.rb
Normal file
30
app/logical/meta_searches/tag.rb
Normal 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
|
||||||
129
app/views/meta_searches/tags.html.erb
Normal file
129
app/views/meta_searches/tags.html.erb
Normal 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 %>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<% content_for(:secondary_links) do %>
|
<% content_for(:secondary_links) do %>
|
||||||
<menu>
|
<menu>
|
||||||
<li><%= link_to "Listing", tag_aliases_path %></li>
|
<li><%= link_to "Listing", tag_aliases_path %></li>
|
||||||
|
<li><%= link_to "MetaSearch", meta_searches_tags_path %></li>
|
||||||
<% if CurrentUser.is_admin? %>
|
<% if CurrentUser.is_admin? %>
|
||||||
<li><%= link_to "New", new_tag_alias_path %></li>
|
<li><%= link_to "New", new_tag_alias_path %></li>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
<div id="c-tag-aliases">
|
<div id="c-tag-aliases">
|
||||||
<div id="a-index">
|
<div id="a-index">
|
||||||
<div class="search">
|
<div class="search">
|
||||||
<%= form_tag(general_search_tag_aliases_path, :method => :get) do %>
|
<%= form_tag(tag_aliases_path, :method => :get) do %>
|
||||||
<%= text_field_tag "query", params[:query], :value => params[:search][:name_matches] %>
|
<%= text_field :search, :name_matches, :value => params[:search][:name_matches] %>
|
||||||
<%= submit_tag "Search Aliases" %>
|
<%= submit_tag "Search" %>
|
||||||
<%= submit_tag "Search Implications" %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<% content_for(:secondary_links) do %>
|
<% content_for(:secondary_links) do %>
|
||||||
<menu>
|
<menu>
|
||||||
<li><%= link_to "Listing", tag_implications_path %></li>
|
<li><%= link_to "Listing", tag_implications_path %></li>
|
||||||
|
<li><%= link_to "MetaSearch", meta_searches_tags_path %></li>
|
||||||
<% if CurrentUser.is_admin? %>
|
<% if CurrentUser.is_admin? %>
|
||||||
<li><%= link_to "New", new_tag_implication_path %></li>
|
<li><%= link_to "New", new_tag_implication_path %></li>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
<div id="c-tag-implications">
|
<div id="c-tag-implications">
|
||||||
<div id="a-index">
|
<div id="a-index">
|
||||||
<div class="search">
|
<div class="search">
|
||||||
<%= form_tag(general_search_tag_aliases_path, :method => :get) do %>
|
<%= form_tag(tag_implications_path, :method => :get) do %>
|
||||||
<%= text_field_tag "query", params[:query], :value => params[:search][:name_matches] %>
|
<%= text_field :search, :name_matches, :value => params[:search][:name_matches] %>
|
||||||
<%= submit_tag "Search Implications" %>
|
<%= submit_tag "Search" %>
|
||||||
<%= submit_tag "Search Aliases" %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
<menu>
|
<menu>
|
||||||
<li><%= render "tags/quick_search" %></li>
|
<li><%= render "tags/quick_search" %></li>
|
||||||
<li><%= link_to "Listing", tags_path %></li>
|
<li><%= link_to "Listing", tags_path %></li>
|
||||||
<li><%= link_to "Aliases", tag_aliases_path %></li>
|
<li><%= link_to "MetaSearch", meta_searches_tags_path %></li>
|
||||||
<li><%= link_to "Implications", tag_implications_path %></li>
|
|
||||||
<li><%= link_to "Cheatsheet", wiki_pages_path(:search => {:title => "help:cheatsheet"}) %></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>
|
<li><%= link_to "Help", wiki_pages_path(:search => {:title => "help:tags"}) %></li>
|
||||||
<% if @tag %>
|
<% if @tag %>
|
||||||
|
|||||||
@@ -202,9 +202,6 @@ Danbooru::Application.routes.draw do
|
|||||||
member do
|
member do
|
||||||
post :approve
|
post :approve
|
||||||
end
|
end
|
||||||
collection do
|
|
||||||
get :general_search
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
resource :tag_alias_request, :only => [:new, :create]
|
resource :tag_alias_request, :only => [:new, :create]
|
||||||
resources :tag_implications do
|
resources :tag_implications do
|
||||||
@@ -370,6 +367,7 @@ Danbooru::Application.routes.draw do
|
|||||||
match "/static/contact" => "static#contact", :as => "contact"
|
match "/static/contact" => "static#contact", :as => "contact"
|
||||||
match "/static/benchmark" => "static#benchmark"
|
match "/static/benchmark" => "static#benchmark"
|
||||||
match "/static/name_change" => "static#name_change", :as => "name_change"
|
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"
|
root :to => "posts#index"
|
||||||
end
|
end
|
||||||
|
|||||||
36
test/unit/meta_searches/tag_test.rb
Normal file
36
test/unit/meta_searches/tag_test.rb
Normal 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
|
||||||
Reference in New Issue
Block a user