mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
committed by
GitHub
parent
78723345c0
commit
9cabd3721b
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user