-
Notifications
You must be signed in to change notification settings - Fork 126
Open
Description
My use case is that I would like a tree structure, but to have each level always sorted by name. I'd like to have the tree editor still work for easily setting parent/child relationships.
Currently I have to override the "sort" controller action so that it does not update the "position" field (which I have set to 'name'), or else all my objects get their name changed to numbers:
# Override the one provided by ActiveAdminSortable, since we want it to ignore updates to the sort order
collection_action :sort, :method => :post do
resource_name = ActiveAdmin::SortableTree::Compatibility.normalized_resource_name(active_admin_config.resource_name)
records = []
params[resource_name].each_pair do |resource, parent_resource|
parent_resource = resource_class.find(parent_resource) rescue nil
records << [resource_class.find(resource), parent_resource]
end
errors = []
ActiveRecord::Base.transaction do
records.each_with_index do |(record, parent_record), position|
# record.send "#{options[:sorting_attribute]}=", position
if options[:tree]
record.send "parent=", parent_record
end
errors << {record.id => record.errors} if !record.save
end
end
if errors.empty?
head 200
else
render json: errors, status: 422
end
end
Could we have a config option that allows us to disable the record.send "#{options[:sorting_attribute]}=", position
?
Metadata
Metadata
Assignees
Labels
No labels