FEATURE: ability to add description to tags (#15125)

Ability to add description to tags, which will be displayed on hover.
This commit is contained in:
Krzysztof Kotlarek
2021-12-01 09:18:56 +11:00
committed by GitHub
parent 78723345c0
commit 9cabd3721b
23 changed files with 190 additions and 85 deletions

View File

@@ -3,6 +3,7 @@
module TopicTagsMixin
def self.included(klass)
klass.attributes :tags
klass.attributes :tags_descriptions
end
def include_tags?
@@ -10,16 +11,26 @@ module TopicTagsMixin
end
def tags
# Calling method `pluck` or `order` along with `includes` causing N+1 queries
tags = (SiteSetting.tags_sort_alphabetically ? topic.tags.sort_by(&:name) : topic.tags.sort_by(&:topic_count).reverse).map(&:name)
if scope.is_staff?
tags
else
tags - scope.hidden_tag_names
end
all_tags.map(&:name)
end
def tags_descriptions
all_tags.each.with_object({}) { |tag, acc| acc[tag.name] = tag.description }.compact
end
def topic
object.is_a?(Topic) ? object : object.topic
end
private
def all_tags
return @tags if defined?(@tags)
# Calling method `pluck` or `order` along with `includes` causing N+1 queries
tags = (SiteSetting.tags_sort_alphabetically ? topic.tags.sort_by(&:name) : topic.tags.sort_by(&:topic_count).reverse)
if !scope.is_staff?
tags = tags.reject { |tag| scope.hidden_tag_names.include?(tag[:name]) }
end
@tags = tags
end
end