forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add search and sort functions to hashtag admin UI (mastodon#11829)
* Add search and sort functions to hashtag admin UI * Move scope processing from tags_controller to tag_filter * Fix based on method naming conventions * Fixed not to get 500 errors for invalid requests
- Loading branch information
1 parent
c06ba20
commit 250b0d6
Showing
7 changed files
with
81 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
class TagFilter | ||
attr_reader :params | ||
|
||
def initialize(params) | ||
@params = params | ||
end | ||
|
||
def results | ||
scope = Tag.unscoped | ||
|
||
params.each do |key, value| | ||
next if key.to_s == 'page' | ||
|
||
scope.merge!(scope_for(key, value.to_s.strip)) if value.present? | ||
end | ||
|
||
scope.order(id: :desc) | ||
end | ||
|
||
private | ||
|
||
def scope_for(key, value) | ||
case key.to_s | ||
when 'directory' | ||
Tag.discoverable | ||
when 'reviewed' | ||
Tag.reviewed.order(reviewed_at: :desc) | ||
when 'unreviewed' | ||
Tag.unreviewed | ||
when 'pending_review' | ||
Tag.pending_review.order(requested_review_at: :desc) | ||
when 'popular' | ||
Tag.order('max_score DESC NULLS LAST') | ||
when 'active' | ||
Tag.order('last_status_at DESC NULLS LAST') | ||
when 'name' | ||
Tag.matches_name(value) | ||
else | ||
raise "Unknown filter: #{key}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters