Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevelito committed Mar 11, 2025
1 parent 750dd25 commit ec17628
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 45 deletions.
28 changes: 16 additions & 12 deletions app/components/avo/views/resource_edit_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ def title
end

def back_path
return helpers.resources_path(resource: @resource) if params[:controller] == "avo/bulk_update"

# The `return_to` param takes precedence over anything else.
return params[:return_to] if params[:return_to].present?

return if via_belongs_to?
return resource_view_path if via_resource?
return resources_path if via_index?

if is_edit? && Avo.configuration.resource_default_view.show? # via resource show or edit page
return helpers.resource_path(record: @resource.record, resource: @resource, **keep_referrer_params)
path = if params[:controller] == "avo/bulk_update"

Check failure on line 29 in app/components/avo/views/resource_edit_component.rb

View workflow job for this annotation

GitHub Actions / lint / runner / standardrb

[rubocop] reported by reviewdog 🐶 [Corrected] Style/RedundantAssignment: Redundant assignment before returning detected. Raw Output: app/components/avo/views/resource_edit_component.rb:29:5: C: [Corrected] Style/RedundantAssignment: Redundant assignment before returning detected. path = if params[:controller] == "avo/bulk_update" ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
helpers.resources_path(resource: @resource)
elsif params[:return_to].present?
# The `return_to` param takes precedence over anything else.
params[:return_to]
elsif via_belongs_to?
nil
elsif via_resource?
resource_view_path
elsif via_index?
resources_path
elsif is_edit? && Avo.configuration.resource_default_view.show? # via resource show or edit page
helpers.resource_path(record: @resource.record, resource: @resource, **keep_referrer_params)
else
resources_path
end

resources_path
path

Check failure on line 46 in app/components/avo/views/resource_edit_component.rb

View workflow job for this annotation

GitHub Actions / lint / runner / standardrb

[rubocop] reported by reviewdog 🐶 [Corrected] Layout/EmptyLines: Extra blank line detected. Raw Output: app/components/avo/views/resource_edit_component.rb:46:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.

Check failure on line 46 in app/components/avo/views/resource_edit_component.rb

View workflow job for this annotation

GitHub Actions / lint / runner / standardrb

[rubocop] reported by reviewdog 🐶 [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end. Raw Output: app/components/avo/views/resource_edit_component.rb:46:1: C: [Corrected] Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.

Check failure on line 46 in app/components/avo/views/resource_edit_component.rb

View workflow job for this annotation

GitHub Actions / lint / runner / standardrb

[rubocop] reported by reviewdog 🐶 [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected. Raw Output: app/components/avo/views/resource_edit_component.rb:46:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
end

def resources_path
Expand Down
30 changes: 9 additions & 21 deletions app/controllers/avo/bulk_update_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def current_resource_params

def progress_bar_fields
@resource.get_field_definitions
.select { |field| field.is_a?(Avo::Fields::ProgressBarField) }
.map(&:id)
.map(&:to_sym)
.select { |field| field.is_a?(Avo::Fields::ProgressBarField) }
.map(&:id)
.map(&:to_sym)
end

def progress_field_with_default?(progress_fields, key_sym, prefilled_value, value)
Expand All @@ -72,13 +72,7 @@ def update_records

@query.each do |record|
update_record(record, params_to_apply)
if record.save
updated_count += 1
else
add_failed_record(failed_records, record)
end
rescue => e
add_failed_record(failed_records, record, e.message)
record.save ? updated_count += 1 : add_failed_record(failed_records, record)
end

[updated_count, failed_records]
Expand All @@ -87,20 +81,14 @@ def update_records
def update_record(record, params_to_apply)
params_to_apply.each do |key, value|
record.public_send(:"#{key}=", value)
rescue => e
log_field_assignment_error(key, e.message)
end

@resource.fill_record(record, params)
end

def log_field_assignment_error(key, error_message)
puts "Błąd przypisywania pola #{key}: #{error_message}"
end

def add_failed_record(failed_records, record, error_message = nil)
errors = error_message ? [error_message] : record.errors.full_messages
failed_records << { record: record, errors: errors }
failed_records << {record: record, errors: errors}
end

def after_bulk_update_path
Expand All @@ -117,10 +105,10 @@ def prefill_fields(records, fields)

def set_query
@query = if params[:query].present?
@resource.find_record(params[:query], params: params)
else
find_records_by_resource_ids
end
@resource.find_record(params[:query], params: params)
else
find_records_by_resource_ids
end
end

def find_records_by_resource_ids
Expand Down
28 changes: 16 additions & 12 deletions app/javascript/js/controllers/item_select_all_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,7 @@ export default class extends Controller {
}

updateActionLinks(param, selector, keys) {
const params = {
resourceIds: {
value: JSON.parse(this.element.dataset.selectedResources).join(','),
selectedAll: 'false',
key: keys.resourceIdsKey,
},
selectedQuery: {
value: this.element.dataset.itemSelectAllSelectedAllQueryValue,
selectedAll: 'true',
key: keys.selectedQueryKey,
},
}
const params = this.setLinkParams(keys)

document.querySelectorAll(selector).forEach((link) => {
try {
Expand All @@ -141,6 +130,21 @@ export default class extends Controller {
})
}

setLinkParams(keys) {
return {
resourceIds: {
value: JSON.parse(this.element.dataset.selectedResources).join(','),
selectedAll: 'false',
key: keys.resourceIdsKey,
},
selectedQuery: {
value: this.element.dataset.itemSelectAllSelectedAllQueryValue,
selectedAll: 'true',
key: keys.selectedQueryKey,
},
}
}

resetUnselected() {
this.selectedAllValue = false
this.unselectedMessageTarget.classList.remove('hidden')
Expand Down

0 comments on commit ec17628

Please sign in to comment.