From e6550aa86f40dbfa4d14b9ce003b5e2713e07d30 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Fri, 7 Feb 2025 13:11:42 +0800 Subject: [PATCH] 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. --- app/admin/ahoy_dashboard.rb | 2 ++ app/models/city.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/app/admin/ahoy_dashboard.rb b/app/admin/ahoy_dashboard.rb index 144ed9f..71044e4 100644 --- a/app/admin/ahoy_dashboard.rb +++ b/app/admin/ahoy_dashboard.rb @@ -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 diff --git a/app/models/city.rb b/app/models/city.rb index 95f8f4d..3477578 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -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"