Skip to content
Snippets Groups Projects
Unverified Commit 8fb3ae44 authored by Arnaud Levy's avatar Arnaud Levy Committed by GitHub
Browse files

Réparation de l'arbre (#2430)

* Fix #2429

* better
parent 04cca043
No related branches found
No related tags found
No related merge requests found
......@@ -14,8 +14,7 @@ module WithTree
end
def ancestors
has_parent? ? parent.ancestors.push(parent)
: []
has_parent? ? parent.ancestors.push(parent) : []
end
def ancestors_and_self
......@@ -23,8 +22,7 @@ module WithTree
end
def descendants
has_children? ? children.ordered(original_localization.language).map { |child| [child, child.descendants].flatten }.flatten
: []
has_children? ? descendants_flattened : []
end
def descendants_and_self
......@@ -33,22 +31,31 @@ module WithTree
def siblings
self.class.unscoped
.where(
parent: parent,
university: university
)
.where(parent: parent, university: university)
.where.not(id: id)
.ordered(original_localization.language)
.ordered(original_language)
end
def self_and_children(level)
elements = []
label = "   " * level + self.to_s
elements << { label: label, id: self.id, parent_id: self.parent_id }
children.ordered(original_localization.language).each do |child|
children.ordered(original_language).each do |child|
elements.concat(child.self_and_children(level + 1))
end
elements
end
protected
def original_language
self.respond_to?(:original_localization) ? original_localization.language : nil
end
def descendants_flattened
children.ordered(original_language).map { |child|
[child, child.descendants]
}.flatten
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment