New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: add new custom status filters #286
Conversation
plugin.rb
Outdated
@@ -310,15 +310,16 @@ def self.skip_db? | |||
end | |||
|
|||
if respond_to?(:register_modifier) | |||
register_modifier(:search_rank_sort_priorities) do |priorities, search| | |||
register_modifier(:search_rank_sort_priorities) do |priorities, _search| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the "_
" prefix to signal that this argument isn't being used.
WHERE topics.id = f.topic_id | ||
AND f.name = '#{::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD}' | ||
) | ||
EXISTS ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatted the query and added the "AND value IS NOT NULL
" condition that is being used everywhere else
WHERE tc.name = '#{::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD}' AND | ||
tc.value IS NOT NULL | ||
)", | ||
solved_callback = ->(scope) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have several ways to filter by solved/unsolved status (in search, in filter, in topic lists, etc...).
I've extracted both solved and unsolved "queries" so they can be used everywhere.
plugin.rb
Outdated
end | ||
|
||
if Discourse.has_needed_version?(Discourse::VERSION::STRING, "1.8.0.beta6") | ||
if respond_to? :register_custom_filter_by_status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the new API introduced in discourse/discourse#26770
plugin.rb
Outdated
register_custom_filter_by_status("unsolved", &unsolved_callback) | ||
end | ||
|
||
if respond_to? :register_search_advanced_filter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used the "plugin" API instead of reaching directly for the Search
class.
plugin.rb
Outdated
@@ -432,19 +423,27 @@ def self.skip_db? | |||
if Search.respond_to? :preloaded_topic_custom_fields | |||
Search.preloaded_topic_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD | |||
end | |||
|
|||
if CategoryList.respond_to?(:preloaded_topic_custom_fields) | |||
if CategoryList.respond_to? :preloaded_topic_custom_fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed parenthesis to match surrounding styling.
AND value IS NOT NULL | ||
) | ||
SQL | ||
on(:filter_auto_bump_topics) do |_category, filters| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tweaked the formatting a little bit so it's less confusing 🤷
Those can be used in /filter route. Depends on discourse/discourse#26770 Internal ref. /t/127278
70dd3a8
to
a49f23e
Compare
How about using discourse_compatibility so we dont have to do all the ifs everywhere? |
Those can be used in /filter route.
Depends on discourse/discourse#26770
Internal ref. /t/127278