Add username filter with UI to admin donations page
This commit is contained in:
@@ -4,11 +4,21 @@ class Admin::DonationsController < Admin::BaseController
|
||||
|
||||
# GET /donations
|
||||
def index
|
||||
@pagy, @donations = pagy(Donation.completed.order('paid_at desc'))
|
||||
@pending_donations = Donation.incomplete.order('paid_at desc')
|
||||
@username = params[:username].presence
|
||||
|
||||
pending_scope = Donation.incomplete.joins(:user).order('paid_at desc')
|
||||
completed_scope = Donation.completed.joins(:user).order('paid_at desc')
|
||||
|
||||
if @username
|
||||
pending_scope = pending_scope.where(users: { cn: @username })
|
||||
completed_scope = completed_scope.where(users: { cn: @username })
|
||||
end
|
||||
|
||||
@pending_donations = pending_scope
|
||||
@pagy, @donations = pagy(completed_scope)
|
||||
|
||||
@stats = {
|
||||
overall_sats: @donations.sum("amount_sats"),
|
||||
overall_sats: Donation.completed.sum("amount_sats"),
|
||||
donor_count: Donation.completed.count(:user_id)
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user