From 11ce73b8eddcb246f76bee17be441ca8fd88c057 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 22 Mar 2017 16:54:12 -0400 Subject: [PATCH] FEATURE: category setting for default top period --- .../components/edit-category-settings.js.es6 | 7 ++++ .../discourse/models/category.js.es6 | 3 +- .../components/edit-category-settings.hbs | 7 ++++ app/controllers/categories_controller.rb | 1 + app/controllers/list_controller.rb | 19 +++++----- app/models/category.rb | 1 + app/serializers/basic_category_serializer.rb | 3 +- config/locales/client.en.yml | 1 + ...05_add_default_top_period_to_categories.rb | 5 +++ spec/controllers/list_controller_spec.rb | 36 +++++++------------ 10 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 db/migrate/20170322191305_add_default_top_period_to_categories.rb diff --git a/app/assets/javascripts/discourse/components/edit-category-settings.js.es6 b/app/assets/javascripts/discourse/components/edit-category-settings.js.es6 index 0d5336835ac..6a97b28ebe7 100644 --- a/app/assets/javascripts/discourse/components/edit-category-settings.js.es6 +++ b/app/assets/javascripts/discourse/components/edit-category-settings.js.es6 @@ -27,6 +27,13 @@ export default buildCategoryPanel('settings', { ]; }, + @computed + availableTopPeriods() { + return ['all', 'yearly', 'quarterly', 'monthly', 'weekly', 'daily'].map((p) => { + return {name: I18n.t(`filters.top.${p}.title`), value: p}; + }); + }, + @computed availableSorts() { return ['likes', 'op_likes', 'views', 'posts', 'activity', 'posters', 'category', 'created'] diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6 index 8550159ddd3..16304f453e6 100644 --- a/app/assets/javascripts/discourse/models/category.js.es6 +++ b/app/assets/javascripts/discourse/models/category.js.es6 @@ -106,7 +106,8 @@ const Category = RestModel.extend({ show_subcategory_list: this.get('show_subcategory_list'), num_featured_topics: this.get('num_featured_topics'), default_view: this.get('default_view'), - subcategory_list_style: this.get('subcategory_list_style') + subcategory_list_style: this.get('subcategory_list_style'), + default_top_period: this.get('default_top_period') }, type: id ? 'PUT' : 'POST' }); diff --git a/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs b/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs index e12846ea3c0..aae72706cd7 100644 --- a/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs +++ b/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs @@ -44,6 +44,13 @@ +
+ +
+