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
This commit is contained in:
mgabdev
2021-01-19 01:25:25 -05:00
parent 24fa2d3a74
commit 51fa8f2eb4
39 changed files with 697 additions and 108 deletions

View File

@@ -0,0 +1,76 @@
# frozen_string_literal: true
module Admin
class AccountStatusesController < BaseController
helper_method :current_params
before_action :set_account
PER_PAGE = 20
def index
authorize :status, :index?
@statuses = @account.statuses
if params[:media]
account_media_status_ids = @account.media_attachments.attached.reorder(nil).select(:status_id).distinct
@statuses.merge!(Status.where(id: account_media_status_ids))
end
@statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
@form = Form::StatusBatch.new
end
def show
authorize :status, :index?
@statuses = @account.statuses.where(id: params[:id])
authorize @statuses.first, :show?
@form = Form::StatusBatch.new
end
def create
authorize :status, :update?
@form = Form::StatusBatch.new(form_status_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_account_statuses_path(@account.id, current_params)
rescue ActionController::ParameterMissing
flash[:alert] = I18n.t('admin.statuses.no_status_selected')
redirect_to admin_account_account_statuses_path(@account.id, current_params)
end
private
def form_status_batch_params
params.require(:form_status_batch).permit(:action, status_ids: [])
end
def set_account
@account = Account.find(params[:account_id])
end
def current_params
page = (params[:page] || 1).to_i
{
media: params[:media],
page: page > 1 && page,
}.select { |_, value| value.present? }
end
def action_from_button
if params[:nsfw_on]
'nsfw_on'
elsif params[:nsfw_off]
'nsfw_off'
elsif params[:delete]
'delete'
end
end
end
end

View File

@@ -205,7 +205,10 @@ module Admin
:display_name,
:email,
:ip,
:staff
:staff,
:note,
:status_count_gte,
:sign_up_date_gte,
)
end

View File

@@ -2,22 +2,20 @@
module Admin
class ChatMessagesController < BaseController
before_action :set_account
PER_PAGE = 100
PER_PAGE = 50
def index
authorize :chat_message, :index?
@chat_messages = ChatMessage.where(from_account: @account).page(params[:page]).per(PER_PAGE)
@chat_messages = filtered_chat_messages.page(params[:page]).per(PER_PAGE)
@form = Form::ChatMessageBatch.new
end
def show
authorize :chat_message, :index?
@chat_messages = @account.chat_messages.where(id: params[:id])
authorize @chat_messages.first, :show?
@chat_message = ChatMessage.where(id: params[:id])
authorize @chat_message, :show?
@form = Form::ChatMessageBatch.new
end
@@ -37,19 +35,18 @@ module Admin
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 set_account
@account = Account.find(params[:account_id])
end
def current_params
page = (params[:page] || 1).to_i
{
media: params[:media],
page: page > 1 && page,
}.select { |_, value| value.present? }
end
@@ -59,5 +56,15 @@ module Admin
'delete'
end
end
def filter_params
params.permit(
:id,
:text,
:account_id,
:created_at_lte,
:created_at_gte
)
end
end
end

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Admin
class FollowsController < BaseController
before_action :set_account
PER_PAGE = 40
def index
authorize :account, :index?
@follows = @account.following.local.recent.page(params[:page]).per(PER_PAGE)
end
def set_account
@account = Account.find(params[:account_id])
end
end
end

View File

@@ -4,7 +4,6 @@ module Admin
class GroupsController < BaseController
before_action :set_group, except: [:index]
before_action :set_accounts, only: [:show]
before_action :set_filter_params
def index
authorize :group, :index?
@@ -47,10 +46,6 @@ module Admin
@mods = GroupAccount.where(group: @group, role: 'moderator')
end
def set_filter_params
@filter_params = filter_params.to_hash.symbolize_keys
end
def resource_params
params.require(:group).permit(
:title,
@@ -66,16 +61,17 @@ module Admin
end
def filtered_groups
query = Group.order('is_featured DESC, member_count DESC')
if params[:title]
query = query.where("LOWER(title) LIKE LOWER(?)", "%#{params[:title]}%")
end
return query
GroupFilter.new(filter_params).results
end
def filter_params
params.permit(:sort,)
params.permit(
:title,
:description,
:id,
:member_count_gte,
:created_at_gte
)
end
end
end

View File

@@ -6,7 +6,7 @@ module Admin
def index
authorize :link_block, :index?
@link_blocks = LinkBlock.page(params[:page])
@link_blocks = filtered_link_blocks.alphabetical.page(params[:page])
end
def new
@@ -36,10 +36,18 @@ module Admin
private
def filtered_link_blocks
LinkBlockFilter.new(filter_params).results
end
def set_link_block
@link_block = LinkBlock.find(params[:id])
end
def filter_params
params.permit(:link)
end
def resource_params
params.require(:link_block).permit(:link)
end

View File

@@ -0,0 +1,61 @@
# frozen_string_literal: true
module Admin
class PreviewCardsController < BaseController
before_action :set_preview_card, except: [:index]
def index
authorize :preview_card, :index?
@preview_cards = filtered_preview_cards.page(params[:page])
@form = Form::PreviewCardBatch.new
end
def show
authorize @preview_card, :show?
@form = Form::PreviewCardBatch.new
end
def create
authorize :preview_card, :update?
@form = Form::PreviewCardBatch.new(form_preview_card_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_preview_cards_path(@account.id, current_params)
rescue ActionController::ParameterMissing
flash[:alert] = I18n.t('admin.statuses.no_status_selected')
redirect_to admin_preview_cards_path(@account.id, current_params)
end
private
def form_preview_card_batch_params
params.require(:form_preview_card_batch).permit(:action, preview_card_ids: [])
end
def filtered_preview_cards
PreviewCardFilter.new(filter_params).results.order(id: :desc)
end
def filter_params
params.permit(
:title,
:description,
:url,
)
end
def set_preview_card
@preview_card = PreviewCard.find(params[:id])
end
def action_from_button
if params[:delete]
'delete'
end
end
end
end

View File

@@ -4,21 +4,12 @@ module Admin
class StatusesController < BaseController
helper_method :current_params
before_action :set_account
PER_PAGE = 20
def index
authorize :status, :index?
@statuses = @account.statuses.where(visibility: [:public, :unlisted])
if params[:media]
account_media_status_ids = @account.media_attachments.attached.reorder(nil).select(:status_id).distinct
@statuses.merge!(Status.where(id: account_media_status_ids))
end
@statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
@statuses = filtered_statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
@form = Form::StatusBatch.new
end
@@ -37,11 +28,11 @@ module Admin
@form = Form::StatusBatch.new(form_status_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_statuses_path(@account.id, current_params)
redirect_to admin_statuses_path(current_params)
rescue ActionController::ParameterMissing
flash[:alert] = I18n.t('admin.statuses.no_status_selected')
redirect_to admin_account_statuses_path(@account.id, current_params)
redirect_to admin_statuses_path(current_params)
end
private
@@ -50,8 +41,8 @@ module Admin
params.require(:form_status_batch).permit(:action, status_ids: [])
end
def set_account
@account = Account.find(params[:account_id])
def filtered_statuses
StatusFilter.new(nil, nil, nil, filter_params).results
end
def current_params
@@ -63,6 +54,18 @@ module Admin
}.select { |_, value| value.present? }
end
def filter_params
params.permit(
:text,
:id,
:account_id,
:group_id,
:preview_card_id,
:created_at_lte,
:created_at_gte
)
end
def action_from_button
if params[:nsfw_on]
'nsfw_on'
@@ -72,5 +75,6 @@ module Admin
'delete'
end
end
end
end