From a60f1bfe3871f875ecead173af6528ac3e97e7c3 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Wed, 5 Feb 2025 14:39:43 +0800 Subject: [PATCH] feat: enhance city status management in dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change table to display cities based on popularity - Modify button logic to toggle between "停用" (disable) and "激活" (activate) based on current city status This update improves the usability of the Ahoy Dashboard by providing clearer management options for city statuses. Users can now easily activate or deactivate cities from the dashboard, enhancing overall administrative efficiency. --- app/admin/ahoy_dashboard.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/admin/ahoy_dashboard.rb b/app/admin/ahoy_dashboard.rb index 19bda68..b82a521 100644 --- a/app/admin/ahoy_dashboard.rb +++ b/app/admin/ahoy_dashboard.rb @@ -74,16 +74,23 @@ ActiveAdmin.register_page "Ahoy Dashboard" do columns do column do panel "城市排名" do - table_for City.least_popular_active do + table_for City.by_popularity 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} 吗?" } + if city.active? + button_to "停用", + admin_ahoy_dashboard_toggle_city_status_path(city_id: city.id), + method: :post, + data: { confirm: "确定要停用 #{city.name} 吗?" } + else + button_to "激活", + admin_ahoy_dashboard_toggle_city_status_path(city_id: city.id), + method: :post, + data: { confirm: "确定要激活 #{city.name} 吗?" } + end } end end