Simple HTML page and form for related tags

This commit is contained in:
Type-kun
2017-01-09 19:18:18 +05:00
parent 49a72e4bf6
commit 7c98c60129
4 changed files with 43 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
class RelatedTagsController < ApplicationController
respond_to :json
respond_to :html, :only=>[:show]
before_filter :require_reportbooru_key, only: [:update]
def show

View File

@@ -26,6 +26,10 @@ class RelatedTagQuery
results
end
def tags_for_html
map_with_category_data(tags)
end
def to_json
{:query => query, :category => category, :tags => map_with_category_data(tags), :wiki_page_tags => map_with_category_data(wiki_page_tags)}.to_json
end

View File

@@ -0,0 +1,37 @@
<div>
<h1>Related tags</h1>
<section>
<%= form_tag(related_tag_path, :method => :get) do %>
<%= text_field_tag "query", params[:query] %>
<%= select_tag "category", options_for_select([""] + Danbooru.config.canonical_tag_category_mapping.map{|x| [x.first, x.first.downcase]}, params[:category]) %>
<%= submit_tag "Show"%>
<% end %>
</section>
<% if params[:query].present? %>
<section>
<table class="striped">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<% @query.tags_for_html.each do |tag, category| %>
<tr>
<td class="category-<%= category %>">
<%= link_to("?", show_or_new_wiki_pages_path(:title => tag)) %>
<%= link_to(tag, posts_path(:tags => tag)) %>
</td>
</tr>
<% end %>
</tbody>
</table>
</section>
<% end %>
</div>
<%= render "tags/secondary_links" %>
<% content_for(:page_title) do %>
Related tags - <%= Danbooru.config.app_name %>
<% end %>

View File

@@ -3,6 +3,7 @@
<li><%= render "tags/quick_search" %></li>
<li><%= link_to "Listing", tags_path %></li>
<li><%= link_to "MetaSearch", meta_searches_tags_path %></li>
<li><%= link_to "Related tags", related_tag_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 %>