songtianlun
1286eff996
- Change column header from '访问(日/周/年)' to '访问(DWMY)' to reflect updated metrics. - Adjust metrics to include monthly view count alongside daily, weekly, and yearly counts. This modification improves clarity by explicitly indicating the metrics being displayed in the dashboard, thereby aiding users in understanding the data better.
121 lines
4.9 KiB
Ruby
121 lines
4.9 KiB
Ruby
ActiveAdmin.register_page "Ahoy Dashboard" do
|
|
menu label: "总览", parent: "数据统计", priority: 1
|
|
page_action :toggle_city_status, method: :post do
|
|
city = City.find(params[:city_id])
|
|
city.update(active: !city.active)
|
|
redirect_back(fallback_location: admin_dashboard_path, notice: "城市状态已更新")
|
|
end
|
|
|
|
content title: "总览" do
|
|
columns do
|
|
column do
|
|
panel "访问统计" do
|
|
para "总访问量: #{Ahoy::Visit.count}"
|
|
para "总事件数: #{Ahoy::Event.count}"
|
|
para "独立访客数: #{Ahoy::Visit.distinct.count(:visitor_token)}"
|
|
para "已激活城市数: #{City.active.count}"
|
|
para "未激活城市数: #{City.inactive.count}"
|
|
end
|
|
end
|
|
|
|
column do
|
|
panel "热门城市" do
|
|
table_for City.by_popularity.limit(10) do
|
|
column("城市") { |city| link_to(city.name, admin_city_path(city)) }
|
|
column("访问量") { |city| city.view_count }
|
|
end
|
|
end
|
|
end
|
|
|
|
column do
|
|
panel "热门天气艺术" do
|
|
table_for WeatherArt.by_popularity.limit(10) do
|
|
column("作品") { |art| link_to(art.to_s, admin_weather_art_path(art)) }
|
|
column("访问量") { |art| art.view_count }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
columns do
|
|
column do
|
|
panel "最冷门活跃城市" do
|
|
# table_for City.least_popular_active.limit(10) do
|
|
table_for City.least_popular_active do
|
|
column("ID") { |city| city.id }
|
|
column("城市") { |city| link_to(city.name, admin_city_path(city)) }
|
|
column("访问(DWMY)") { |city| "#{city.view_count(:day)}/#{city.view_count(:week)}/#{city.view_count(:month)}/#{city.view_count(:year)}" }
|
|
column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") }
|
|
column("所属区域") { |city| city.country.name+"/"+city.country.region.name }
|
|
column("图像个数") { |city| city.weather_arts.count }
|
|
column("最后更新时间") { |city| city.last_weather_fetch }
|
|
# column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") }
|
|
column("操作") { |city|
|
|
button_to "停用",
|
|
admin_ahoy_dashboard_toggle_city_status_path(city_id: city.id),
|
|
method: :post,
|
|
data: { confirm: "确定要停用 #{city.name} 吗?" }
|
|
}
|
|
end
|
|
end
|
|
end
|
|
|
|
column do
|
|
panel "热门未活跃城市" do
|
|
# table_for City.most_popular_inactive.limit(10) do
|
|
table_for City.most_popular_inactive do
|
|
column("ID") { |city| city.id }
|
|
column("城市") { |city| link_to(city.name, admin_city_path(city)) }
|
|
column("访问(DWMY)") { |city| "#{city.view_count(:day)}/#{city.view_count(:week)}/#{city.view_count(:month)}/#{city.view_count(:year)}" }
|
|
column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") }
|
|
column("所属区域") { |city| city.country.name+"/"+city.country.region.name }
|
|
column("图像个数") { |city| city.weather_arts.count }
|
|
column("最后更新时间") { |city| city.last_weather_fetch }
|
|
column("操作") { |city|
|
|
button_to "激活",
|
|
admin_ahoy_dashboard_toggle_city_status_path(city_id: city.id),
|
|
method: :post,
|
|
data: { confirm: "确定要激活 #{city.name} 吗?" }
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# columns do
|
|
# column do
|
|
# panel "城市排名" do
|
|
# table_for City.by_popularity do
|
|
# column("城市") { |city| link_to(city.name, admin_city_path(city)) }
|
|
# column("访问量") { |city| city.view_count }
|
|
# column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") }
|
|
# # column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") }
|
|
# column("操作") { |city|
|
|
# if city.active?
|
|
# button_to "停用",
|
|
# admin_ahoy_dashboard_toggle_city_status_path(city_id: city.id),
|
|
# method: :post,
|
|
# data: { confirm: "确定要停用 #{city.name} 吗?" }
|
|
# else
|
|
# button_to "激活",
|
|
# admin_ahoy_dashboard_toggle_city_status_path(city_id: city.id),
|
|
# method: :post,
|
|
# data: { confirm: "确定要激活 #{city.name} 吗?" }
|
|
# end
|
|
# }
|
|
# end
|
|
# end
|
|
# end
|
|
# end
|
|
|
|
# 添加一个事件列表面板
|
|
panel "最近事件" do
|
|
table_for Ahoy::Event.order(time: :desc).limit(10) do
|
|
column :time
|
|
column :name
|
|
column :properties
|
|
end
|
|
end
|
|
end
|
|
end
|