songtianlun
adb671e668
- Introduce new panel in the admin dashboard for displaying the least popular active cities. - Implement a database scope `least_popular_active` to retrieve cities based on their view counts. - Ensure compatibility with both SQLite and PostgreSQL for fetching city view data. This addition enhances the admin dashboard by allowing administrators to easily identify and manage cities that are receiving less user interaction, thus aiding in strategic planning for engagement and promotion.
82 lines
2.3 KiB
Ruby
82 lines
2.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
ActiveAdmin.register_page "Dashboard" do
|
|
menu priority: 1, label: proc { I18n.t("active_admin.dashboard") }
|
|
|
|
content title: proc { I18n.t("active_admin.dashboard") } do
|
|
div class: "blank_slate_container", id: "dashboard_default_message" do
|
|
span class: "blank_slate" do
|
|
span I18n.t("active_admin.dashboard_welcome.welcome")
|
|
small I18n.t("active_admin.dashboard_welcome.call_to_action")
|
|
end
|
|
end
|
|
|
|
columns do
|
|
column do
|
|
panel "访问统计" do
|
|
para "总访问量: #{Ahoy::Visit.count}"
|
|
para "总事件数: #{Ahoy::Event.count}"
|
|
para "独立访客数: #{Ahoy::Visit.distinct.count(:visitor_token)}"
|
|
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
|
|
|
|
column do
|
|
panel "冷门活跃城市" do
|
|
table_for City.least_popular_active.limit(10) do
|
|
column("城市") { |city| link_to(city.name, admin_city_path(city)) }
|
|
column("访问量") { |city| city.view_count }
|
|
# column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# 添加一个事件列表面板
|
|
panel "最近事件" do
|
|
table_for Ahoy::Event.order(time: :desc).limit(10) do
|
|
column :time
|
|
column :name
|
|
column :properties
|
|
end
|
|
end
|
|
|
|
# Here is an example of a simple dashboard with columns and panels.
|
|
#
|
|
# columns do
|
|
# column do
|
|
# panel "Recent Posts" do
|
|
# ul do
|
|
# Post.recent(5).map do |post|
|
|
# li link_to(post.title, admin_post_path(post))
|
|
# end
|
|
# end
|
|
# end
|
|
# end
|
|
|
|
# column do
|
|
# panel "Info" do
|
|
# para "Welcome to ActiveAdmin."
|
|
# end
|
|
# end
|
|
# end
|
|
end # content
|
|
end
|