forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement UI for Admin Search of Hashtags (mastodon#30880)
- Loading branch information
1 parent
6d2ed0d
commit c40e481
Showing
17 changed files
with
316 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin::TagsHelper | ||
def admin_tags_moderation_options | ||
[ | ||
[t('admin.tags.moderation.reviewed'), 'reviewed'], | ||
[t('admin.tags.moderation.review_requested'), 'review_requested'], | ||
[t('admin.tags.moderation.unreviewed'), 'unreviewed'], | ||
[t('admin.tags.moderation.trendable'), 'trendable'], | ||
[t('admin.tags.moderation.not_trendable'), 'not_trendable'], | ||
[t('admin.tags.moderation.usable'), 'usable'], | ||
[t('admin.tags.moderation.not_usable'), 'not_usable'], | ||
] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::TagFilter | ||
KEYS = %i( | ||
status | ||
name | ||
order | ||
).freeze | ||
|
||
attr_reader :params | ||
|
||
def initialize(params) | ||
@params = params.to_h.symbolize_keys | ||
end | ||
|
||
def results | ||
scope = Tag.reorder(nil) | ||
|
||
params.each do |key, value| | ||
next if key == :page | ||
|
||
scope.merge!(scope_for(key, value)) if value.present? | ||
end | ||
|
||
scope | ||
end | ||
|
||
private | ||
|
||
def scope_for(key, value) | ||
case key | ||
when :status | ||
status_scope(value) | ||
when :name | ||
Tag.search_for(value.to_s.strip, params[:limit], params[:offset], exclude_unlistable: false) | ||
when :order | ||
order_scope(value) | ||
else | ||
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}" | ||
end | ||
end | ||
|
||
def status_scope(value) | ||
case value.to_s | ||
when 'reviewed' | ||
Tag.reviewed | ||
when 'review_requested' | ||
Tag.pending_review | ||
when 'unreviewed' | ||
Tag.unreviewed | ||
when 'trendable' | ||
Tag.trendable | ||
when 'not_trendable' | ||
Tag.not_trendable | ||
when 'usable' | ||
Tag.usable | ||
when 'not_usable' | ||
Tag.not_usable | ||
else | ||
raise Mastodon::InvalidParameterError, "Unknown status: #{value}" | ||
end | ||
end | ||
|
||
def order_scope(value) | ||
case value.to_s | ||
when 'newest' | ||
Tag.order(created_at: :desc) | ||
when 'oldest' | ||
Tag.order(created_at: :asc) | ||
else | ||
raise Mastodon::InvalidParameterError, "Unknown order: #{value}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.batch-table__row{ class: [!tag.requires_review? && !tag.usable? && 'batch-table__row--muted'] } | ||
.batch-table__row__content.batch-table__row__content--padded.pending-account | ||
.pending-account__header | ||
%strong | ||
= link_to tag.formatted_name, admin_tag_path(tag.id) | ||
|
||
%br/ | ||
|
||
- if tag.usable? | ||
= t('admin.tags.moderation.usable') | ||
- else | ||
= t('admin.tags.moderation.not_usable') | ||
|
||
· | ||
- if tag.trendable? | ||
= t('admin.tags.moderation.trendable') | ||
- else | ||
= t('admin.tags.moderation.not_trendable') | ||
|
||
- if tag.requested_review? || tag.requires_review? | ||
· | ||
- if tag.requested_review? | ||
%span.negative-hint | ||
= t('admin.tags.moderation.review_requested') | ||
- else | ||
%span.warning-hint | ||
= t('admin.tags.moderation.pending_review') |
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,39 @@ | ||
- content_for :page_title do | ||
= t('admin.tags.title') | ||
|
||
= form_with url: admin_tags_url, method: :get, class: :simple_form do |form| | ||
.filters | ||
.filter-subset.filter-subset--with-select | ||
%strong= t('admin.tags.moderation.title') | ||
.input.select.optional | ||
= form.select :status, | ||
options_for_select(admin_tags_moderation_options, params[:status]), | ||
prompt: t('generic.all') | ||
|
||
.filter-subset.filter-subset--with-select | ||
%strong= t 'generic.order_by' | ||
.input.select | ||
= form.select :order, | ||
options_for_select([[t('admin.tags.newest'), 'newest'], [t('admin.tags.oldest'), 'oldest']], params[:order]) | ||
|
||
.fields-group | ||
.input.string.optional | ||
= form.text_field :name, | ||
value: params[:name], | ||
class: 'string optional', | ||
placeholder: t('admin.tags.name') | ||
|
||
.actions | ||
%button.button= t('admin.tags.search') | ||
= link_to t('admin.tags.reset'), admin_tags_path, class: 'button negative' | ||
|
||
%hr.spacer/ | ||
|
||
.batch-table | ||
.batch-table__body | ||
- if @tags.empty? | ||
= nothing_here 'nothing-here--under-tabs' | ||
- else | ||
= render partial: 'tag', collection: @tags | ||
|
||
= paginate @tags |
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
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
Oops, something went wrong.