Add a very rudimentary admin dashboard.

This commit is contained in:
Mike Dalessio
2025-11-19 13:43:02 -05:00
parent 4636b31f06
commit 362be963c0
3 changed files with 96 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
class Admin::StatsController < AdminController
disallow_account_scope
layout "public"
def show
@accounts_last_7_days = Account.where(created_at: 7.days.ago..).count
@accounts_last_24_hours = Account.where(created_at: 24.hours.ago..).count
@identities_last_7_days = Identity.where(created_at: 7.days.ago..).count
@identities_last_24_hours = Identity.where(created_at: 24.hours.ago..).count
@top_accounts = Account
.where("cards_count > 0")
.order(cards_count: :desc)
.limit(10)
.includes(users: :identity)
end
end
+76
View File
@@ -0,0 +1,76 @@
<% @page_title = "Account Statistics" %>
<% content_for :header do %>
<h1 class="header__title"><%= @page_title %></h1>
<% end %>
<section class="settings">
<div class="settings__panel panel shadow center">
<header>
<h2 class="divider txt-medium margin-block-start">Recent Activity</h2>
</header>
<div class="flex gap margin-block-half">
<div class="flex flex-column gap-half flex-item-grow">
<div>Accounts Created</div>
<div class="flex gap-half">
<div class="flex flex-column gap-quarter flex-item-grow">
<div class="txt-x-small">7 days</div>
<div class="txt-large">
<strong><%= @accounts_last_7_days %></strong>
</div>
</div>
<div class="flex flex-column gap-quarter flex-item-grow">
<div class="txt-x-small">24 hours</div>
<div class="txt-large">
<strong><%= @accounts_last_24_hours %></strong>
</div>
</div>
</div>
</div>
<div class="flex flex-column gap-half flex-item-grow">
<div>Identities Created</div>
<div class="flex gap-half">
<div class="flex flex-column gap-quarter flex-item-grow">
<div class="txt-x-small">7 days</div>
<div class="txt-large">
<strong><%= @identities_last_7_days %></strong>
</div>
</div>
<div class="flex flex-column gap-quarter flex-item-grow">
<div class="txt-x-small">24 hours</div>
<div class="txt-large">
<strong><%= @identities_last_24_hours %></strong>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="settings__panel panel shadow center">
<header>
<h2 class="divider txt-medium margin-block-start">
Top 10 Accounts by Card Count
</h2>
</header>
<ul class="margin-block-half">
<% @top_accounts.each do |account| %>
<% admin_user = account.users.find { |u| u.role == "admin" } %>
<li class="flex align-center gap-half margin-block-start-half">
<div class="flex-item-grow min-width overflow-ellipsis">
<strong><%= account.name %></strong>
<span class="txt-x-small txt-ink-medium"> • #<%= account.external_account_id %> • <%= admin_user&.identity&.email_address || "No admin" %></span>
</div>
<div class="txt-medium">
<strong><%= number_with_delimiter(account.cards_count) %></strong>
<span class="txt-x-small txt-ink-medium">cards</span>
</div>
</li>
<% end %>
</ul>
</div>
</section>
+1
View File
@@ -227,5 +227,6 @@ Rails.application.routes.draw do
namespace :admin do
mount MissionControl::Jobs::Engine, at: "/jobs"
get "stats", to: "stats#show"
end
end