Add username filter with UI to admin donations page
This commit is contained in:
parent
71352d13d2
commit
04094efbdb
@ -4,11 +4,21 @@ class Admin::DonationsController < Admin::BaseController
|
|||||||
|
|
||||||
# GET /donations
|
# GET /donations
|
||||||
def index
|
def index
|
||||||
@pagy, @donations = pagy(Donation.completed.order('paid_at desc'))
|
@username = params[:username].presence
|
||||||
@pending_donations = Donation.incomplete.order('paid_at desc')
|
|
||||||
|
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 = {
|
@stats = {
|
||||||
overall_sats: @donations.sum("amount_sats"),
|
overall_sats: Donation.completed.sum("amount_sats"),
|
||||||
donor_count: Donation.completed.count(:user_id)
|
donor_count: Donation.completed.count(:user_id)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<table class="divided mb-8">
|
<table class="divided">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>User</th>
|
<th>User</th>
|
||||||
@ -28,5 +28,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<% if defined?(pagy) %>
|
<% if defined?(pagy) %>
|
||||||
<%== pagy_nav pagy %>
|
<div class="mt-8">
|
||||||
|
<%== pagy_nav pagy %>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -18,7 +18,21 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<% if @pending_donations.any? %>
|
<section>
|
||||||
|
<%= form_with url: admin_donations_path, method: :get, local: true, class: "flex gap-1" do %>
|
||||||
|
<%= text_field_tag :username, @username, placeholder: 'Filter by username' %>
|
||||||
|
<%= button_tag type: 'submit', name: nil, title: "Filter", class: 'btn-md btn-icon btn-outline' do %>
|
||||||
|
<%= render partial: "icons/filter", locals: { custom_class: "text-blue-600 h-4 w-4 inline" } %>
|
||||||
|
<% end %>
|
||||||
|
<% if @username %>
|
||||||
|
<%= link_to admin_donations_path, title: "Remove filter", class: 'btn-md btn-icon btn-outline' do %>
|
||||||
|
<%= render partial: "icons/x", locals: { custom_class: "text-red-600 h-4 w-4 inline" } %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<% if @pending_donations.present? %>
|
||||||
<section>
|
<section>
|
||||||
<h3>Pending</h3>
|
<h3>Pending</h3>
|
||||||
<%= render partial: "admin/donations/list", locals: {
|
<%= render partial: "admin/donations/list", locals: {
|
||||||
@ -28,8 +42,8 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<% if @donations.any? %>
|
<% if @donations.present? %>
|
||||||
<h3>Recent</h3>
|
<h3>Received</h3>
|
||||||
<%= render partial: "admin/donations/list", locals: {
|
<%= render partial: "admin/donations/list", locals: {
|
||||||
donations: @donations, pagy: @pagy
|
donations: @donations, pagy: @pagy
|
||||||
} %>
|
} %>
|
||||||
|
@ -1 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-filter"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"></polygon></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-filter <%= custom_class %>"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"></polygon></svg>
|
||||||
|
Before Width: | Height: | Size: 290 B After Width: | Height: | Size: 311 B |
Loading…
x
Reference in New Issue
Block a user