Skip to content

Commit 7a67ccd

Browse files
committed
rubocop changes in bulk update
1 parent fa8c558 commit 7a67ccd

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

app/components/avo/views/resource_edit_component.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def title
2626
end
2727

2828
def back_path
29-
return helpers.resources_path(resource: @resource) if params[:controller] == 'avo/bulk_update'
29+
return helpers.resources_path(resource: @resource) if params[:controller] == "avo/bulk_update"
3030

3131
# The `return_to` param takes precedence over anything else.
3232
return params[:return_to] if params[:return_to].present?
@@ -86,7 +86,7 @@ def is_edit?
8686
end
8787

8888
def form_method
89-
return :put if is_edit? && params[:controller] != 'avo/bulk_update'
89+
return :put if is_edit? && params[:controller] != "avo/bulk_update"
9090

9191
:post
9292
end
@@ -96,7 +96,7 @@ def model
9696
end
9797

9898
def form_url
99-
if params[:controller] == 'avo/bulk_update'
99+
if params[:controller] == "avo/bulk_update"
100100
helpers.handle_bulk_update_path(resource_name: @resource.name, query: @query)
101101
elsif is_edit?
102102
helpers.resource_path(

app/controllers/avo/bulk_update_controller.rb

+19-26
Original file line numberDiff line numberDiff line change
@@ -42,51 +42,44 @@ def params_to_apply
4242
current_params = params[resource_key] || {}
4343

4444
progress_fields = @resource
45-
.get_field_definitions
46-
.select { |field| field.is_a?(Avo::Fields::ProgressBarField) }
47-
.map(&:id)
48-
.map(&:to_sym)
45+
.get_field_definitions
46+
.select { |field| field.is_a?(Avo::Fields::ProgressBarField) }
47+
.map(&:id)
48+
.map(&:to_sym)
4949

50-
51-
params_to_apply = current_params.reject do |key, value|
50+
current_params.reject do |key, value|
5251
key_sym = key.to_sym
5352
prefilled_value = prefilled_params[key_sym]
5453

5554
next true if progress_fields.include?(key_sym) && prefilled_value == "" && value.to_s == "50"
5655

5756
prefilled_value.to_s == value.to_s
5857
end
59-
60-
params_to_apply
6158
end
6259

6360
def update_records
6461
updated_count = 0
6562
failed_records = []
6663

6764
@query.each do |record|
68-
begin
69-
params_to_apply.each do |key, value|
70-
begin
71-
record.public_send("#{key}=", value)
72-
rescue => e
73-
puts "Błąd przypisywania pola #{key}: #{e.message}"
74-
end
75-
end
76-
77-
@resource.fill_record(record, params)
78-
79-
if record.save
80-
updated_count += 1
81-
else
82-
failed_records << { record: record, errors: record.errors.full_messages }
83-
end
65+
params_to_apply.each do |key, value|
66+
record.public_send(:"#{key}=", value)
8467
rescue => e
85-
failed_records << { record: record, errors: [e.message] }
68+
puts "Błąd przypisywania pola #{key}: #{e.message}"
69+
end
70+
71+
@resource.fill_record(record, params)
72+
73+
if record.save
74+
updated_count += 1
75+
else
76+
failed_records << { record: record, errors: record.errors.full_messages }
8677
end
78+
rescue => e
79+
failed_records << { record: record, errors: [e.message] }
8780
end
8881

89-
return updated_count, failed_records
82+
[updated_count, failed_records]
9083
end
9184

9285
def after_bulk_update_path

config/routes.rb

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
get "resources", to: redirect(Avo.configuration.root_path)
55
get "dashboards", to: redirect(Avo.configuration.root_path)
66

7-
# Mount Avo engines routes by default but leave it configurable in case the user wants to nest these under a scope.
8-
if Avo.configuration.mount_avo_engines
9-
instance_exec(&Avo.mount_engines)
10-
end
11-
127
get "/bulk_update/edit", to: "bulk_update#edit", as: "edit_bulk_update"
138
post "/bulk_update/handle", to: "bulk_update#handle", as: "handle_bulk_update"
149

0 commit comments

Comments
 (0)