This commit is contained in:
parent
38fc1b498d
commit
a56c4742d3
|
@ -3,6 +3,7 @@
|
||||||
module Admin
|
module Admin
|
||||||
class CustomEmojisController < BaseController
|
class CustomEmojisController < BaseController
|
||||||
before_action :set_custom_emoji, except: [:index, :new, :create]
|
before_action :set_custom_emoji, except: [:index, :new, :create]
|
||||||
|
before_action :set_filter_params
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize :custom_emoji, :index?
|
authorize :custom_emoji, :index?
|
||||||
|
@ -32,23 +33,26 @@ module Admin
|
||||||
|
|
||||||
if @custom_emoji.update(resource_params)
|
if @custom_emoji.update(resource_params)
|
||||||
log_action :update, @custom_emoji
|
log_action :update, @custom_emoji
|
||||||
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.updated_msg')
|
flash[:notice] = I18n.t('admin.custom_emojis.updated_msg')
|
||||||
else
|
else
|
||||||
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.update_failed_msg')
|
flash[:alert] = I18n.t('admin.custom_emojis.update_failed_msg')
|
||||||
end
|
end
|
||||||
|
redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
authorize @custom_emoji, :destroy?
|
authorize @custom_emoji, :destroy?
|
||||||
@custom_emoji.destroy!
|
@custom_emoji.destroy!
|
||||||
log_action :destroy, @custom_emoji
|
log_action :destroy, @custom_emoji
|
||||||
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.destroyed_msg')
|
flash[:notice] = I18n.t('admin.custom_emojis.destroyed_msg')
|
||||||
|
redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def copy
|
def copy
|
||||||
authorize @custom_emoji, :copy?
|
authorize @custom_emoji, :copy?
|
||||||
|
|
||||||
emoji = CustomEmoji.find_or_initialize_by(domain: nil, shortcode: @custom_emoji.shortcode)
|
emoji = CustomEmoji.find_or_initialize_by(domain: nil,
|
||||||
|
shortcode: @custom_emoji.shortcode)
|
||||||
emoji.image = @custom_emoji.image
|
emoji.image = @custom_emoji.image
|
||||||
|
|
||||||
if emoji.save
|
if emoji.save
|
||||||
|
@ -58,21 +62,23 @@ module Admin
|
||||||
flash[:alert] = I18n.t('admin.custom_emojis.copy_failed_msg')
|
flash[:alert] = I18n.t('admin.custom_emojis.copy_failed_msg')
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to admin_custom_emojis_path(page: params[:page])
|
redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def enable
|
def enable
|
||||||
authorize @custom_emoji, :enable?
|
authorize @custom_emoji, :enable?
|
||||||
@custom_emoji.update!(disabled: false)
|
@custom_emoji.update!(disabled: false)
|
||||||
log_action :enable, @custom_emoji
|
log_action :enable, @custom_emoji
|
||||||
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.enabled_msg')
|
flash[:notice] = I18n.t('admin.custom_emojis.enabled_msg')
|
||||||
|
redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable
|
def disable
|
||||||
authorize @custom_emoji, :disable?
|
authorize @custom_emoji, :disable?
|
||||||
@custom_emoji.update!(disabled: true)
|
@custom_emoji.update!(disabled: true)
|
||||||
log_action :disable, @custom_emoji
|
log_action :disable, @custom_emoji
|
||||||
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.disabled_msg')
|
flash[:notice] = I18n.t('admin.custom_emojis.disabled_msg')
|
||||||
|
redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -81,6 +87,10 @@ module Admin
|
||||||
@custom_emoji = CustomEmoji.find(params[:id])
|
@custom_emoji = CustomEmoji.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_filter_params
|
||||||
|
@filter_params = filter_params.to_hash.symbolize_keys
|
||||||
|
end
|
||||||
|
|
||||||
def resource_params
|
def resource_params
|
||||||
params.require(:custom_emoji).permit(:shortcode, :image, :visible_in_picker)
|
params.require(:custom_emoji).permit(:shortcode, :image, :visible_in_picker)
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,18 +11,18 @@
|
||||||
%td
|
%td
|
||||||
- if custom_emoji.local?
|
- if custom_emoji.local?
|
||||||
- if custom_emoji.visible_in_picker
|
- 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 }), method: :patch
|
= 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
|
||||||
- else
|
- else
|
||||||
= table_link_to 'eye-slash', t('admin.custom_emojis.unlisted'), admin_custom_emoji_path(custom_emoji, custom_emoji: { visible_in_picker: true }), method: :patch
|
= 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
|
||||||
- else
|
- else
|
||||||
- if custom_emoji.local_counterpart.present?
|
- if custom_emoji.local_counterpart.present?
|
||||||
= 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]), method: :post, class: 'table-action-link'
|
= 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'
|
||||||
- else
|
- else
|
||||||
= table_link_to 'copy', t('admin.custom_emojis.copy'), copy_admin_custom_emoji_path(custom_emoji, page: params[:page]), method: :post
|
= table_link_to 'copy', t('admin.custom_emojis.copy'), copy_admin_custom_emoji_path(custom_emoji, page: params[:page], **@filter_params), method: :post
|
||||||
%td
|
%td
|
||||||
- if custom_emoji.disabled?
|
- if custom_emoji.disabled?
|
||||||
= table_link_to 'power-off', t('admin.custom_emojis.enable'), enable_admin_custom_emoji_path(custom_emoji), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
|
= 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') }
|
||||||
- else
|
- else
|
||||||
= table_link_to 'power-off', t('admin.custom_emojis.disable'), disable_admin_custom_emoji_path(custom_emoji), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
|
= 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') }
|
||||||
%td
|
%td
|
||||||
= table_link_to 'times', t('admin.custom_emojis.delete'), admin_custom_emoji_path(custom_emoji), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') }
|
= 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') }
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
.actions
|
.actions
|
||||||
%button= t('admin.accounts.search')
|
%button= t('admin.accounts.search')
|
||||||
= link_to t('admin.accounts.reset'), admin_accounts_path, class: 'button negative'
|
= link_to t('admin.accounts.reset'), admin_custom_emojis_path, class: 'button negative'
|
||||||
|
|
||||||
.table-wrapper
|
.table-wrapper
|
||||||
%table.table
|
%table.table
|
||||||
|
|
Loading…
Reference in New Issue