basic implementation of per-category new/latest etc filters
This commit is contained in:
parent
89f801ac04
commit
b7d3b52e4f
|
@ -26,6 +26,9 @@ Discourse.Route.buildRoutes(function() {
|
|||
Discourse.ListController.filters.forEach(function(filter) {
|
||||
router.route(filter, { path: "/" + filter });
|
||||
router.route(filter, { path: "/" + filter + "/more" });
|
||||
router.route(filter + "Category", { path: "/category/:slug/" + filter });
|
||||
router.route(filter + "Category", { path: "/category/:slug/" + filter + "/more" });
|
||||
|
||||
});
|
||||
|
||||
// the homepage is the first item of the 'top_menu' site setting
|
||||
|
|
|
@ -40,7 +40,7 @@ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({
|
|||
this._super();
|
||||
|
||||
// Add a search context
|
||||
this.controllerFor('search').set('searchContext', this.modelFor('listCategory').get('searchContext'));
|
||||
this.controllerFor('search').set('searchContext', this.modelFor(this.get('routeName')).get('searchContext'));
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
|
@ -54,3 +54,8 @@ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({
|
|||
});
|
||||
|
||||
|
||||
Discourse.ListController.filters.forEach(function(filter) {
|
||||
Discourse["List" + (filter.capitalize()) + "CategoryRoute"] = Discourse.ListCategoryRoute.extend({ filter: filter });
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -139,7 +139,8 @@ class ListController < ApplicationController
|
|||
return {
|
||||
page: params[:page],
|
||||
topic_ids: param_to_integer_list(:topic_ids),
|
||||
exclude_category: (params[:exclude_category] || menu_item.try(:filter))
|
||||
exclude_category: (params[:exclude_category] || menu_item.try(:filter)),
|
||||
category: params[:category]
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -196,7 +196,6 @@ Discourse::Application.routes.draw do
|
|||
|
||||
get 'category/:category.rss' => 'list#category_feed', format: :rss, as: 'category_feed'
|
||||
get 'category/:category' => 'list#category', as: 'category_list'
|
||||
get 'category/:parent_category/:category' => 'list#category', as: 'category_list_parent'
|
||||
get 'category/:category/more' => 'list#category', as: 'category_list_more'
|
||||
|
||||
# We've renamed popular to latest. If people access it we want a permanent redirect.
|
||||
|
@ -210,8 +209,13 @@ Discourse::Application.routes.draw do
|
|||
[:latest, :hot, :favorited, :read, :posted, :unread, :new].each do |filter|
|
||||
get "#{filter}" => "list##{filter}"
|
||||
get "#{filter}/more" => "list##{filter}"
|
||||
|
||||
get "category/:category/#{filter}" => "list##{filter}"
|
||||
get "category/:category/#{filter}/more" => "list##{filter}"
|
||||
end
|
||||
|
||||
get 'category/:parent_category/:category' => 'list#category', as: 'category_list_parent'
|
||||
|
||||
get 'search' => 'search#query'
|
||||
|
||||
# Topics resource
|
||||
|
|
|
@ -7,7 +7,7 @@ require_dependency 'suggested_topics_builder'
|
|||
|
||||
class TopicQuery
|
||||
# Could be rewritten to %i if Ruby 1.9 is no longer supported
|
||||
VALID_OPTIONS = %w(except_topic_id exclude_category limit page per_page topic_ids visible).map(&:to_sym)
|
||||
VALID_OPTIONS = %w(except_topic_id exclude_category limit page per_page topic_ids visible category).map(&:to_sym)
|
||||
|
||||
class << self
|
||||
# use the constants in conjuction with COALESCE to determine the order with regard to pinned
|
||||
|
@ -233,7 +233,7 @@ class TopicQuery
|
|||
|
||||
result = result.listable_topics.includes(category: :topic_only_relative_url)
|
||||
result = result.where('categories.name is null or categories.name <> ?', options[:exclude_category]).references(:categories) if options[:exclude_category]
|
||||
result = result.where('categories.name = ?', options[:only_category]).references(:categories) if options[:only_category]
|
||||
result = result.where('categories.slug = ?', options[:category]).references(:categories) if options[:category].present?
|
||||
result = result.limit(options[:per_page]) unless options[:limit] == false
|
||||
result = result.visible if options[:visible] || @user.nil? || @user.regular?
|
||||
result = result.where('topics.id <> ?', options[:except_topic_id]).references(:topics) if options[:except_topic_id]
|
||||
|
|
Loading…
Reference in New Issue