mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Make bulk actions more generic
This commit is contained in:
@@ -32,7 +32,7 @@ class Admin::OrdersReflex < ApplicationReflex
|
||||
).broadcast
|
||||
|
||||
BulkInvoiceJob.perform_later(
|
||||
params[:order_ids],
|
||||
params[:bulk_ids],
|
||||
"tmp/invoices/#{Time.zone.now.to_i}-#{SecureRandom.hex(2)}.pdf",
|
||||
channel: SessionChannel.for_request(request)
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class OrdersBulkCancelService
|
||||
def initialize(params, current_user)
|
||||
@order_ids = params[:order_ids]
|
||||
@order_ids = params[:bulk_ids]
|
||||
@current_user = current_user
|
||||
@send_cancellation_email = params[:send_cancellation_email]
|
||||
@restock_items = params[:restock_items]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
%tr{ id: dom_id(order), class: "state-#{order.state}" }
|
||||
%td.align-center
|
||||
%input{type: 'checkbox', value: order.id, name: 'order_ids[]', "data-checked-target": "checkbox", "data-action": "change->checked#toggleCheckbox" }
|
||||
%input{type: 'checkbox', value: order.id, name: 'bulk_ids[]', "data-checked-target": "checkbox", "data-action": "change->checked#toggleCheckbox" }
|
||||
%td.align-center
|
||||
= order.distributor.name
|
||||
%td.align-center
|
||||
|
||||
@@ -7,13 +7,13 @@ export default class extends ApplicationController {
|
||||
|
||||
// abstract
|
||||
confirm(action) {
|
||||
this.stimulate(action, this.getOrdersIds());
|
||||
this.stimulate(action, this.getSelectedIds());
|
||||
}
|
||||
|
||||
// private
|
||||
getOrdersIds() {
|
||||
getSelectedIds() {
|
||||
const checkboxes = document.querySelectorAll(
|
||||
"#listing_orders input[name='order_ids[]']:checked"
|
||||
"table input[name='bulk_ids[]']:checked"
|
||||
);
|
||||
return Array.from(checkboxes).map((checkbox) => checkbox.value);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ export default class extends BulkActionsController {
|
||||
}
|
||||
|
||||
generate() {
|
||||
this.stimulate("Admin::OrdersReflex#bulk_invoice", { order_ids: super.getOrdersIds() });
|
||||
this.stimulate("Admin::OrdersReflex#bulk_invoice", { bulk_ids: super.getSelectedIds() });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export default class extends BulkActionsController {
|
||||
}
|
||||
|
||||
confirm() {
|
||||
let data = { order_ids: super.getOrdersIds() };
|
||||
let data = { bulk_ids: super.getSelectedIds() };
|
||||
|
||||
if (this.hasExtraParamsTarget) {
|
||||
Object.assign(data, this.extraFormData())
|
||||
|
||||
@@ -465,10 +465,10 @@ distributors: [distributor4, distributor5]) }
|
||||
|
||||
it "can bulk print invoices but only for the 'complete' or 'resumed' ones" do
|
||||
within "#listing_orders" do
|
||||
page.find("input[name='order_ids[]'][value='#{order2.id}']").click
|
||||
page.find("input[name='order_ids[]'][value='#{order3.id}']").click
|
||||
page.find("input[name='order_ids[]'][value='#{order4.id}']").click
|
||||
page.find("input[name='order_ids[]'][value='#{order5.id}']").click
|
||||
page.find("input[name='bulk_ids[]'][value='#{order2.id}']").click
|
||||
page.find("input[name='bulk_ids[]'][value='#{order3.id}']").click
|
||||
page.find("input[name='bulk_ids[]'][value='#{order4.id}']").click
|
||||
page.find("input[name='bulk_ids[]'][value='#{order5.id}']").click
|
||||
end
|
||||
|
||||
page.find("span.icon-reorder", text: "ACTIONS").click
|
||||
@@ -492,8 +492,8 @@ distributors: [distributor4, distributor5]) }
|
||||
end
|
||||
|
||||
it "can bulk send email to 2 orders" do
|
||||
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(2) input[name='order_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(1) input[name='bulk_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(2) input[name='bulk_ids[]']").click
|
||||
|
||||
page.find("span.icon-reorder", text: "ACTIONS").click
|
||||
within ".ofn-drop-down-with-prepend .menu" do
|
||||
@@ -512,8 +512,8 @@ distributors: [distributor4, distributor5]) }
|
||||
end
|
||||
|
||||
it "can bulk print invoices from 2 orders" do
|
||||
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(2) input[name='order_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(1) input[name='bulk_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(2) input[name='bulk_ids[]']").click
|
||||
|
||||
page.find("span.icon-reorder", text: "ACTIONS").click
|
||||
within ".ofn-drop-down-with-prepend .menu" do
|
||||
@@ -527,8 +527,8 @@ distributors: [distributor4, distributor5]) }
|
||||
end
|
||||
|
||||
it "can bulk cancel 2 orders" do
|
||||
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(2) input[name='order_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(1) input[name='bulk_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(2) input[name='bulk_ids[]']").click
|
||||
|
||||
page.find("span.icon-reorder", text: "ACTIONS").click
|
||||
within ".ofn-drop-down-with-prepend .menu" do
|
||||
@@ -574,10 +574,10 @@ distributors: [distributor4, distributor5]) }
|
||||
end
|
||||
|
||||
it "cannot send emails to orders if permission have been revoked in the meantime" do
|
||||
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
|
||||
page.find("#listing_orders tbody tr:nth-child(1) input[name='bulk_ids[]']").click
|
||||
# Find the clicked order
|
||||
order = Spree::Order.find_by(
|
||||
id: page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").value
|
||||
id: page.find("#listing_orders tbody tr:nth-child(1) input[name='bulk_ids[]']").value
|
||||
)
|
||||
# Revoke permission for the current user on that specific order by changing its owners
|
||||
order.update_attribute(:distributor, distributor)
|
||||
|
||||
Reference in New Issue
Block a user