work in progress wide category list

This commit is contained in:
Sam
2013-10-17 17:44:56 +11:00
parent 7bf96ee690
commit 1ee49798b2
17 changed files with 200 additions and 25 deletions

View File

@@ -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