Add batch actions and categories to admin UI for custom emojis (#11793)
parent
39e904f9c1
commit
25fb124ee6
@ -0,0 +1,106 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Form::CustomEmojiBatch
|
||||||
|
include ActiveModel::Model
|
||||||
|
include Authorization
|
||||||
|
include AccountableConcern
|
||||||
|
|
||||||
|
attr_accessor :custom_emoji_ids, :action, :current_account,
|
||||||
|
:category_id, :category_name, :visible_in_picker
|
||||||
|
|
||||||
|
def save
|
||||||
|
case action
|
||||||
|
when 'update'
|
||||||
|
update!
|
||||||
|
when 'list'
|
||||||
|
list!
|
||||||
|
when 'unlist'
|
||||||
|
unlist!
|
||||||
|
when 'enable'
|
||||||
|
enable!
|
||||||
|
when 'disable'
|
||||||
|
disable!
|
||||||
|
when 'copy'
|
||||||
|
copy!
|
||||||
|
when 'delete'
|
||||||
|
delete!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def custom_emojis
|
||||||
|
CustomEmoji.where(id: custom_emoji_ids)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update!
|
||||||
|
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) }
|
||||||
|
|
||||||
|
category = begin
|
||||||
|
if category_id.present?
|
||||||
|
CustomEmojiCategory.find(category_id)
|
||||||
|
elsif category_name.present?
|
||||||
|
CustomEmojiCategory.create!(name: category_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
custom_emojis.each do |custom_emoji|
|
||||||
|
custom_emoji.update(category_id: category&.id)
|
||||||
|
log_action :update, custom_emoji
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def list!
|
||||||
|
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) }
|
||||||
|
|
||||||
|
custom_emojis.each do |custom_emoji|
|
||||||
|
custom_emoji.update(visible_in_picker: true)
|
||||||
|
log_action :update, custom_emoji
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def unlist!
|
||||||
|
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) }
|
||||||
|
|
||||||
|
custom_emojis.each do |custom_emoji|
|
||||||
|
custom_emoji.update(visible_in_picker: false)
|
||||||
|
log_action :update, custom_emoji
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def enable!
|
||||||
|
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :enable?) }
|
||||||
|
|
||||||
|
custom_emojis.each do |custom_emoji|
|
||||||
|
custom_emoji.update(disabled: false)
|
||||||
|
log_action :enable, custom_emoji
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def disable!
|
||||||
|
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :disable?) }
|
||||||
|
|
||||||
|
custom_emojis.each do |custom_emoji|
|
||||||
|
custom_emoji.update(disabled: true)
|
||||||
|
log_action :disable, custom_emoji
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def copy!
|
||||||
|
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :copy?) }
|
||||||
|
|
||||||
|
custom_emojis.each do |custom_emoji|
|
||||||
|
copied_custom_emoji = custom_emoji.copy!
|
||||||
|
log_action :create, copied_custom_emoji
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete!
|
||||||
|
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :destroy?) }
|
||||||
|
|
||||||
|
custom_emojis.each do |custom_emoji|
|
||||||
|
custom_emoji.destroy
|
||||||
|
log_action :destroy, custom_emoji
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,28 +1,31 @@
|
|||||||
%tr
|
.batch-table__row
|
||||||
%td
|
%label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox
|
||||||
= custom_emoji_tag(custom_emoji)
|
= f.check_box :custom_emoji_ids, { multiple: true, include_hidden: false }, custom_emoji.id
|
||||||
%td
|
.batch-table__row__content.batch-table__row__content--with-image
|
||||||
%samp= ":#{custom_emoji.shortcode}:"
|
.batch-table__row__content__image
|
||||||
%td
|
= custom_emoji_tag(custom_emoji)
|
||||||
- if custom_emoji.local?
|
|
||||||
= t('admin.accounts.location.local')
|
.batch-table__row__content__text
|
||||||
- else
|
%samp= ":#{custom_emoji.shortcode}:"
|
||||||
= link_to custom_emoji.domain, admin_custom_emojis_path(by_domain: custom_emoji.domain)
|
|
||||||
%td
|
- if custom_emoji.local?
|
||||||
- if custom_emoji.local?
|
%span.account-role.bot= custom_emoji.category&.name || t('admin.custom_emojis.uncategorized')
|
||||||
- if custom_emoji.visible_in_picker
|
|
||||||
= table_link_to 'eye', t('admin.custom_emojis.listed'), admin_custom_emoji_path(custom_emoji, custom_emoji: { visible_in_picker: false }, page: params[:page], **@filter_params), method: :patch
|
.batch-table__row__content__extra
|
||||||
|
- if custom_emoji.local?
|
||||||
|
= t('admin.accounts.location.local')
|
||||||
- else
|
- else
|
||||||
= table_link_to 'eye-slash', t('admin.custom_emojis.unlisted'), admin_custom_emoji_path(custom_emoji, custom_emoji: { visible_in_picker: true }, page: params[:page], **@filter_params), method: :patch
|
= custom_emoji.domain
|
||||||
- else
|
|
||||||
- if custom_emoji.local_counterpart.present?
|
%br/
|
||||||
= link_to safe_join([custom_emoji_tag(custom_emoji.local_counterpart), t('admin.custom_emojis.overwrite')]), copy_admin_custom_emoji_path(custom_emoji, page: params[:page], **@filter_params), method: :post, class: 'table-action-link'
|
|
||||||
|
- if custom_emoji.disabled?
|
||||||
|
= t('admin.custom_emojis.disabled')
|
||||||
- else
|
- else
|
||||||
= table_link_to 'copy', t('admin.custom_emojis.copy'), copy_admin_custom_emoji_path(custom_emoji, page: params[:page], **@filter_params), method: :post
|
= t('admin.custom_emojis.enabled')
|
||||||
%td
|
- if custom_emoji.local?
|
||||||
- if custom_emoji.disabled?
|
•
|
||||||
= table_link_to 'power-off', t('admin.custom_emojis.enable'), enable_admin_custom_emoji_path(custom_emoji, page: params[:page], **@filter_params), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
|
- if custom_emoji.visible_in_picker?
|
||||||
- else
|
= t('admin.custom_emojis.listed')
|
||||||
= table_link_to 'power-off', t('admin.custom_emojis.disable'), disable_admin_custom_emoji_path(custom_emoji, page: params[:page], **@filter_params), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
|
- else
|
||||||
%td
|
= t('admin.custom_emojis.unlisted')
|
||||||
= table_link_to 'times', t('admin.custom_emojis.delete'), admin_custom_emoji_path(custom_emoji, page: params[:page], **@filter_params), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') }
|
|
||||||
|
Loading…
Reference in new issue