gab-social/app/controllers/admin/chat_messages_controller.rb
mgabdev 51fa8f2eb4 Added/Updated admin dashboard tables
• Added:
- New Account filtering
- PreviewCard viewing/sorting/filtering deleting (todo)
- DeletePreviewCardWorker, Service
- Status viewing/sorting/filtering deleting
- ChatMessage viewing/sorting/filtering deleting (todo)
- Account > Follows view

• Updated:
- LinkBlock to sort alphabetically
- Groups to be under "Moderation" instead of "Admin" in navigation.rb
- Status in admin to have group name/link
- Reports reset button
- Group filtering/sorting
- LinkBlock filtering/sorting
- Account now has bio and few more data points in dashboard
2021-01-19 01:25:25 -05:00

71 lines
1.7 KiB
Ruby

# frozen_string_literal: true
module Admin
class ChatMessagesController < BaseController
PER_PAGE = 50
def index
authorize :chat_message, :index?
@chat_messages = filtered_chat_messages.page(params[:page]).per(PER_PAGE)
@form = Form::ChatMessageBatch.new
end
def show
authorize :chat_message, :index?
@chat_message = ChatMessage.where(id: params[:id])
authorize @chat_message, :show?
@form = Form::ChatMessageBatch.new
end
def create
authorize :chat_message, :update?
@form = Form::ChatMessageBatch.new(form_chat_message_batch_params.merge(current_account: current_account, action: action_from_button))
flash[:alert] = I18n.t('admin.statuses.failed_to_execute') unless @form.save
redirect_to admin_account_chat_messages_path(@account.id, current_params)
rescue ActionController::ParameterMissing
flash[:alert] = I18n.t('admin.statuses.no_status_selected')
redirect_to admin_account_chat_messages_path(@account.id, current_params)
end
private
def filtered_chat_messages
ChatMessageFilter.new(filter_params).results
end
def form_chat_message_batch_params
params.require(:form_chat_message_batch).permit(:action, chat_message_ids: [])
end
def current_params
page = (params[:page] || 1).to_i
{
page: page > 1 && page,
}.select { |_, value| value.present? }
end
def action_from_button
if params[:delete]
'delete'
end
end
def filter_params
params.permit(
:id,
:text,
:account_id,
:created_at_lte,
:created_at_gte
)
end
end
end