1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Bulk transaction deletion (#845)

* Clean up transaction show view, add delete button

* Clean up tailwind global styles, add switch

* Bulk deletion controller and tests

* Normalize translations

* Add bulk deletion button and form
This commit is contained in:
Zach Gollwitzer 2024-06-07 16:56:30 -04:00 committed by GitHub
parent 115f792198
commit d3f9be15f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 225 additions and 95 deletions

View file

@ -52,6 +52,21 @@ class TransactionsController < ApplicationController
redirect_to transactions_url, notice: t(".success")
end
def bulk_delete
destroyed = Current.family.transactions.destroy_by(id: bulk_delete_params[:transaction_ids])
redirect_to transactions_url, notice: t(".success", count: destroyed.count)
end
def bulk_update
transactions = Current.family.transactions.where(id: bulk_update_params[:transaction_ids])
updates = bulk_update_params.except(:transaction_ids)
if transactions.update_all(bulk_update_params.except(:transaction_ids).to_h)
redirect_to transactions_url, notice: t(".success", count: transactions.count)
else
render :index, status: :unprocessable_entity, notice: t(".failure")
end
end
private
def set_transaction
@ -70,11 +85,19 @@ class TransactionsController < ApplicationController
params[:transaction][:nature].to_s.inquiry
end
def bulk_delete_params
params.require(:bulk_delete).permit(transaction_ids: [])
end
def bulk_update_params
params.require(:bulk_update).permit(:category_id, :excluded, :currency, tag_ids: [], transaction_ids: [])
end
def search_params
params.fetch(:q, {}).permit(:start_date, :end_date, :search, accounts: [], account_ids: [], categories: [], merchants: [])
end
def transaction_params
params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id, :merchant_id, tag_ids: [], taggings_attributes: [ :id, :tag_id, :_destroy ])
params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id, :merchant_id, tag_ids: [])
end
end