The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

77 lines
1.9 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class CustomEmojisController < BaseController
  4. def index
  5. authorize :custom_emoji, :index?
  6. @custom_emojis = filtered_custom_emojis.eager_load(:local_counterpart).page(params[:page])
  7. @form = Form::CustomEmojiBatch.new
  8. end
  9. def new
  10. authorize :custom_emoji, :create?
  11. @custom_emoji = CustomEmoji.new
  12. end
  13. def create
  14. authorize :custom_emoji, :create?
  15. @custom_emoji = CustomEmoji.new(resource_params)
  16. if @custom_emoji.save
  17. log_action :create, @custom_emoji
  18. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.created_msg')
  19. else
  20. render :new
  21. end
  22. end
  23. def batch
  24. @form = Form::CustomEmojiBatch.new(form_custom_emoji_batch_params.merge(current_account: current_account, action: action_from_button))
  25. @form.save
  26. rescue ActionController::ParameterMissing
  27. flash[:alert] = I18n.t('admin.accounts.no_account_selected')
  28. ensure
  29. redirect_to admin_custom_emojis_path(filter_params)
  30. end
  31. private
  32. def resource_params
  33. params.require(:custom_emoji).permit(:shortcode, :image, :visible_in_picker)
  34. end
  35. def filtered_custom_emojis
  36. CustomEmojiFilter.new(filter_params).results
  37. end
  38. def filter_params
  39. params.slice(:page, *CustomEmojiFilter::KEYS).permit(:page, *CustomEmojiFilter::KEYS)
  40. end
  41. def action_from_button
  42. if params[:update]
  43. 'update'
  44. elsif params[:list]
  45. 'list'
  46. elsif params[:unlist]
  47. 'unlist'
  48. elsif params[:enable]
  49. 'enable'
  50. elsif params[:disable]
  51. 'disable'
  52. elsif params[:copy]
  53. 'copy'
  54. elsif params[:delete]
  55. 'delete'
  56. end
  57. end
  58. def form_custom_emoji_batch_params
  59. params.require(:form_custom_emoji_batch).permit(:action, :category_id, :category_name, custom_emoji_ids: [])
  60. end
  61. end
  62. end