related tags: add AI tags to related tags section.
Add a Suggested tags list to the Related Tags box. The suggested tags are just the AI tags for the post. Suggested tags are currently hidden in CSS for beta testing. Use custom CSS to unhide them.
This commit is contained in:
@@ -8,8 +8,9 @@ class RelatedTagsController < ApplicationController
|
||||
category = params[:category] || search_params[:category]
|
||||
type = params[:type] || search_params[:type]
|
||||
limit = params[:limit]
|
||||
media_asset = MediaAsset.find(params[:media_asset_id]) if params[:media_asset_id].present?
|
||||
|
||||
@query = RelatedTagQuery.new(query: query, category: category, type: type, user: CurrentUser.user, limit: limit)
|
||||
@query = RelatedTagQuery.new(query: query, media_asset: media_asset, category: category, type: type, user: CurrentUser.user, limit: limit)
|
||||
respond_with(@query)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,7 +27,8 @@ RelatedTag.initialize_all = function() {
|
||||
}
|
||||
|
||||
RelatedTag.initialize_recent_and_favorite_tags = function(event) {
|
||||
$.get("/related_tag.js", { user_tags: true });
|
||||
let media_asset_id = $("#related-tags-container").attr("data-media-asset-id");
|
||||
$.get("/related_tag.js", { user_tags: true, media_asset_id: media_asset_id });
|
||||
}
|
||||
|
||||
RelatedTag.on_click_related_tags_button = function (event) {
|
||||
|
||||
@@ -6,12 +6,13 @@ class RelatedTagQuery
|
||||
include ActiveModel::Serializers::JSON
|
||||
include ActiveModel::Serializers::Xml
|
||||
|
||||
attr_reader :query, :post_query, :category, :type, :user, :limit
|
||||
attr_reader :query, :post_query, :media_asset, :category, :type, :user, :limit
|
||||
|
||||
def initialize(query:, user: User.anonymous, category: nil, type: nil, limit: nil)
|
||||
def initialize(query:, media_asset: nil, user: User.anonymous, category: nil, type: nil, limit: nil)
|
||||
@user = user
|
||||
@post_query = PostQuery.normalize(query, current_user: user) # XXX This query does not include implicit metatags (rating:s, -status:deleted)
|
||||
@query = @post_query.to_s
|
||||
@media_asset = media_asset
|
||||
@category = category
|
||||
@type = type
|
||||
@limit = (limit =~ /^\d+/ ? limit.to_i : 25)
|
||||
@@ -55,6 +56,11 @@ class RelatedTagQuery
|
||||
@similar_tags ||= RelatedTagCalculator.similar_tags_for_search(post_query, category: category_of).take(limit)
|
||||
end
|
||||
|
||||
def ai_tags
|
||||
return AITag.none if media_asset.nil?
|
||||
media_asset.ai_tags.joins(:tag).undeprecated.nonempty.in_order_of(:"tags.category", TagCategory.canonical_mapping.values).order("ai_tags.score DESC, tags.name ASC").take(limit)
|
||||
end
|
||||
|
||||
# Returns the top 20 most frequently added tags within the last 20 edits made by the user in the last hour.
|
||||
def recent_tags(since: 1.hour.ago, max_edits: 20, max_tags: 20)
|
||||
return [] unless user.present? && PostVersion.enabled?
|
||||
|
||||
@@ -9,6 +9,13 @@ class AITag < ApplicationRecord
|
||||
|
||||
validates :score, inclusion: { in: (0..100) }
|
||||
|
||||
scope :deprecated, -> { where(tag: Tag.deprecated) }
|
||||
scope :undeprecated, -> { where(tag: Tag.undeprecated) }
|
||||
scope :empty, -> { where(tag: Tag.empty) }
|
||||
scope :nonempty, -> { where(tag: Tag.nonempty) }
|
||||
|
||||
delegate :name, :pretty_name, :post_count, :category, :category_name, to: :tag
|
||||
|
||||
def self.named(name)
|
||||
name = $1.downcase if name =~ /\A(rating:.)/i
|
||||
where(tag: Tag.find_by_name_or_alias(name))
|
||||
|
||||
@@ -49,5 +49,5 @@
|
||||
<%= f.submit "Submit" %>
|
||||
</div>
|
||||
|
||||
<%= render "related_tags/container" %>
|
||||
<%= render "related_tags/container", media_asset: post.media_asset %>
|
||||
<% end %>
|
||||
|
||||
18
app/views/related_tags/_ai_tags_column.html.erb
Normal file
18
app/views/related_tags/_ai_tags_column.html.erb
Normal file
@@ -0,0 +1,18 @@
|
||||
<div class="tag-column ai-tags-related-tags-column hidden">
|
||||
<h3 class="flex items-center space-x-1">
|
||||
<input type="checkbox" class="invisible">
|
||||
<span>Suggested</span>
|
||||
</h3>
|
||||
|
||||
<ul class="tag-list simple-tag-list">
|
||||
<% ai_tags.each do |t| %>
|
||||
<li class="flex items-center space-x-1">
|
||||
<input type="checkbox" tabindex="-1">
|
||||
<span>
|
||||
<%= link_to t.pretty_name, posts_path(tags: t.name), class: "search-tag tag-type-#{t.category}", "data-tag-name": t.name %>
|
||||
<%= tag.span "#{t.score}%", class: "text-muted text-xs" %>
|
||||
</span>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -1,4 +1,4 @@
|
||||
<div id="related-tags-container" class="visible">
|
||||
<div id="related-tags-container" class="visible" data-media-asset-id="<%= media_asset.id %>">
|
||||
<h3>
|
||||
Related Tags
|
||||
<a href="#" id="show-related-tags-link">»</a>
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
<% if related_tags.present? %>
|
||||
<%= render "related_tags/tag_column", tags: related_tags.recent_tags, class: "recent-related-tags-column", title: "Recent" %>
|
||||
<%= render "related_tags/tag_column", tags: related_tags.favorite_tags, class: "frequent-related-tags-column", title: "Frequent" %>
|
||||
<%= render "related_tags/ai_tags_column", ai_tags: related_tags.ai_tags %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -92,6 +92,6 @@
|
||||
<%= f.input :is_pending, as: :boolean, label: "Upload for approval", wrapper_html: { class: "inline-block" }, input_html: { checked: post.is_pending? } %>
|
||||
<% end %>
|
||||
|
||||
<%= render "related_tags/container" %>
|
||||
<%= render "related_tags/container", media_asset: media_asset %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user