feat: add least popular active cities panel
- 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.
This commit is contained in:
parent
50321533f7
commit
adb671e668
@ -37,6 +37,16 @@ ActiveAdmin.register_page "Dashboard" do
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# 添加一个事件列表面板
|
# 添加一个事件列表面板
|
||||||
|
@ -37,6 +37,24 @@ class City < ApplicationRecord
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope :least_popular_active, -> {
|
||||||
|
if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
|
||||||
|
active
|
||||||
|
.joins("LEFT JOIN ahoy_events ON json_extract(ahoy_events.properties, '$.city_id') = cities.id
|
||||||
|
AND json_extract(ahoy_events.properties, '$.event_type') = 'city_view'")
|
||||||
|
.group("cities.id")
|
||||||
|
.select("cities.*, COUNT(ahoy_events.id) as visit_count")
|
||||||
|
.order("visit_count ASC, cities.name ASC")
|
||||||
|
else
|
||||||
|
active
|
||||||
|
.joins("LEFT JOIN ahoy_events ON (ahoy_events.properties->>'city_id')::integer = cities.id
|
||||||
|
AND ahoy_events.properties->>'event_type' = 'city_view'")
|
||||||
|
.group("cities.id")
|
||||||
|
.select("cities.*, COUNT(ahoy_events.id) as visit_count")
|
||||||
|
.order("visit_count ASC, cities.name ASC")
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user