From 7162ecfb04cca5f8778b7cf9cdbbe524c3132b43 Mon Sep 17 00:00:00 2001 From: mintsaxon Date: Sun, 27 Jun 2021 21:46:11 +0200 Subject: [PATCH] FEATURE: Per-category default slow mode duration for topics. When configured, all topics in the category inherits the slow mode duration from the category's default. Note that currently there is no way to remove the slow mode from the topics once it has been set. --- .../app/components/edit-category-settings.js | 6 ++++++ .../javascripts/discourse/app/models/category.js | 6 ++++++ .../components/edit-category-settings.hbs | 15 +++++++++++++++ .../stylesheets/common/base/edit-category.scss | 3 ++- app/controllers/categories_controller.rb | 1 + app/models/category.rb | 1 + app/models/topic.rb | 7 +++++++ app/serializers/category_serializer.rb | 3 ++- config/locales/client.en.yml | 1 + ..._add_default_auto_close_seconds_to_category.rb | 7 +++++++ .../schemas/json/category_create_response.json | 7 +++++++ .../schemas/json/category_update_response.json | 7 +++++++ 12 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20210702204007_add_default_auto_close_seconds_to_category.rb 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 bfcfa19cd5e..93947368f3e 100644 --- a/app/assets/javascripts/discourse/app/components/edit-category-settings.js +++ b/app/assets/javascripts/discourse/app/components/edit-category-settings.js @@ -138,4 +138,10 @@ export default buildCategoryPanel("settings", { let hours = minutes ? minutes / 60 : null; this.set("category.auto_close_hours", hours); }, + + @action + onDefaultSlowModeDurationChange(minutes) { + let seconds = minutes ? minutes * 60 : null; + this.set("category.default_slow_mode_seconds", seconds); + }, }); diff --git a/app/assets/javascripts/discourse/app/models/category.js b/app/assets/javascripts/discourse/app/models/category.js index af65076dba4..940bb5ba39e 100644 --- a/app/assets/javascripts/discourse/app/models/category.js +++ b/app/assets/javascripts/discourse/app/models/category.js @@ -177,6 +177,11 @@ const Category = RestModel.extend({ return topicCount; }, + @discourseComputed("default_slow_mode_seconds") + defaultSlowModeMinutes(seconds) { + return seconds ? seconds / 60 : null; + }, + save() { const id = this.id; const url = id ? `/categories/${id}` : "/categories"; @@ -193,6 +198,7 @@ const Category = RestModel.extend({ auto_close_based_on_last_post: this.get( "auto_close_based_on_last_post" ), + default_slow_mode_seconds: this.default_slow_mode_seconds, position: this.position, email_in: this.email_in, email_in_allow_strangers: this.email_in_allow_strangers, 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 78c3414a364..8dc72c57022 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 @@ -116,6 +116,21 @@ +
+
+ +
+ {{relative-time-picker + id="category-default-slow-mode" + durationMinutes=category.defaultSlowModeMinutes + hiddenIntervals=hiddenRelativeIntervals + onChange=(action "onDefaultSlowModeDurationChange")}} +
+
+
+