From 8e218adea5ced508f9d535f76e99d0068b0be266 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 28 Jul 2026 11:17:09 +0200 Subject: [PATCH] more stat tweaks --- apps/api/app/admin/dashboard.rb | 65 ++------------------------------- apps/api/app/admin/downloads.rb | 51 ++++++++++++++++++++++++++ apps/api/app/admin/files.rb | 26 ++++++++++++- 3 files changed, 80 insertions(+), 62 deletions(-) diff --git a/apps/api/app/admin/dashboard.rb b/apps/api/app/admin/dashboard.rb index 9e85c63..1dfeec4 100644 --- a/apps/api/app/admin/dashboard.rb +++ b/apps/api/app/admin/dashboard.rb @@ -1,66 +1,9 @@ ActiveAdmin.register_page "Dashboard" do - menu priority: 1 + menu false - content title: "Dashboard" do - columns do - column do - panel "Downloads Summary" do - dl style: "display:grid;grid-template-columns:1fr 1fr;gap:8px 16px;margin:0;" do - dt { strong "Total downloads" } - dd { b Download.count.to_s } - - dt { strong "Today" } - dd { b Download.where("created_at >= ?", Date.current.beginning_of_day).count.to_s } - - dt { strong "This week" } - dd { b Download.where("created_at >= ?", 1.week.ago).count.to_s } - - dt { strong "This month" } - dd { b Download.where("created_at >= ?", 1.month.ago).count.to_s } - end - end - end - end - - columns do - column do - panel "Top 10 Downloaded Files" do - table_for Download.group(:file_path) - .select("file_path, COUNT(*) as dl_count, MAX(created_at) as last_dl") - .order("dl_count DESC") - .limit(10) do - column("File") { |row| span row.file_path.truncate(60), style: "font-family:monospace;font-size:12px;" } - column("Downloads") { |row| row.dl_count } - column("Last") { |row| row.last_dl&.strftime("%Y-%m-%d %H:%M") } - end - end - end - - column do - panel "Top 5 Software by Downloads" do - rows = Download.joins(release: :software) - .group("softwares.title") - .order("count_all DESC") - .limit(5) - .count - table_for rows do - column("Software") { |title, _| title } - column("Downloads") { |_, count| count } - end - end - end - end - - columns do - column do - panel "Recent 15 Downloads" do - table_for Download.includes(release: :software).order(created_at: :desc).limit(15) do - column("File") { |d| link_to d.file_path.truncate(50), admin_download_path(d), style: "font-family:monospace;font-size:12px;" } - column("IP") { |d| d.ip_address } - column("Date") { |d| d.created_at.strftime("%Y-%m-%d %H:%M") } - end - end - end + controller do + def index + redirect_to "/admin/softwares" end end end diff --git a/apps/api/app/admin/downloads.rb b/apps/api/app/admin/downloads.rb index 4627c5d..d7ad1ee 100644 --- a/apps/api/app/admin/downloads.rb +++ b/apps/api/app/admin/downloads.rb @@ -13,6 +13,57 @@ ActiveAdmin.register Download do config.sort_order = "created_at_desc" index do + # Summary panels above the table + columns do + column do + panel "Summary" do + dl style: "display:grid;grid-template-columns:1fr 1fr;gap:8px 16px;margin:0;" do + dt { strong "Total" } + dd { b Download.count.to_s } + + dt { strong "Today" } + dd { b Download.where("created_at >= ?", Date.current.beginning_of_day).count.to_s } + + dt { strong "This week" } + dd { b Download.where("created_at >= ?", 1.week.ago).count.to_s } + + dt { strong "This month" } + dd { b Download.where("created_at >= ?", 1.month.ago).count.to_s } + end + end + end + end + + columns do + column do + panel "Top 10 Downloaded Files" do + table_for Download.group(:file_path) + .select("file_path, COUNT(*) as dl_count, MAX(created_at) as last_dl") + .order("dl_count DESC") + .limit(10) do + column("File") { |row| span row.file_path.truncate(60), style: "font-family:monospace;font-size:12px;" } + column("Downloads") { |row| row.dl_count } + column("Last") { |row| row.last_dl&.strftime("%Y-%m-%d %H:%M") } + end + end + end + + column do + panel "Top 5 Software by Downloads" do + rows = Download.joins(release: :software) + .group("softwares.title") + .order("count_all DESC") + .limit(5) + .count + table_for rows do + column("Software") { |title, _| title } + column("Downloads") { |_, count| count } + end + end + end + end + + # Download log table id_column column(:file_path) { |d| span d.file_path.truncate(50), style: "font-family:monospace;font-size:12px;" } column("Software") { |d| d.release&.software&.title || "–" } diff --git a/apps/api/app/admin/files.rb b/apps/api/app/admin/files.rb index efe6d4b..180f88c 100644 --- a/apps/api/app/admin/files.rb +++ b/apps/api/app/admin/files.rb @@ -58,13 +58,24 @@ ActiveAdmin.register_page "Files" do # File listing table class: "fm-table" do + # Pre-fetch download counts for files in current directory + file_entries = entries.select { |e| e[:type] != :directory } + dl_counts = if file_entries.any? + Download.where(file_path: file_entries.map { |e| e[:path] }) + .group(:file_path) + .count + else + {} + end + thead do tr do th "Type", style: "width:60px" th "Name" th "Size", style: "width:100px" + th "DL", style: "width:50px" th "Modified", style: "width:160px" - th "Actions", style: "width:#{picker_mode ? '280' : '180'}px" + th "Actions", style: "width:#{picker_mode ? '340' : '240'}px" end end @@ -83,6 +94,7 @@ ActiveAdmin.register_page "Files" do td "" td "" td "" + td "" end end @@ -102,6 +114,12 @@ ActiveAdmin.register_page "Files" do td do text_node(entry[:size] ? number_to_human_size(entry[:size]) : "") end + td do + if entry[:type] != :directory + count = dl_counts[entry[:path]] || 0 + span count.to_s, style: count > 0 ? "font-weight:bold;" : "color:#999;" + end + end td do text_node(entry[:mtime]&.strftime("%Y-%m-%d %H:%M") || "") end @@ -117,6 +135,12 @@ ActiveAdmin.register_page "Files" do a "Delete", href: "#", class: "fm-action-link fm-danger", onclick: "if(confirm('Delete \\'#{j entry[:name]}\\'?')){document.getElementById('delete-#{entry_id}').submit();}return false;" + # Stats (files only) + if entry[:type] != :directory + text_node " " + a "Stats", href: admin_downloads_path(q: { file_path_cont: entry[:path] }), class: "fm-action-link" + end + # Picker mode: Select button if picker_mode text_node " "