stats menu fix
This commit is contained in:
@@ -12,58 +12,49 @@ ActiveAdmin.register Download do
|
||||
|
||||
config.sort_order = "created_at_desc"
|
||||
|
||||
sidebar "Summary", only: :index do
|
||||
dl style: "display:grid;grid-template-columns:1fr auto;gap:6px 12px;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
|
||||
|
||||
sidebar "Top 10 Files", only: :index 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.split("/").last, style: "font-family:monospace;font-size:11px;" }
|
||||
column("DL") { |row| row.dl_count }
|
||||
end
|
||||
end
|
||||
|
||||
sidebar "Top 5 Software", only: :index do
|
||||
rows = Download.joins(release: :software)
|
||||
.group("softwares.title")
|
||||
.order("count_all DESC")
|
||||
.limit(5)
|
||||
.count
|
||||
if rows.any?
|
||||
table_for rows do
|
||||
column("Software") { |title, _| title }
|
||||
column("DL") { |_, count| count }
|
||||
end
|
||||
else
|
||||
para "No data", style: "color:#999;font-style:italic;"
|
||||
end
|
||||
end
|
||||
|
||||
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 || "–" }
|
||||
|
||||
Reference in New Issue
Block a user