From 362be963c0b517198bb6ecc05bb494fbbedf7e8c Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 19 Nov 2025 13:43:02 -0500 Subject: [PATCH] Add a very rudimentary admin dashboard. --- app/controllers/admin/stats_controller.rb | 19 ++++++ app/views/admin/stats/show.html.erb | 76 +++++++++++++++++++++++ config/routes.rb | 1 + 3 files changed, 96 insertions(+) create mode 100644 app/controllers/admin/stats_controller.rb create mode 100644 app/views/admin/stats/show.html.erb diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb new file mode 100644 index 000000000..68fc3f9e4 --- /dev/null +++ b/app/controllers/admin/stats_controller.rb @@ -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 diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb new file mode 100644 index 000000000..678e78e71 --- /dev/null +++ b/app/views/admin/stats/show.html.erb @@ -0,0 +1,76 @@ +<% @page_title = "Account Statistics" %> + +<% content_for :header do %> +

<%= @page_title %>

+<% end %> + +
+
+
+

Recent Activity

+
+ +
+
+
Accounts Created
+
+
+
7 days
+
+ <%= @accounts_last_7_days %> +
+
+
+
24 hours
+
+ <%= @accounts_last_24_hours %> +
+
+
+
+ +
+
Identities Created
+
+
+
7 days
+
+ <%= @identities_last_7_days %> +
+
+
+
24 hours
+
+ <%= @identities_last_24_hours %> +
+
+
+
+
+
+ +
+
+

+ Top 10 Accounts by Card Count +

+
+ +
    + <% @top_accounts.each do |account| %> + <% admin_user = account.users.find { |u| u.role == "admin" } %> +
  • +
    + <%= account.name %> + • #<%= account.external_account_id %> • <%= admin_user&.identity&.email_address || "No admin" %> +
    + +
    + <%= number_with_delimiter(account.cards_count) %> + cards +
    +
  • + <% end %> +
+
+
diff --git a/config/routes.rb b/config/routes.rb index e165802e0..1fd25a50e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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