- 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.
This commit is contained in:
parent
138d610c3a
commit
62bfe8888e
@ -1,5 +1,10 @@
|
|||||||
ActiveAdmin.register_page "Ahoy Dashboard" do
|
ActiveAdmin.register_page "Ahoy Dashboard" do
|
||||||
menu label: "总览", parent: "数据统计", priority: 1
|
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
|
content title: "总览" do
|
||||||
columns do
|
columns do
|
||||||
@ -36,7 +41,14 @@ ActiveAdmin.register_page "Ahoy Dashboard" do
|
|||||||
table_for City.least_popular_active.limit(10) do
|
table_for City.least_popular_active.limit(10) do
|
||||||
column("城市") { |city| link_to(city.name, admin_city_path(city)) }
|
column("城市") { |city| link_to(city.name, admin_city_path(city)) }
|
||||||
column("访问量") { |city| city.view_count }
|
column("访问量") { |city| city.view_count }
|
||||||
|
column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") }
|
||||||
# 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
|
end
|
||||||
end
|
end
|
||||||
@ -48,6 +60,12 @@ ActiveAdmin.register_page "Ahoy Dashboard" do
|
|||||||
column("访问量") { |city| city.view_count }
|
column("访问量") { |city| city.view_count }
|
||||||
column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") }
|
column("状态") { |city| status_tag(city.active? ? "活跃" : "停用") }
|
||||||
column("所属区域") { |city| city.country.region.name }
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user