From 62bfe8888ecc3ef04119f6d80a7e9165f6f883d7 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Tue, 28 Jan 2025 02:12:09 +0800 Subject: [PATCH] feat: add toggle city status action - Implement city status toggle functionality in the Ahoy Dashboard - Add buttons for activating and deactivating cities - Update the UI to show the current status of cities This commit enhances the admin dashboard by allowing administrators to toggle the activation status of cities. The buttons provide confirmation prompts before executing state changes, improving user experience and preventing accidental actions. --- app/admin/ahoy_dashboard.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/admin/ahoy_dashboard.rb b/app/admin/ahoy_dashboard.rb index eabbe4a..a73aa5e 100644 --- a/app/admin/ahoy_dashboard.rb +++ b/app/admin/ahoy_dashboard.rb @@ -1,5 +1,10 @@ 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 @@ -36,7 +41,14 @@ ActiveAdmin.register_page "Ahoy Dashboard" 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? ? "活跃" : "停用") } # 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 @@ -48,6 +60,12 @@ ActiveAdmin.register_page "Ahoy Dashboard" do column("访问量") { |city| city.view_count } column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") } column("所属区域") { |city| city.country.region.name } + column("操作") { |city| + button_to "激活", + admin_ahoy_dashboard_toggle_city_status_path(city_id: city.id), + method: :post, + data: { confirm: "确定要激活 #{city.name} 吗?" } + } end end end