Add pagination to admin pages
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Râu Cao 2023-03-01 17:08:36 +08:00
parent 3aad27c7bd
commit cbbb4c6e47
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
6 changed files with 11 additions and 6 deletions

View File

@ -5,7 +5,8 @@ class Admin::DonationsController < Admin::BaseController
# GET /donations # GET /donations
# GET /donations.json # GET /donations.json
def index def index
@donations = Donation.all.order('created_at desc') @pagy, @donations = pagy(Donation.all.order('created_at desc'))
@stats = { @stats = {
overall_sats: @donations.all.sum("amount_sats"), overall_sats: @donations.all.sum("amount_sats"),
donor_count: Donation.distinct.count(:user_id) donor_count: Donation.distinct.count(:user_id)

View File

@ -1,7 +1,8 @@
class Admin::InvitationsController < Admin::BaseController class Admin::InvitationsController < Admin::BaseController
def index def index
@current_section = :invitations @current_section = :invitations
@invitations_used = Invitation.used.order('used_at desc') @pagy, @invitations_used = pagy(Invitation.used.order('used_at desc'))
@stats = { @stats = {
available: Invitation.unused.count, available: Invitation.unused.count,
accepted: @invitations_used.length, accepted: @invitations_used.length,

View File

@ -6,7 +6,7 @@ class Admin::UsersController < Admin::BaseController
ldap = LdapService.new ldap = LdapService.new
@ou = params[:ou] || "kosmos.org" @ou = params[:ou] || "kosmos.org"
@orgs = ldap.fetch_organizations @orgs = ldap.fetch_organizations
@users = User.where(ou: @ou).order(cn: :asc).to_a @pagy, @users = pagy(User.where(ou: @ou).order(cn: :asc))
@stats = { @stats = {
users_confirmed: User.where(ou: @ou).confirmed.count, users_confirmed: User.where(ou: @ou).confirmed.count,

View File

@ -21,7 +21,7 @@
<section> <section>
<% if @donations.any? %> <% if @donations.any? %>
<h3>Recent Donations</h3> <h3>Recent Donations</h3>
<table class="divided"> <table class="divided mb-8">
<thead> <thead>
<tr> <tr>
<th>User</th> <th>User</th>
@ -52,6 +52,7 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%== pagy_nav @pagy %>
<% else %> <% else %>
<p> <p>
No donations yet. No donations yet.

View File

@ -24,7 +24,7 @@
<% if @invitations_used.any? %> <% if @invitations_used.any? %>
<section> <section>
<h3>Recently Accepted</h3> <h3>Recently Accepted</h3>
<table class="divided"> <table class="divided mb-8">
<thead> <thead>
<tr> <tr>
<th>Token</th> <th>Token</th>
@ -44,6 +44,7 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%== pagy_nav @pagy %>
</section> </section>
<% end %> <% end %>
<% end %> <% end %>

View File

@ -30,7 +30,7 @@
<% end %> <% end %>
<section> <section>
<table class="divided"> <table class="divided mb-8">
<thead> <thead>
<tr> <tr>
<th>UID</th> <th>UID</th>
@ -49,5 +49,6 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%== pagy_nav @pagy %>
</section> </section>
<% end %> <% end %>