From c022e862aa44848ca794390731552f710e0a0d41 Mon Sep 17 00:00:00 2001 From: Alex Hatzenbuhler Date: Mon, 5 May 2025 11:43:46 -0500 Subject: [PATCH] Add ability to delete all tags (#2200) * Add ability to delete all tags * Downcase resource for confirmation * Clean up deletion resource names * titleize button --- app/controllers/tags_controller.rb | 5 +++++ app/helpers/custom_confirm.rb | 6 +++--- app/views/accounts/show/_menu.html.erb | 2 +- app/views/categories/index.html.erb | 2 +- app/views/chats/_chat.html.erb | 2 +- app/views/chats/_chat_nav.html.erb | 2 +- app/views/imports/_import.html.erb | 2 +- app/views/rules/_rule.html.erb | 2 +- app/views/rules/index.html.erb | 2 +- app/views/tags/index.html.erb | 28 +++++++++++++++++++------- config/routes.rb | 1 + 11 files changed, 37 insertions(+), 17 deletions(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 0794e1e7..1c286290 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -34,6 +34,11 @@ class TagsController < ApplicationController redirect_to tags_path, notice: t(".deleted") end + def destroy_all + Current.family.tags.destroy_all + redirect_back_or_to tags_path, notice: "All tags deleted" + end + private def set_tag diff --git a/app/helpers/custom_confirm.rb b/app/helpers/custom_confirm.rb index bf40f449..cdf24585 100644 --- a/app/helpers/custom_confirm.rb +++ b/app/helpers/custom_confirm.rb @@ -6,9 +6,9 @@ class CustomConfirm new( destructive: true, high_severity: high_severity, - title: "Delete #{resource_name}?", - body: "Are you sure you want to delete #{resource_name}? This is not reversible.", - btn_text: "Delete #{resource_name}" + title: "Delete #{resource_name.titleize}?", + body: "Are you sure you want to delete #{resource_name.downcase}? This is not reversible.", + btn_text: "Delete #{resource_name.titleize}" ) end end diff --git a/app/views/accounts/show/_menu.html.erb b/app/views/accounts/show/_menu.html.erb index 5e59c88a..56d78f62 100644 --- a/app/views/accounts/show/_menu.html.erb +++ b/app/views/accounts/show/_menu.html.erb @@ -19,7 +19,7 @@ href: account_path(account), method: :delete, icon: "trash-2", - confirm: CustomConfirm.for_resource_deletion("Account", high_severity: true), + confirm: CustomConfirm.for_resource_deletion("account", high_severity: true), data: { turbo_frame: :_top } ) %> <% end %> diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index 95344043..5f630e74 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -9,7 +9,7 @@ href: destroy_all_categories_path, method: :delete, icon: "trash-2", - confirm: CustomConfirm.for_resource_deletion("All categories", high_severity: true)) %> + confirm: CustomConfirm.for_resource_deletion("all categories", high_severity: true)) %> <% end %> <%= render LinkComponent.new( diff --git a/app/views/chats/_chat.html.erb b/app/views/chats/_chat.html.erb index 79e02b73..fd904de1 100644 --- a/app/views/chats/_chat.html.erb +++ b/app/views/chats/_chat.html.erb @@ -17,6 +17,6 @@ href: chat_path(chat), icon: "trash-2", method: :delete, - confirm: CustomConfirm.for_resource_deletion("Chat")) %> + confirm: CustomConfirm.for_resource_deletion("chat")) %> <% end %> <% end %> diff --git a/app/views/chats/_chat_nav.html.erb b/app/views/chats/_chat_nav.html.erb index 47e56c8e..9faa2e5a 100644 --- a/app/views/chats/_chat_nav.html.erb +++ b/app/views/chats/_chat_nav.html.erb @@ -29,7 +29,7 @@ href: chat_path(chat), icon: "trash-2", method: :delete, - confirm: CustomConfirm.for_resource_deletion("Chat")) %> + confirm: CustomConfirm.for_resource_deletion("chat")) %> <% end %> <% end %> diff --git a/app/views/imports/_import.html.erb b/app/views/imports/_import.html.erb index fca4764b..a0b1d965 100644 --- a/app/views/imports/_import.html.erb +++ b/app/views/imports/_import.html.erb @@ -59,7 +59,7 @@ href: import_path(import), icon: "trash-2", method: :delete, - confirm: CustomConfirm.for_resource_deletion("Import")) %> + confirm: CustomConfirm.for_resource_deletion("import")) %> <% end %> <% end %> diff --git a/app/views/rules/_rule.html.erb b/app/views/rules/_rule.html.erb index 0a19d9b3..e2b01b74 100644 --- a/app/views/rules/_rule.html.erb +++ b/app/views/rules/_rule.html.erb @@ -55,7 +55,7 @@ href: rule_path(rule), icon: "trash-2", method: :delete, - confirm: CustomConfirm.for_resource_deletion("Rule")) %> + confirm: CustomConfirm.for_resource_deletion("rule")) %> <% end %> diff --git a/app/views/rules/index.html.erb b/app/views/rules/index.html.erb index 13e538b4..2c3040a1 100644 --- a/app/views/rules/index.html.erb +++ b/app/views/rules/index.html.erb @@ -10,7 +10,7 @@ href: destroy_all_rules_path, icon: "trash-2", method: :delete, - confirm: CustomConfirm.for_resource_deletion("All rules", high_severity: true)) %> + confirm: CustomConfirm.for_resource_deletion("all rules", high_severity: true)) %> <% end %> <% end %> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index d12bd356..24bc2d10 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -1,13 +1,27 @@

<%= t(".tags") %>

- <%= render LinkComponent.new( - text: t(".new"), - variant: "primary", - href: new_tag_path, - icon: "plus", - frame: :modal - ) %> +
+ <%= render MenuComponent.new do |menu| %> + <% menu.with_item( + variant: "button", + text: "Delete all", + href: destroy_all_tags_path, + method: :delete, + icon: "trash-2", + confirm: CustomConfirm.for_resource_deletion("all tags", high_severity: true)) %> + <% end %> + + <%= render LinkComponent.new( + text: t(".new"), + variant: "primary", + href: new_tag_path, + icon: "plus", + frame: :modal + ) %> + +
+
diff --git a/config/routes.rb b/config/routes.rb index b0538fb1..da7790fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,6 +64,7 @@ Rails.application.routes.draw do resources :tags, except: :show do resources :deletions, only: %i[new create], module: :tag + delete :destroy_all, on: :collection end namespace :category do