From ad75ec8b5b1775edaa485e94ddab69f189affde9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 13 Dec 2017 13:28:31 +0100 Subject: [PATCH] Add filters to admin UI for custom emojis (#6003) --- app/controllers/admin/custom_emojis_controller.rb | 4 +++- app/helpers/admin/filter_helper.rb | 9 +++++---- app/models/custom_emoji_filter.rb | 2 ++ .../admin/custom_emojis/_custom_emoji.html.haml | 2 +- app/views/admin/custom_emojis/index.html.haml | 14 ++++++++++++++ config/locales/en.yml | 1 + 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/custom_emojis_controller.rb b/app/controllers/admin/custom_emojis_controller.rb index 3fa2a0b72e..ccab03de42 100644 --- a/app/controllers/admin/custom_emojis_controller.rb +++ b/app/controllers/admin/custom_emojis_controller.rb @@ -92,7 +92,9 @@ module Admin def filter_params params.permit( :local, - :remote + :remote, + :by_domain, + :shortcode ) end end diff --git a/app/helpers/admin/filter_helper.rb b/app/helpers/admin/filter_helper.rb index 7fe3def987..359c43d0e3 100644 --- a/app/helpers/admin/filter_helper.rb +++ b/app/helpers/admin/filter_helper.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true module Admin::FilterHelper - ACCOUNT_FILTERS = %i(local remote by_domain silenced suspended recent username display_name email ip staff).freeze - REPORT_FILTERS = %i(resolved account_id target_account_id).freeze - INVITE_FILTER = %i(available expired).freeze + ACCOUNT_FILTERS = %i(local remote by_domain silenced suspended recent username display_name email ip staff).freeze + REPORT_FILTERS = %i(resolved account_id target_account_id).freeze + INVITE_FILTER = %i(available expired).freeze + CUSTOM_EMOJI_FILTERS = %i(local remote by_domain shortcode).freeze - FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS + INVITE_FILTER + FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS + INVITE_FILTER + CUSTOM_EMOJI_FILTERS def filter_link_to(text, link_to_params, link_class_params = link_to_params) new_url = filtered_url_for(link_to_params) diff --git a/app/models/custom_emoji_filter.rb b/app/models/custom_emoji_filter.rb index 2d1394a597..2c09ed65ca 100644 --- a/app/models/custom_emoji_filter.rb +++ b/app/models/custom_emoji_filter.rb @@ -27,6 +27,8 @@ class CustomEmojiFilter CustomEmoji.remote when 'by_domain' CustomEmoji.where(domain: value) + when 'shortcode' + CustomEmoji.where(shortcode: value) else raise "Unknown filter: #{key}" end diff --git a/app/views/admin/custom_emojis/_custom_emoji.html.haml b/app/views/admin/custom_emojis/_custom_emoji.html.haml index bab34bc8d7..f7fd2538c9 100644 --- a/app/views/admin/custom_emojis/_custom_emoji.html.haml +++ b/app/views/admin/custom_emojis/_custom_emoji.html.haml @@ -7,7 +7,7 @@ - if custom_emoji.local? = t('admin.accounts.location.local') - else - = custom_emoji.domain + = link_to custom_emoji.domain, admin_custom_emojis_path(by_domain: custom_emoji.domain) %td - if custom_emoji.local? - if custom_emoji.visible_in_picker diff --git a/app/views/admin/custom_emojis/index.html.haml b/app/views/admin/custom_emojis/index.html.haml index 20ffb85294..89ea3a6fe3 100644 --- a/app/views/admin/custom_emojis/index.html.haml +++ b/app/views/admin/custom_emojis/index.html.haml @@ -17,6 +17,20 @@ - else = filter_link_to t('admin.accounts.location.remote'), remote: '1', local: nil += form_tag admin_custom_emojis_url, method: 'GET', class: 'simple_form' do + .fields-group + - Admin::FilterHelper::CUSTOM_EMOJI_FILTERS.each do |key| + - if params[key].present? + = hidden_field_tag key, params[key] + + - %i(shortcode by_domain).each do |key| + .input.string.optional + = text_field_tag key, params[key], class: 'string optional', placeholder: I18n.t("admin.custom_emojis.#{key}") + + .actions + %button= t('admin.accounts.search') + = link_to t('admin.accounts.reset'), admin_accounts_path, class: 'button negative' + .table-wrapper %table.table %thead diff --git a/config/locales/en.yml b/config/locales/en.yml index cc22d02ac9..325391cfd3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -161,6 +161,7 @@ en: update_status: "%{name} updated status by %{target}" title: Audit log custom_emojis: + by_domain: Domain copied_msg: Successfully created local copy of the emoji copy: Copy copy_failed_msg: Could not make a local copy of that emoji