diff --git a/app/assets/stylesheets/specific/meta_searches.css.scss b/app/assets/stylesheets/specific/meta_searches.css.scss new file mode 100644 index 000000000..98133734d --- /dev/null +++ b/app/assets/stylesheets/specific/meta_searches.css.scss @@ -0,0 +1,5 @@ +#c-meta-searches { + section { + margin-bottom: 2em; + } +} \ No newline at end of file diff --git a/app/controllers/meta_searches_controller.rb b/app/controllers/meta_searches_controller.rb new file mode 100644 index 000000000..c9fd25126 --- /dev/null +++ b/app/controllers/meta_searches_controller.rb @@ -0,0 +1,6 @@ +class MetaSearchesController < ApplicationController + def tags + @meta_search = MetaSearches::Tag.new(params) + @meta_search.load_all + end +end diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index 67106a213..96a55ff8f 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -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]) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2bbb33d59..c9083bc78 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -139,7 +139,7 @@ protected when "artists", "artist_versions" /^\/artist/ - when "tags" + when "tags", "meta_searches" /^\/tags/ when "pools", "pool_versions" diff --git a/app/logical/meta_searches/tag.rb b/app/logical/meta_searches/tag.rb new file mode 100644 index 000000000..46eec97d3 --- /dev/null +++ b/app/logical/meta_searches/tag.rb @@ -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 diff --git a/app/views/meta_searches/tags.html.erb b/app/views/meta_searches/tags.html.erb new file mode 100644 index 000000000..21a3bffb3 --- /dev/null +++ b/app/views/meta_searches/tags.html.erb @@ -0,0 +1,129 @@ +
+
+

MetaSearch Tags

+ +
+ <%= form_tag(meta_searches_tags_path, :method => :get) do %> + <%= text_field_tag "name", params[:name] %> + <%= submit_tag "Go" %> + <% end %> +
+ +
+

Tags

+ + <% if @meta_search.tags.empty? %> +

No results

+ <% else %> + + + + + + + + + + + <% @meta_search.tags.each do |tag| %> + + + + + + <% end %> + +
NameCount
<%= tag.name %><%= tag.post_count %> + <% 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 %> +
+ <% end %> +
+ + +
+

Tag Aliases

+ <% if @meta_search.tag_aliases.empty? %> +

No results

+ <% else %> + + + + + + + + + + + <% @meta_search.tag_aliases.each do |tag_alias| %> + + + + + + <% end %> + +
FromTo
<%= tag_alias.antecedent_name %><%= tag_alias.consequent_name %> + <%= 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 %> +
+ <% end %> +
+ +
+

Tag Implications

+ <% if @meta_search.tag_implications.empty? %> +

No results

+ <% else %> + + + + + + + + + + + <% @meta_search.tag_implications.each do |tag_implication| %> + + + + + + <% end %> + +
FromTo
<%= tag_implication.antecedent_name %><%= tag_implication.consequent_name %> + <%= 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 %> +
+ <% end %> +
+
+
+ +<%= render "tags/secondary_links" %> + +<% content_for(:page_title) do %> + MetaSearch - Tags - <%= Danbooru.config.app_name %> +<% end %> \ No newline at end of file diff --git a/app/views/tag_aliases/_secondary_links.html.erb b/app/views/tag_aliases/_secondary_links.html.erb index b7fc8f59c..663069a99 100644 --- a/app/views/tag_aliases/_secondary_links.html.erb +++ b/app/views/tag_aliases/_secondary_links.html.erb @@ -1,6 +1,7 @@ <% content_for(:secondary_links) do %>
  • <%= link_to "Listing", tag_aliases_path %>
  • +
  • <%= link_to "MetaSearch", meta_searches_tags_path %>
  • <% if CurrentUser.is_admin? %>
  • <%= link_to "New", new_tag_alias_path %>
  • <% else %> diff --git a/app/views/tag_aliases/index.html.erb b/app/views/tag_aliases/index.html.erb index 10f98ca82..6e74c4ad6 100644 --- a/app/views/tag_aliases/index.html.erb +++ b/app/views/tag_aliases/index.html.erb @@ -1,10 +1,9 @@
    diff --git a/app/views/tag_implications/_secondary_links.html.erb b/app/views/tag_implications/_secondary_links.html.erb index 77351b538..aafe29969 100644 --- a/app/views/tag_implications/_secondary_links.html.erb +++ b/app/views/tag_implications/_secondary_links.html.erb @@ -1,6 +1,7 @@ <% content_for(:secondary_links) do %>
  • <%= link_to "Listing", tag_implications_path %>
  • +
  • <%= link_to "MetaSearch", meta_searches_tags_path %>
  • <% if CurrentUser.is_admin? %>
  • <%= link_to "New", new_tag_implication_path %>
  • <% else %> diff --git a/app/views/tag_implications/index.html.erb b/app/views/tag_implications/index.html.erb index 6c018da22..46e54abe5 100644 --- a/app/views/tag_implications/index.html.erb +++ b/app/views/tag_implications/index.html.erb @@ -1,10 +1,9 @@
    diff --git a/app/views/tags/_secondary_links.html.erb b/app/views/tags/_secondary_links.html.erb index 672a295a4..854f4eff6 100644 --- a/app/views/tags/_secondary_links.html.erb +++ b/app/views/tags/_secondary_links.html.erb @@ -2,8 +2,7 @@
  • <%= render "tags/quick_search" %>
  • <%= link_to "Listing", tags_path %>
  • -
  • <%= link_to "Aliases", tag_aliases_path %>
  • -
  • <%= link_to "Implications", tag_implications_path %>
  • +
  • <%= link_to "MetaSearch", meta_searches_tags_path %>
  • <%= link_to "Cheatsheet", wiki_pages_path(:search => {:title => "help:cheatsheet"}) %>
  • <%= link_to "Help", wiki_pages_path(:search => {:title => "help:tags"}) %>
  • <% if @tag %> diff --git a/config/routes.rb b/config/routes.rb index e2cb274d9..dc85c2382 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/unit/meta_searches/tag_test.rb b/test/unit/meta_searches/tag_test.rb new file mode 100644 index 000000000..fdb5b8a02 --- /dev/null +++ b/test/unit/meta_searches/tag_test.rb @@ -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