Skip to content

Commit

Permalink
Add: カスタム絵文字の専用編集画面
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Oct 17, 2023
1 parent 72d18cb commit 8e79047
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
27 changes: 27 additions & 0 deletions app/controllers/admin/custom_emojis_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Admin
class CustomEmojisController < BaseController
before_action :set_custom_emoji, only: [:edit, :update]

def index
authorize :custom_emoji, :index?

Expand All @@ -15,6 +17,10 @@ def new
@custom_emoji = CustomEmoji.new
end

def edit
authorize :custom_emoji, :create?
end

def create
authorize :custom_emoji, :create?

Expand All @@ -28,6 +34,19 @@ def create
end
end

def update
authorize :custom_emoji, :create?

@custom_emoji.assign_attributes(update_params)

if @custom_emoji.save
log_action :create, @custom_emoji
redirect_to admin_custom_emojis_path(filter_params), notice: I18n.t('admin.custom_emojis.updated_msg')
else
render :new
end
end

def batch
authorize :custom_emoji, :index?

Expand All @@ -43,10 +62,18 @@ def batch

private

def set_custom_emoji
@custom_emoji = CustomEmoji.find(params[:id])
end

def resource_params
params.require(:custom_emoji).permit(:shortcode, :image, :visible_in_picker)
end

def update_params
params.require(:custom_emoji).permit(:visible_in_picker, :aliases_raw, :license)
end

def filtered_custom_emojis
CustomEmojiFilter.new(filter_params).results
end
Expand Down
7 changes: 6 additions & 1 deletion app/views/admin/custom_emojis/_custom_emoji.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@

.batch-table__row__content__text
%samp= ":#{custom_emoji.shortcode}:"
= link_to safe_join([fa_icon('pencil'), t('admin.custom_emojis.edit.label')]), edit_admin_custom_emoji_path(custom_emoji, local: params[:local], remote: params[:remote], shortcode: params[:shortcode], by_domain: params[:by_domain]), method: :get, class: 'table-action-link'

- if custom_emoji.local?
%span.information-badge= custom_emoji.category&.name || t('admin.custom_emojis.uncategorized')
- if custom_emoji.aliases_raw.present?
%br/
%span= custom_emoji.aliases_raw
%span.neutral-hint= custom_emoji.aliases_raw
- if custom_emoji.license.present?
%br/
%span= custom_emoji.license

.batch-table__row__content__extra
- if custom_emoji.local?
Expand Down
39 changes: 39 additions & 0 deletions app/views/admin/custom_emojis/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
- content_for :page_title do
= t('.title')

= simple_form_for @custom_emoji, url: admin_custom_emoji_path(@custom_emoji.id), method: :put do |f|
= render 'shared/error_messages', object: @custom_emoji
- CustomEmojiFilter::KEYS.each do |key|
= hidden_field_tag key, params[key] if params[key].present?

%h4= t('admin.custom_emojis.shortcode')

.fields-group
%samp= @custom_emoji.shortcode

- if !@custom_emoji.local?
%h4= t('admin.custom_emojis.domain')

.fields-group
%samp= @custom_emoji.domain

- if @custom_emoji.local?
%h4= t('admin.custom_emojis.edit.label')

.fields-group
= f.input :visible_in_picker, as: :boolean, wrapper: :with_label, label: t('admin.custom_emojis.visible_in_picker')

.fields-group
= f.input :aliases_raw, wrapper: :with_label, kmyblue: true, label: t('admin.custom_emojis.aliases'), hint: t('admin.custom_emojis.aliases_hint')

.fields-group
= f.input :license, wrapper: :with_label, kmyblue: true, label: t('admin.custom_emojis.license'), hint: t('admin.custom_emojis.license_hint')

.actions
= f.button :button, t('generic.save_changes'), type: :submit

- elsif @custom_emoji.license.present?
%h4= t('admin.custom_emojis.license')

.fields-group
%p= @custom_emoji.license
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ en:
updated_msg: Announcement successfully updated!
critical_update_pending: Critical update pending
custom_emojis:
aliases: Alias names
aliases_hint: When searching within the pictogram picker, you can search not only by short code, but also by alias name. You can specify multiple alias names by separating them with "," (comma).
assign_category: Assign category
by_domain: Domain
copied_msg: Successfully created local copy of the emoji
Expand All @@ -328,11 +330,17 @@ en:
disable: Disable
disabled: Disabled
disabled_msg: Successfully disabled that emoji
domain: Domain
edit:
label: Edit
title: Edit custom emoji
emoji: Emoji
enable: Enable
enabled: Enabled
enabled_msg: Successfully enabled that emoji
image_hint: PNG or GIF up to %{size}
license: License
license_hint: Set license information for custom pictograms. However, many servers do not support the federation of license information, and Misskey also supports license information for local pictograms, but does not reference license information from other servers. Consider that licenses may be ignored.
list: List
listed: Listed
new:
Expand All @@ -349,6 +357,7 @@ en:
update_failed_msg: Could not update that emoji
updated_msg: Emoji successfully updated!
upload: Upload
visible_in_picker: Visible in emoji picker
dashboard:
active_users: active users
interactions: interactions
Expand Down
9 changes: 9 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ ja:
updated_msg: お知らせを更新しました
critical_update_pending: 重要な更新が保留中です
custom_emojis:
aliases: エイリアス名
aliases_hint: 絵文字ピッカー内で検索する際、ショートコードだけでなくエイリアス名でも検索できます。「,」(カンマ)で区切ることで、複数指定が可能です。
assign_category: カテゴリーを割り当て
by_domain: ドメイン
copied_msg: 絵文字のコピーをローカルに作成しました
Expand All @@ -325,11 +327,17 @@ ja:
disable: 無効化
disabled: 無効
disabled_msg: 絵文字を無効化しました
domain: ドメイン
edit:
label: 編集
title: カスタム絵文字の編集
emoji: 絵文字
enable: 有効化
enabled: 有効
enabled_msg: 絵文字を有効化しました
image_hint: '%{size}までのPNGまたはGIF画像を利用できます'
license: ライセンス
license_hint: カスタム絵文字のライセンス情報を設定します。ただしライセンス情報の連合に対応していないサーバーも多く、Misskeyもローカル絵文字のライセンス情報には対応しますが他のサーバーのライセンス情報は参照しません。ライセンスは無視される場合があることを考慮してください。
list: 表示
listed: 表示
new:
Expand All @@ -346,6 +354,7 @@ ja:
update_failed_msg: 絵文字を更新できませんでした
updated_msg: 絵文字の更新に成功しました!
upload: アップロード
visible_in_picker: 絵文字ピッカーで表示
dashboard:
active_users: アクティブユーザー
interactions: 交流
Expand Down
2 changes: 1 addition & 1 deletion config/routes/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
resource :role, only: [:show, :update], controller: 'users/roles'
end

resources :custom_emojis, only: [:index, :new, :create] do
resources :custom_emojis, only: [:index, :new, :create, :edit, :update] do
collection do
post :batch
end
Expand Down

0 comments on commit 8e79047

Please sign in to comment.