FEATURE: category setting for default list filter. (#9975)

FEATURE: category setting for default list filter. (#9975)

diff --git a/app/assets/javascripts/discourse/app/components/edit-category-settings.js b/app/assets/javascripts/discourse/app/components/edit-category-settings.js
index 5844e45..c811ce2 100644
--- a/app/assets/javascripts/discourse/app/components/edit-category-settings.js
+++ b/app/assets/javascripts/discourse/app/components/edit-category-settings.js
@@ -69,6 +69,13 @@ export default buildCategoryPanel("settings", {
   },
 
   @discourseComputed
+  availableListFilters() {
+    return ["all", "none"].map(p => {
+      return { name: I18n.t(`category.list_filters.${p}`), value: p };
+    });
+  },
+
+  @discourseComputed
   searchPrioritiesOptions() {
     const options = [];
 
diff --git a/app/assets/javascripts/discourse/app/models/category.js b/app/assets/javascripts/discourse/app/models/category.js
index 2c0442a..7d950ca 100644
--- a/app/assets/javascripts/discourse/app/models/category.js
+++ b/app/assets/javascripts/discourse/app/models/category.js
@@ -188,7 +188,8 @@ const Category = RestModel.extend({
         ),
         search_priority: this.search_priority,
         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"
     });
diff --git a/app/assets/javascripts/discourse/app/pre-initializers/dynamic-route-builders.js b/app/assets/javascripts/discourse/app/pre-initializers/dynamic-route-builders.js
index 9c96d01..4762691 100644
--- a/app/assets/javascripts/discourse/app/pre-initializers/dynamic-route-builders.js
+++ b/app/assets/javascripts/discourse/app/pre-initializers/dynamic-route-builders.js
@@ -13,6 +13,7 @@ export default {
     app.DiscoveryCategoryController = DiscoverySortableController.extend();
     app.DiscoveryParentCategoryController = DiscoverySortableController.extend();
     app.DiscoveryCategoryNoneController = DiscoverySortableController.extend();
+    app.DiscoveryCategoryAllController = DiscoverySortableController.extend();
     app.DiscoveryCategoryWithIDController = DiscoverySortableController.extend();
 
     app.DiscoveryCategoryRoute = buildCategoryRoute("default");
@@ -20,6 +21,9 @@ export default {
     app.DiscoveryCategoryNoneRoute = buildCategoryRoute("default", {
       no_subcategories: true
     });
+    app.DiscoveryCategoryAllRoute = buildCategoryRoute("default", {
+      no_subcategories: false
+    });
     app.DiscoveryCategoryWithIDRoute = buildCategoryRoute("default");
 
     const site = Site.current();
diff --git a/app/assets/javascripts/discourse/app/routes/app-route-map.js b/app/assets/javascripts/discourse/app/routes/app-route-map.js
index fb13822..9057ff2 100644
--- a/app/assets/javascripts/discourse/app/routes/app-route-map.js
+++ b/app/assets/javascripts/discourse/app/routes/app-route-map.js
@@ -70,6 +70,7 @@ export default function() {
 
     // default filter for a category
     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" });
   });
 
diff --git a/app/assets/javascripts/discourse/app/routes/build-category-route.js b/app/assets/javascripts/discourse/app/routes/build-category-route.js
index eac84d8..58e5584 100644
--- a/app/assets/javascripts/discourse/app/routes/build-category-route.js
+++ b/app/assets/javascripts/discourse/app/routes/build-category-route.js
@@ -30,6 +30,11 @@ export default (filterArg, params) => {
             category,
             category_slug_path_with_id
           });
+        } else if (modelParams.id === "all") {
+          modelParams.category_slug_path_with_id = [
+            modelParams.parentSlug,
+            modelParams.slug
+          ].join("/");
         } else {
           modelParams.category_slug_path_with_id = [
             modelParams.parentSlug,
@@ -76,10 +81,24 @@ export default (filterArg, params) => {
         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([
-        this._createSubcategoryList(model.category),
-        this._retrieveTopicList(model.category, transition, model.modelParams)
+        this._createSubcategoryList(category),
+        this._retrieveTopicList(category, transition, modelParams)
       ]);
     },
 
diff --git a/app/assets/javascripts/discourse/app/templates/components/edit-category-settings.hbs b/app/assets/javascripts/discourse/app/templates/components/edit-category-settings.hbs
index ab17a30..a569876 100644
--- a/app/assets/javascripts/discourse/app/templates/components/edit-category-settings.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/edit-category-settings.hbs
@@ -196,6 +196,21 @@
       {{/unless}}
     </div>
   </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}}
     <section class="field show-subcategory-list-field">
       <label>
diff --git a/app/assets/javascripts/select-kit/addon/components/category-drop.js b/app/assets/javascripts/select-kit/addon/components/category-drop.js
index 3722e73..a0ad319 100644
--- a/app/assets/javascripts/select-kit/addon/components/category-drop.js
+++ b/app/assets/javascripts/select-kit/addon/components/category-drop.js
@@ -128,7 +128,9 @@ export default ComboBoxComponent.extend({
     "selectKit.options.subCategory",
     function() {
       return getURL(
-        this.selectKit.options.subCategory ? this.parentCategoryUrl || "/" : "/"
+        this.selectKit.options.subCategory
+          ? `${this.parentCategoryUrl}/all` || "/"
+          : "/"
       );
     }
   ),
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 8a36480..20e02ab 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -329,6 +329,7 @@ class CategoriesController < ApplicationController
         :required_tag_group_name,
         :min_tags_from_required_group,
         :read_only_banner,
+        :default_list_filter,
         custom_fields: [params[:custom_fields].try(:keys)],
         permissions: [*p.try(:keys)],
         allowed_tags: [],
diff --git a/app/serializers/basic_category_serializer.rb b/app/serializers/basic_category_serializer.rb
index 540422a..87c02a6 100644
--- a/app/serializers/basic_category_serializer.rb
+++ b/app/serializers/basic_category_serializer.rb
@@ -28,6 +28,7 @@ class BasicCategorySerializer < ApplicationSerializer
              :default_view,
              :subcategory_list_style,
              :default_top_period,
+             :default_list_filter,
              :minimum_required_tags,
              :navigate_to_first_post_after_read,
              :custom_fields
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 8f5e123..b5db1f5 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2826,6 +2826,7 @@ en:
       sort_order: "Topic List Sort By:"
       default_view: "Default Topic List:"
       default_top_period: "Default Top Period:"
+      default_list_filter: "Default List Filter:"

[... diff too long, it was truncated ...]

GitHub sha: 3e7f7fdd

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/in-a-top-category-page-show-only-its-own-topics-below-subcategories/39527/32

This commit appears in #9975 which was merged by vinothkannans.