gab-social/app/controllers/admin/preview_cards_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

62 lines
1.5 KiB
Ruby

# 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