BUGFIX: correctly auto-select /top time range when filtering on a category
This commit is contained in:
parent
b232736242
commit
3fde28e108
|
@ -314,7 +314,7 @@ class ListController < ApplicationController
|
||||||
topic_query = TopicQuery.new(current_user, options)
|
topic_query = TopicQuery.new(current_user, options)
|
||||||
|
|
||||||
if current_user.present?
|
if current_user.present?
|
||||||
periods = [ListController.best_period_for(current_user.previous_visit_at)]
|
periods = [ListController.best_period_for(current_user.previous_visit_at, options[:category])]
|
||||||
else
|
else
|
||||||
periods = TopTopic.periods
|
periods = TopTopic.periods
|
||||||
end
|
end
|
||||||
|
@ -324,9 +324,13 @@ class ListController < ApplicationController
|
||||||
top
|
top
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.best_period_for(previous_visit_at)
|
def self.best_period_for(previous_visit_at, category_id=nil)
|
||||||
ListController.best_periods_for(previous_visit_at).each do |period|
|
best_periods_for(previous_visit_at).each do |period|
|
||||||
return period if TopTopic.where("#{period}_score > 0").count >= SiteSetting.topics_per_period_in_top_page
|
top_topics = TopTopic.where("#{period}_score > 0")
|
||||||
|
if category_id
|
||||||
|
top_topics = top_topics.joins(:topic).where("topics.category_id = ?", category_id)
|
||||||
|
end
|
||||||
|
return period if top_topics.count >= SiteSetting.topics_per_period_in_top_page
|
||||||
end
|
end
|
||||||
# default period is yearly
|
# default period is yearly
|
||||||
:yearly
|
:yearly
|
||||||
|
|
Loading…
Reference in New Issue