-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Add search and sort functions to hashtag admin UI #11829
Changes from 3 commits
8c6872a
f585086
7896a8b
debe1f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# 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 'context' | ||
Tag.discoverable if value == 'directory' | ||
when 'name' | ||
Tag.matches_name(value) | ||
when 'order' | ||
scope_for_order(value) | ||
when 'review' | ||
scope_for_review(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if these method names are okay... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems OK. |
||
else | ||
raise "Unknown filter: #{key}" | ||
end | ||
end | ||
|
||
def scope_for_order(order) | ||
case order | ||
when 'popular' | ||
Tag.order('max_score DESC NULLS LAST') | ||
when 'active' | ||
Tag.order('last_status_at DESC NULLS LAST') | ||
else | ||
raise "Unknown filter: #{order}" | ||
end | ||
end | ||
|
||
def scope_for_review(review) | ||
case review | ||
when 'reviewed' | ||
Tag.reviewed.order(reviewed_at: :desc) | ||
when 'unreviewed' | ||
Tag.unreviewed | ||
when 'pending_review' | ||
Tag.pending_review.order(requested_review_at: :desc) | ||
else | ||
raise "Unknown filter: #{review}" | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,26 @@ | |
%li= filter_link_to t('admin.tags.reviewed'), review: 'reviewed' | ||
%li= filter_link_to safe_join([t('admin.accounts.moderation.pending'), "(#{Tag.pending_review.count})"], ' '), review: 'pending_review' | ||
|
||
.filter-subset | ||
%strong= t('generic.order_by') | ||
%ul | ||
%li= filter_link_to t('admin.tags.most_recent'), order: nil | ||
%li= filter_link_to t('admin.tags.most_popular'), order: 'popular' | ||
%li= filter_link_to t('admin.tags.last_active'), order: 'active' | ||
|
||
= form_tag admin_tags_url, method: 'GET', class: 'simple_form' do | ||
.fields-group | ||
- Admin::FilterHelper::TAGS_FILTERS.each do |key| | ||
= hidden_field_tag key, params[key] if params[key].present? | ||
|
||
- %i(name).each do |key| | ||
.input.string.optional | ||
= text_field_tag key, params[key], class: 'string optional', placeholder: I18n.t("admin.tags.#{key}") | ||
|
||
.actions | ||
%button= t('admin.accounts.search') | ||
= link_to t('admin.accounts.reset'), admin_tags_path, class: 'button negative' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These borrowed from existing translations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine, we do that for other views with the same buttons. |
||
|
||
%hr.spacer/ | ||
|
||
= form_for(@form, url: batch_admin_tags_path) do |f| | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,8 @@ en: | |
must_be_follower: Block notifications from non-followers | ||
must_be_following: Block notifications from people you don't follow | ||
must_be_following_dm: Block direct messages from people you don't follow | ||
invite: | ||
comment: Comment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This translation has nothing to do with this PR. |
||
invite_request: | ||
text: Why do you want to join? | ||
notification_emails: | ||
|
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.
What happens if
scope.merge!(nil)
?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.
Oh… thank you, I will fix it.