FEATURE: category setting for default list filter. ()

This commit is contained in:
Vinoth Kannan 2020-06-04 00:56:56 +05:30 committed by GitHub
parent 22789e0201
commit 3e7f7fdde8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 63 additions and 5 deletions
app
assets/javascripts
discourse/app
select-kit/addon/components
controllers
serializers
config
spec/requests/api

View File

@ -68,6 +68,13 @@ export default buildCategoryPanel("settings", {
); );
}, },
@discourseComputed
availableListFilters() {
return ["all", "none"].map(p => {
return { name: I18n.t(`category.list_filters.${p}`), value: p };
});
},
@discourseComputed @discourseComputed
searchPrioritiesOptions() { searchPrioritiesOptions() {
const options = []; const options = [];

View File

@ -188,7 +188,8 @@ const Category = RestModel.extend({
), ),
search_priority: this.search_priority, search_priority: this.search_priority,
reviewable_by_group_name: this.reviewable_by_group_name, reviewable_by_group_name: this.reviewable_by_group_name,
read_only_banner: this.read_only_banner read_only_banner: this.read_only_banner,
default_list_filter: this.default_list_filter
}, },
type: id ? "PUT" : "POST" type: id ? "PUT" : "POST"
}); });

View File

@ -13,6 +13,7 @@ export default {
app.DiscoveryCategoryController = DiscoverySortableController.extend(); app.DiscoveryCategoryController = DiscoverySortableController.extend();
app.DiscoveryParentCategoryController = DiscoverySortableController.extend(); app.DiscoveryParentCategoryController = DiscoverySortableController.extend();
app.DiscoveryCategoryNoneController = DiscoverySortableController.extend(); app.DiscoveryCategoryNoneController = DiscoverySortableController.extend();
app.DiscoveryCategoryAllController = DiscoverySortableController.extend();
app.DiscoveryCategoryWithIDController = DiscoverySortableController.extend(); app.DiscoveryCategoryWithIDController = DiscoverySortableController.extend();
app.DiscoveryCategoryRoute = buildCategoryRoute("default"); app.DiscoveryCategoryRoute = buildCategoryRoute("default");
@ -20,6 +21,9 @@ export default {
app.DiscoveryCategoryNoneRoute = buildCategoryRoute("default", { app.DiscoveryCategoryNoneRoute = buildCategoryRoute("default", {
no_subcategories: true no_subcategories: true
}); });
app.DiscoveryCategoryAllRoute = buildCategoryRoute("default", {
no_subcategories: false
});
app.DiscoveryCategoryWithIDRoute = buildCategoryRoute("default"); app.DiscoveryCategoryWithIDRoute = buildCategoryRoute("default");
const site = Site.current(); const site = Site.current();

View File

@ -70,6 +70,7 @@ export default function() {
// default filter for a category // default filter for a category
this.route("categoryNone", { path: "/c/*category_slug_path_with_id/none" }); this.route("categoryNone", { path: "/c/*category_slug_path_with_id/none" });
this.route("categoryAll", { path: "/c/*category_slug_path_with_id/all" });
this.route("category", { path: "/c/*category_slug_path_with_id" }); this.route("category", { path: "/c/*category_slug_path_with_id" });
}); });

View File

@ -30,6 +30,11 @@ export default (filterArg, params) => {
category, category,
category_slug_path_with_id category_slug_path_with_id
}); });
} else if (modelParams.id === "all") {
modelParams.category_slug_path_with_id = [
modelParams.parentSlug,
modelParams.slug
].join("/");
} else { } else {
modelParams.category_slug_path_with_id = [ modelParams.category_slug_path_with_id = [
modelParams.parentSlug, modelParams.parentSlug,
@ -76,10 +81,24 @@ export default (filterArg, params) => {
return; return;
} }
this._setupNavigation(model.category); const { category, modelParams } = model;
if (
category.default_list_filter === "none" &&
filterArg === "default" &&
modelParams &&
modelParams.id !== "all"
) {
this.replaceWith("discovery.categoryNone", {
category,
category_slug_path_with_id: modelParams.category_slug_path_with_id
});
}
this._setupNavigation(category);
return all([ return all([
this._createSubcategoryList(model.category), this._createSubcategoryList(category),
this._retrieveTopicList(model.category, transition, model.modelParams) this._retrieveTopicList(category, transition, modelParams)
]); ]);
}, },

View File

@ -196,6 +196,21 @@
{{/unless}} {{/unless}}
</div> </div>
</section> </section>
<section class="field">
<label for="category-default-filter">
{{i18n "category.default_list_filter"}}
</label>
<div class="controls">
{{combo-box
id="category-default-filter"
valueProperty="value"
content=availableListFilters
value=category.default_list_filter
}}
</div>
</section>
{{#if isParentCategory}} {{#if isParentCategory}}
<section class="field show-subcategory-list-field"> <section class="field show-subcategory-list-field">
<label> <label>

View File

@ -128,7 +128,9 @@ export default ComboBoxComponent.extend({
"selectKit.options.subCategory", "selectKit.options.subCategory",
function() { function() {
return getURL( return getURL(
this.selectKit.options.subCategory ? this.parentCategoryUrl || "/" : "/" this.selectKit.options.subCategory
? `${this.parentCategoryUrl}/all` || "/"
: "/"
); );
} }
), ),

View File

@ -329,6 +329,7 @@ class CategoriesController < ApplicationController
:required_tag_group_name, :required_tag_group_name,
:min_tags_from_required_group, :min_tags_from_required_group,
:read_only_banner, :read_only_banner,
:default_list_filter,
custom_fields: [params[:custom_fields].try(:keys)], custom_fields: [params[:custom_fields].try(:keys)],
permissions: [*p.try(:keys)], permissions: [*p.try(:keys)],
allowed_tags: [], allowed_tags: [],

View File

@ -28,6 +28,7 @@ class BasicCategorySerializer < ApplicationSerializer
:default_view, :default_view,
:subcategory_list_style, :subcategory_list_style,
:default_top_period, :default_top_period,
:default_list_filter,
:minimum_required_tags, :minimum_required_tags,
:navigate_to_first_post_after_read, :navigate_to_first_post_after_read,
:custom_fields :custom_fields

View File

@ -2826,6 +2826,7 @@ en:
sort_order: "Topic List Sort By:" sort_order: "Topic List Sort By:"
default_view: "Default Topic List:" default_view: "Default Topic List:"
default_top_period: "Default Top Period:" default_top_period: "Default Top Period:"
default_list_filter: "Default List Filter:"
allow_badges_label: "Allow badges to be awarded in this category" allow_badges_label: "Allow badges to be awarded in this category"
edit_permissions: "Edit Permissions" edit_permissions: "Edit Permissions"
reviewable_by_group: "In addition to staff, posts and flags in this category can be also be reviewed by:" reviewable_by_group: "In addition to staff, posts and flags in this category can be also be reviewed by:"
@ -2888,6 +2889,9 @@ en:
moderation: "Moderation" moderation: "Moderation"
appearance: "Appearance" appearance: "Appearance"
email: "Email" email: "Email"
list_filters:
all: "all"
none: "none"
flagging: flagging:
title: "Thanks for helping to keep our community civil!" title: "Thanks for helping to keep our community civil!"

View File

@ -686,6 +686,7 @@ Discourse::Application.routes.draw do
get "/l/#{filter}" => "list#category_#{filter}", as: "category_#{filter}" get "/l/#{filter}" => "list#category_#{filter}", as: "category_#{filter}"
end end
get "/all" => "list#category_default", as: "category_all", constraints: { format: 'html' }
get "/" => "list#category_default", as: "category_default" get "/" => "list#category_default", as: "category_default"
end end

View File

@ -195,6 +195,7 @@ describe 'categories' do
default_view: { type: :string, nullable: true }, default_view: { type: :string, nullable: true },
subcategory_list_style: { type: :string }, subcategory_list_style: { type: :string },
default_top_period: { type: :string }, default_top_period: { type: :string },
default_list_filter: { type: :string },
minimum_required_tags: { type: :integer }, minimum_required_tags: { type: :integer },
navigate_to_first_post_after_read: { type: :boolean }, navigate_to_first_post_after_read: { type: :boolean },
custom_fields: { custom_fields: {
@ -370,6 +371,7 @@ describe 'categories' do
default_view: { type: :string, nullable: true }, default_view: { type: :string, nullable: true },
subcategory_list_style: { type: :string }, subcategory_list_style: { type: :string },
default_top_period: { type: :string }, default_top_period: { type: :string },
default_list_filter: { type: :string },
minimum_required_tags: { type: :integer }, minimum_required_tags: { type: :integer },
navigate_to_first_post_after_read: { type: :boolean }, navigate_to_first_post_after_read: { type: :boolean },
custom_fields: { custom_fields: {