diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb
index b00212dc5e2..bc2a9592968 100644
--- a/app/controllers/transactions_controller.rb
+++ b/app/controllers/transactions_controller.rb
@@ -57,13 +57,16 @@ def bulk_delete
redirect_to transactions_url, notice: t(".success", count: destroyed.count)
end
+ def bulk_edit
+ 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)
+ if transactions.update_all(bulk_update_params.except(:transaction_ids).to_h.compact_blank!)
redirect_to transactions_url, notice: t(".success", count: transactions.count)
else
- render :index, status: :unprocessable_entity, notice: t(".failure")
+ flash.now[:error] = t(".failure")
+ render :index, status: :unprocessable_entity
end
end
@@ -90,7 +93,7 @@ def bulk_delete_params
end
def bulk_update_params
- params.require(:bulk_update).permit(:category_id, :excluded, :currency, tag_ids: [], transaction_ids: [])
+ params.require(:bulk_update).permit(:date, :notes, :excluded, :category_id, :merchant_id, transaction_ids: [])
end
def search_params
diff --git a/app/javascript/controllers/bulk_select_controller.js b/app/javascript/controllers/bulk_select_controller.js
index 124ddf9cb2d..a1aff137a59 100644
--- a/app/javascript/controllers/bulk_select_controller.js
+++ b/app/javascript/controllers/bulk_select_controller.js
@@ -2,7 +2,7 @@ import {Controller} from "@hotwired/stimulus"
// Connects to data-controller="bulk-select"
export default class extends Controller {
- static targets = ["row", "group", "selectionBar", "selectionBarText"]
+ static targets = ["row", "group", "selectionBar", "selectionBarText", "bulkEditDrawerTitle"]
static values = {
resource: String,
selectedIds: {type: Array, default: []}
@@ -18,9 +18,14 @@ export default class extends Controller {
document.removeEventListener("turbo:load", this.#updateView)
}
- submitBulkDeletionRequest(e) {
+ bulkEditDrawerTitleTargetConnected(element) {
+ element.innerText = `Edit ${this.selectedIdsValue.length} ${this.#pluralizedResourceName()}`
+ }
+
+ submitBulkRequest(e) {
const form = e.target.closest("form");
- this.#addHiddenFormInputsForSelectedIds(form, "bulk_delete[transaction_ids][]", this.selectedIdsValue)
+ const scope = e.params.scope
+ this.#addHiddenFormInputsForSelectedIds(form, `${scope}[transaction_ids][]`, this.selectedIdsValue)
form.requestSubmit()
}
@@ -96,11 +101,15 @@ export default class extends Controller {
#updateSelectionBar() {
const count = this.selectedIdsValue.length
- this.selectionBarTextTarget.innerText = `${count} ${this.resourceValue}${count === 1 ? "" : "s"} selected`
+ this.selectionBarTextTarget.innerText = `${count} ${this.#pluralizedResourceName()} selected`
this.selectionBarTarget.hidden = count === 0
this.selectionBarTarget.querySelector("input[type='checkbox']").checked = count > 0
}
+ #pluralizedResourceName() {
+ return `${this.resourceValue}${this.selectedIdsValue.length === 1 ? "" : "s"}`
+ }
+
#updateGroups() {
this.groupTargets.forEach(group => {
const rows = this.rowTargets.filter(row => group.contains(row))
diff --git a/app/views/transactions/_selection_bar.html.erb b/app/views/transactions/_selection_bar.html.erb
index 4e42d7dc940..34cc0a1f30b 100644
--- a/app/views/transactions/_selection_bar.html.erb
+++ b/app/views/transactions/_selection_bar.html.erb
@@ -6,12 +6,17 @@
- <%= button_to "#", disabled: true, class: "cursor-not-allowed p-1.5 group hover:bg-gray-700 flex items-center justify-center rounded-md", title: "Edit" do %>
+ <%= turbo_frame_tag "bulk_transaction_edit_drawer" %>
+
+ <%= link_to bulk_edit_transactions_path,
+ class: "p-1.5 group hover:bg-gray-700 flex items-center justify-center rounded-md",
+ title: "Edit",
+ data: { turbo_frame: "bulk_transaction_edit_drawer" } do %>
<%= lucide_icon "pencil-line", class: "w-5 group-hover:text-white" %>
<% end %>
<%= form_with url: bulk_delete_transactions_path, builder: ActionView::Helpers::FormBuilder, data: { turbo_confirm: true } do %>
-