diff --git a/app/assets/javascripts/discourse/controllers/discovery_top_controller.js b/app/assets/javascripts/discourse/controllers/discovery_top_controller.js
index 4c95239cc..ff77d8e05 100644
--- a/app/assets/javascripts/discourse/controllers/discovery_top_controller.js
+++ b/app/assets/javascripts/discourse/controllers/discovery_top_controller.js
@@ -1,5 +1,5 @@
/**
- The controller for discoverying "Top" topics
+ The controller for discoverying 'Top' topics
@class DiscoveryTopController
@extends Discourse.Controller
@@ -10,14 +10,14 @@ Discourse.DiscoveryTopController = Discourse.ObjectController.extend({
category: null,
redirectedToTopPageReason: function() {
- // no need for a reason if the default homepage is "top"
- if (Discourse.Utilities.defaultHomepage() === "top") { return null; }
+ // no need for a reason if the default homepage is 'top'
+ if (Discourse.Utilities.defaultHomepage() === 'top') { return null; }
// check if the user is authenticated
if (Discourse.User.current()) {
- if (Discourse.User.currentProp("trust_level") === 0) {
- return I18n.t("filters.top.redirect_reasons.new_user");
- } else if (!Discourse.User.currentProp("hasBeenSeenInTheLastMonth")) {
- return I18n.t("filters.top.redirect_reasons.not_seen_in_a_month");
+ if (Discourse.User.currentProp('trust_level') === 0) {
+ return I18n.t('filters.top.redirect_reasons.new_user');
+ } else if (!Discourse.User.currentProp('hasBeenSeenInTheLastMonth')) {
+ return I18n.t('filters.top.redirect_reasons.not_seen_in_a_month');
}
}
// no reason detected
@@ -27,14 +27,16 @@ Discourse.DiscoveryTopController = Discourse.ObjectController.extend({
hasDisplayedAllTopLists: Em.computed.and('content.yearly', 'content.monthly', 'content.weekly', 'content.daily'),
showMoreUrl: function(period) {
- var url = "", category = this.get("category");
- if (category) { url += category.get("url") + "/l"; }
- url += "/top/" + period;
+ var url = '', category = this.get('category');
+ if (category) {
+ url = '/category/' + Discourse.Category.slugFor(category) + (this.get('noSubcategories') ? '/none' : '') + '/l';
+ }
+ url += '/top/' + period;
return url;
},
- showMoreDailyUrl: function() { return this.showMoreUrl("daily"); }.property("category.url"),
- showMoreWeeklyUrl: function() { return this.showMoreUrl("weekly"); }.property("category.url"),
- showMoreMonthlyUrl: function() { return this.showMoreUrl("monthly"); }.property("category.url"),
- showMoreYearlyUrl: function() { return this.showMoreUrl("yearly"); }.property("category.url"),
+ showMoreDailyUrl: function() { return this.showMoreUrl('daily'); }.property('category', 'noSubcategories'),
+ showMoreWeeklyUrl: function() { return this.showMoreUrl('weekly'); }.property('category', 'noSubcategories'),
+ showMoreMonthlyUrl: function() { return this.showMoreUrl('monthly'); }.property('category', 'noSubcategories'),
+ showMoreYearlyUrl: function() { return this.showMoreUrl('yearly'); }.property('category', 'noSubcategories'),
});
diff --git a/app/assets/javascripts/discourse/routes/discovery_top_routes.js b/app/assets/javascripts/discourse/routes/discovery_top_routes.js
index 54accbc8a..ea34efa8e 100644
--- a/app/assets/javascripts/discourse/routes/discovery_top_routes.js
+++ b/app/assets/javascripts/discourse/routes/discovery_top_routes.js
@@ -1,5 +1,5 @@
/**
- Handles the routes related to "Top"
+ Handles the routes related to 'Top'
@class DiscoveryTopRoute
@extends Discourse.Route
@@ -29,7 +29,7 @@ Discourse.DiscoveryTopRoute = Discourse.Route.extend({
});
/**
- Handles the routes related to "Top" within a category
+ Handles the routes related to 'Top' within a category
@class DiscoveryTopCategoryRoute
@extends Discourse.Route
@@ -44,7 +44,7 @@ Discourse.DiscoveryTopCategoryRoute = Discourse.Route.extend({
afterModel: function(model) {
var self = this,
noSubcategories = this.get('no_subcategories'),
- filterMode = "category/" + Discourse.Category.slugFor(model) + (noSubcategories ? "/none" : "") + "/l/top";
+ filterMode = 'category/' + Discourse.Category.slugFor(model) + (noSubcategories ? '/none' : '') + '/l/top';
this.controllerFor('search').set('searchContext', model);
@@ -70,8 +70,12 @@ Discourse.DiscoveryTopCategoryRoute = Discourse.Route.extend({
var topList = this.get('topList');
var filterText = I18n.t('filters.top.title');
Discourse.set('title', I18n.t('filters.with_category', {filter: filterText, category: model.get('name').capitalize()}));
- this.controllerFor('discoveryTop').setProperties({ model: topList, category: model });
this.controllerFor('navigationCategory').set('canCreateTopic', topList.get('can_create_topic'));
+ this.controllerFor('discoveryTop').setProperties({
+ model: topList,
+ category: model,
+ noSubcategories: this.get('no_subcategories')
+ });
this.set('topList', null);
},
diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb
index 29a0e273a..bd0a1c1b3 100644
--- a/app/controllers/list_controller.rb
+++ b/app/controllers/list_controller.rb
@@ -1,22 +1,40 @@
class ListController < ApplicationController
+ skip_before_filter :check_xhr
+
+ @@categories = [
+ # filtered topics lists
+ Discourse.filters.map { |f| "#{f}_category".to_sym },
+ Discourse.filters.map { |f| "#{f}_category_none".to_sym },
+ # top summary
+ :top_category,
+ :top_category_none,
+ # top pages (ie. with a period)
+ TopTopic.periods.map { |p| "top_#{p}_category".to_sym },
+ TopTopic.periods.map { |p| "top_#{p}_category_none".to_sym },
+ # category feeds
+ :category_feed,
+ ].flatten
+
+ before_filter :set_category, only: @@categories
+
before_filter :ensure_logged_in, except: [
:topics_by,
# anonymous filters
- Discourse.anonymous_filters, Discourse.anonymous_filters.map { |f| "#{f}_feed".to_sym },
- # category
- :category, :category_feed,
+ Discourse.anonymous_filters,
+ Discourse.anonymous_filters.map { |f| "#{f}_feed".to_sym },
+ # categories
+ @@categories,
# top
- :top_lists, TopTopic.periods.map { |p| "top_#{p}".to_sym }
+ :top,
+ TopTopic.periods.map { |p| "top_#{p}".to_sym }
].flatten
- before_filter :set_category, only: [:category, :category_none, :category_feed]
- skip_before_filter :check_xhr
-
# Create our filters
Discourse.filters.each do |filter|
- define_method(filter) do
+ define_method(filter) do |options = nil|
list_opts = build_topic_list_options
+ list_opts.merge!(options) if options
user = list_target_user
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
list.more_topics_url = construct_url_with(filter, list_opts)
@@ -26,6 +44,14 @@ class ListController < ApplicationController
end
respond(list)
end
+
+ define_method("#{filter}_category") do
+ self.send(filter, { category: @category.id })
+ end
+
+ define_method("#{filter}_category_none") do
+ self.send(filter, { category: @category.id, no_subcategories: true })
+ end
end
Discourse.anonymous_filters.each do |filter|
@@ -55,14 +81,6 @@ class ListController < ApplicationController
end
end
- def category
- category_response
- end
-
- def category_none
- category_response(no_subcategories: true)
- end
-
def category_feed
guardian.ensure_can_see!(@category)
discourse_expires_in 1.minute
@@ -72,6 +90,7 @@ class ListController < ApplicationController
@description = "#{I18n.t('topics_in_category', category: @category.name)} #{@category.description}"
@atom_link = "#{Discourse.base_url}/category/#{@category.slug}.rss"
@topic_list = TopicQuery.new.list_new_in_category(@category)
+
render 'list', formats: [:rss]
end
@@ -81,11 +100,13 @@ class ListController < ApplicationController
redirect_to latest_path, :status => 301
end
- def top_lists
+ def top(options = nil)
discourse_expires_in 1.minute
- options = build_topic_list_options
- top = generate_top_lists(options)
+ top_options = build_topic_list_options
+ top_options.merge!(options) if options
+
+ top = generate_top_lists(top_options)
respond_to do |format|
format.html do
@@ -99,28 +120,38 @@ class ListController < ApplicationController
end
end
+ def top_category
+ options = { category: @category.id }
+ top(options)
+ end
+
+ def top_category_none
+ options = { category: @category.id, no_subcategories: true }
+ top(options)
+ end
+
TopTopic.periods.each do |period|
- define_method("top_#{period}") do
- options = build_topic_list_options
- options[:per_page] = SiteSetting.topics_per_period_in_top_page
+ define_method("top_#{period}") do |options = nil|
+ top_options = build_topic_list_options
+ top_options.merge!(options) if options
+ top_options[:per_page] = SiteSetting.topics_per_period_in_top_page
user = list_target_user
- list = TopicQuery.new(user, options).public_send("list_top_#{period}")
- list.more_topics_url = construct_url_with(period, options, "top")
+ list = TopicQuery.new(user, top_options).public_send("list_top_#{period}")
+ list.more_topics_url = construct_url_with(period, top_options, "top")
respond(list)
end
+
+ define_method("top_#{period}_category") do
+ self.send("top_#{period}", { category: @category.id })
+ end
+
+ define_method("top_#{period}_category_none") do
+ self.send("top_#{period}", { category: @category.id, no_subcategories: true })
+ end
end
protected
- def category_response(extra_opts=nil)
- list_opts = build_topic_list_options
- list_opts.merge!(extra_opts) if extra_opts
- query = TopicQuery.new(current_user, list_opts)
- list = query.list_latest
- list.more_topics_url = construct_url_with(:latest, list_opts)
- respond(list)
- end
-
def respond(list)
discourse_expires_in 1.minute
@@ -158,12 +189,13 @@ class ListController < ApplicationController
if parent_slug_or_id.present?
parent_category_id = Category.where(slug: parent_slug_or_id).pluck(:id).first ||
Category.where(id: parent_slug_or_id.to_i).pluck(:id).first
-
raise Discourse::NotFound.new if parent_category_id.blank?
end
@category = Category.where(slug: slug_or_id, parent_category_id: parent_category_id).includes(:featured_users).first ||
Category.where(id: slug_or_id.to_i, parent_category_id: parent_category_id).includes(:featured_users).first
+
+ raise Discourse::NotFound.new if @category.blank?
end
def build_topic_list_options
diff --git a/app/views/list/list.rss.erb b/app/views/list/list.rss.erb
index eaf7c608b..542a67545 100644
--- a/app/views/list/list.rss.erb
+++ b/app/views/list/list.rss.erb
@@ -7,28 +7,30 @@
<%= @link %>
- <%= topic.posts.first.cooked.html_safe %> --
<%= t 'num_posts' %> <%= topic.posts_count %>
-<%= t 'num_participants' %> <%= topic.participant_count %>
-<%= link_to t('read_full_topic'), topic_url %>
- ]]> - <%= topic_url %> -+ <%= topic.posts.first.cooked.html_safe %> ++
<%= t 'num_posts' %> <%= topic.posts_count %>
+<%= t 'num_participants' %> <%= topic.participant_count %>
+<%= link_to t('read_full_topic'), topic_url %>
+ ]]>