feat: add active and inactive city counts to dashboard

- Add display of activated and non-activated city counts
- Introduce a new scope for inactive cities in City model
- Update Ahoy Dashboard to show the total count of both active and inactive cities

This update provides better insights into city activation status within the
Ahoy Dashboard. It introduces a new function in the City model and updates
the dashboard to reflect these statistics, assisting in better monitoring
of city status.
This commit is contained in:
songtianlun 2025-02-07 13:11:42 +08:00
parent d418232e7b
commit e6550aa86f
2 changed files with 3 additions and 0 deletions

View File

@ -13,6 +13,8 @@ ActiveAdmin.register_page "Ahoy Dashboard" 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

View File

@ -19,6 +19,7 @@ class City < ApplicationRecord
scope :by_region, ->(region_id) { joins(:country).where(countries: { region_id: region_id }) }
scope :by_country, ->(country_id) { where(country_id: country_id) }
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
scope :by_popularity, -> {
if ActiveRecord::Base.connection.adapter_name.downcase == "sqlite"