modernizar el reordenamiento
This commit is contained in:
parent
f77a907753
commit
ab3c2a8f42
1 changed files with 9 additions and 10 deletions
|
@ -58,25 +58,24 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
#
|
#
|
||||||
# { uuid => 2, uuid => 1, uuid => 0 }
|
# { uuid => 2, uuid => 1, uuid => 0 }
|
||||||
def reorder
|
def reorder
|
||||||
posts = site.posts(lang: locale)
|
reorder = params.require(:post).permit(reorder: {}).try(:[], :reorder).transform_values(&:to_i)
|
||||||
reorder = params.require(:post).permit(reorder: {}).try(:[], :reorder)
|
posts = site.posts(lang: locale).where(uuid: reorder.keys)
|
||||||
modified = PostRelation.new(site: site)
|
|
||||||
|
|
||||||
files = reorder.keys.map do |uuid|
|
files = posts.map do |post|
|
||||||
post = posts.find(uuid, uuid: true)
|
next unless post.attribute? :order
|
||||||
order = reorder[uuid].to_i
|
|
||||||
|
order = reorder[post.uuid.value]
|
||||||
|
|
||||||
next unless post
|
|
||||||
next unless post.attributes.include? :order
|
|
||||||
next if post.order.value == order
|
next if post.order.value == order
|
||||||
|
|
||||||
modified << post
|
|
||||||
post.order.value = order
|
post.order.value = order
|
||||||
post.path.absolute
|
post.path.absolute
|
||||||
end.compact
|
end.compact
|
||||||
|
|
||||||
|
return if files.empty?
|
||||||
|
|
||||||
# TODO: Implementar transacciones!
|
# TODO: Implementar transacciones!
|
||||||
modified.save_all(validate: false) &&
|
posts.save_all(validate: false) &&
|
||||||
commit(action: :reorder, file: files)
|
commit(action: :reorder, file: files)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue