mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
UX: Introduce automatic 'categories topics' setting (#8804)
When 'categories topics' setting is set to 0, the system will automatically try to find a value to keep the two columns (categories and topics) symmetrical. The value is computed as 1.5x the number of top level categories and at least 5 topics will always be returned.
This commit is contained in:
19
lib/validators/categories_topics_validator.rb
Normal file
19
lib/validators/categories_topics_validator.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CategoriesTopicsValidator
|
||||
def initialize(opts = {})
|
||||
@opts = opts
|
||||
end
|
||||
|
||||
def valid_value?(val)
|
||||
num = val.to_i
|
||||
return false if num.to_s != val.to_s
|
||||
return false if num != 0 && num < CategoriesController::MIN_CATEGORIES_TOPICS
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def error_message
|
||||
I18n.t('site_settings.errors.invalid_integer_min', min: 5)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user