/related_tag: convert to table builder.
This commit is contained in:
@@ -18,11 +18,11 @@ class RelatedTagQuery
|
||||
if query =~ /\*/
|
||||
pattern_matching_tags
|
||||
elsif category.present?
|
||||
RelatedTagCalculator.frequent_tags_for_search(query, category: Tag.categories.value_for(category)).take(25).pluck(:name)
|
||||
RelatedTagCalculator.frequent_tags_for_search(query, category: Tag.categories.value_for(category)).take(25)
|
||||
elsif query.present?
|
||||
RelatedTagCalculator.similar_tags_for_search(query).take(25).map(&:name)
|
||||
RelatedTagCalculator.similar_tags_for_search(query).take(25)
|
||||
else
|
||||
[]
|
||||
Tag.none
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,15 +54,11 @@ class RelatedTagQuery
|
||||
other_wikis
|
||||
end
|
||||
|
||||
def tags_for_html
|
||||
tags_with_categories(tags)
|
||||
end
|
||||
|
||||
def serializable_hash(**options)
|
||||
{
|
||||
query: query,
|
||||
category: category,
|
||||
tags: tags_with_categories(tags),
|
||||
tags: tags_with_categories(tags.map(&:name)),
|
||||
wiki_page_tags: tags_with_categories(wiki_page_tags),
|
||||
other_wikis: other_wiki_pages.map { |wiki| [wiki.title, tags_with_categories(wiki.tags)] }.to_h
|
||||
}
|
||||
@@ -75,7 +71,7 @@ class RelatedTagQuery
|
||||
end
|
||||
|
||||
def pattern_matching_tags
|
||||
Tag.name_matches(query).where("post_count > 0").order("post_count desc").limit(50).sort_by {|x| x.name}.map(&:name)
|
||||
Tag.nonempty.name_matches(query).order("post_count desc, name asc").limit(50)
|
||||
end
|
||||
|
||||
def wiki_page
|
||||
|
||||
@@ -9,26 +9,13 @@
|
||||
<% end %>
|
||||
|
||||
<% if params.dig(:search, :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_wiki "?", tag %>
|
||||
<%= link_to(tag, posts_path(:tags => tag)) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<% end %>
|
||||
<%= table_for @query.tags do |t| %>
|
||||
<% t.column "Name" do |tag| %>
|
||||
<%= link_to_wiki "?", tag.name, class: "tag-type-#{tag.category}" %>
|
||||
<%= link_to tag.name, posts_path(tags: tag.name), class: "tag-type-#{tag.category}" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "work" do
|
||||
assert_equal(["aaa", "bbb", "ccc"], @query.tags)
|
||||
assert_equal(["aaa", "bbb", "ccc"], @query.tags.map(&:name))
|
||||
end
|
||||
|
||||
should "render the json" do
|
||||
@@ -51,7 +51,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "work" do
|
||||
assert_equal([], @query.tags)
|
||||
assert_equal(true, @query.tags.empty?)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -68,7 +68,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "take related tags from the consequent tag" do
|
||||
assert_equal(%w[aaa bbb ccc], @query.tags)
|
||||
assert_equal(%w[aaa bbb ccc], @query.tags.map(&:name))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,7 +78,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "work" do
|
||||
assert_equal(["aaa"], @query.tags)
|
||||
assert_equal(["aaa"], @query.tags.map(&:name))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -118,7 +118,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "find the related tags" do
|
||||
assert_equal(%w(ccc), @query.tags)
|
||||
assert_equal(["ccc"], @query.tags.map(&:name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user