You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.7 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class CustomEmojisController < BaseController
  4. before_action :set_custom_emoji, except: [:index, :new, :create]
  5. def index
  6. @custom_emojis = filtered_custom_emojis.page(params[:page])
  7. end
  8. def new
  9. @custom_emoji = CustomEmoji.new
  10. end
  11. def create
  12. @custom_emoji = CustomEmoji.new(resource_params)
  13. if @custom_emoji.save
  14. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.created_msg')
  15. else
  16. render :new
  17. end
  18. end
  19. def destroy
  20. @custom_emoji.destroy
  21. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.destroyed_msg')
  22. end
  23. def copy
  24. emoji = CustomEmoji.new(domain: nil, shortcode: @custom_emoji.shortcode, image: @custom_emoji.image)
  25. if emoji.save
  26. flash[:notice] = I18n.t('admin.custom_emojis.copied_msg')
  27. else
  28. flash[:alert] = I18n.t('admin.custom_emojis.copy_failed_msg')
  29. end
  30. redirect_to admin_custom_emojis_path(page: params[:page])
  31. end
  32. def enable
  33. @custom_emoji.update!(disabled: false)
  34. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.enabled_msg')
  35. end
  36. def disable
  37. @custom_emoji.update!(disabled: true)
  38. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.disabled_msg')
  39. end
  40. private
  41. def set_custom_emoji
  42. @custom_emoji = CustomEmoji.find(params[:id])
  43. end
  44. def resource_params
  45. params.require(:custom_emoji).permit(:shortcode, :image)
  46. end
  47. def filtered_custom_emojis
  48. CustomEmojiFilter.new(filter_params).results
  49. end
  50. def filter_params
  51. params.permit(
  52. :local,
  53. :remote
  54. )
  55. end
  56. end
  57. end