mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
work in progress wide category list
This commit is contained in:
@@ -8,10 +8,11 @@ class CategoryList
|
||||
:draft_key,
|
||||
:draft_sequence
|
||||
|
||||
def initialize(guardian=nil)
|
||||
def initialize(guardian=nil, options = {})
|
||||
@guardian = guardian || Guardian.new
|
||||
@options = options
|
||||
|
||||
find_relevant_topics
|
||||
find_relevant_topics unless latest_post_only?
|
||||
find_categories
|
||||
|
||||
prune_empty
|
||||
@@ -21,6 +22,10 @@ class CategoryList
|
||||
|
||||
private
|
||||
|
||||
def latest_post_only?
|
||||
@options[:latest_post_only]
|
||||
end
|
||||
|
||||
# Retrieve a list of all the topics we'll need
|
||||
def find_relevant_topics
|
||||
@topics_by_category_id = {}
|
||||
@@ -47,16 +52,35 @@ class CategoryList
|
||||
.order('COALESCE(categories.topics_month, 0) DESC')
|
||||
.order('COALESCE(categories.topics_year, 0) DESC')
|
||||
|
||||
if latest_post_only?
|
||||
@categories = @categories.includes(:latest_post => :topic )
|
||||
end
|
||||
|
||||
@categories = @categories.to_a
|
||||
@categories.each do |c|
|
||||
topics_in_cat = @topics_by_category_id[c.id]
|
||||
if topics_in_cat.present?
|
||||
c.displayable_topics = []
|
||||
topics_in_cat.each do |topic_id|
|
||||
topic = @topics_by_id[topic_id]
|
||||
if topic.present?
|
||||
topic.category = c
|
||||
c.displayable_topics << topic
|
||||
|
||||
if latest_post_only?
|
||||
@all_topics = []
|
||||
@categories.each do |c|
|
||||
if c.latest_post && c.latest_post.topic
|
||||
c.displayable_topics = [c.latest_post.topic]
|
||||
topic = c.latest_post.topic
|
||||
topic.include_last_poster = true # hint for serialization
|
||||
@all_topics << topic
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @topics_by_category_id
|
||||
@categories.each do |c|
|
||||
topics_in_cat = @topics_by_category_id[c.id]
|
||||
if topics_in_cat.present?
|
||||
c.displayable_topics = []
|
||||
topics_in_cat.each do |topic_id|
|
||||
topic = @topics_by_id[topic_id]
|
||||
if topic.present?
|
||||
topic.category = c
|
||||
c.displayable_topics << topic
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user