Skip to content
Snippets Groups Projects
Commit b6962541 authored by pabois's avatar pabois
Browse files

order in trees

parent ced5e4db
No related branches found
No related tags found
No related merge requests found
......@@ -14,24 +14,24 @@ module WithTree
end
def ancestors
has_parent? ? parent.ancestors.push(parent)
has_parent? ? parent.ancestors.ordered.push(parent)
: []
end
def descendents
has_children? ? children.map { |child| [child, child.descendents].flatten }.flatten
has_children? ? children.ordered.map { |child| [child, child.descendents].flatten }.flatten
: []
end
def siblings
self.class.unscoped.where(parent: parent, university: university).where.not(id: id)
self.class.unscoped.where(parent: parent, university: university).where.not(id: id).ordered
end
def self_and_children(level)
elements = []
label = "   " * level + self.to_s
elements << { label: label, id: self.id, parent_id: self.parent_id }
children.each do |child|
children.ordered.each do |child|
elements.concat(child.self_and_children(level + 1))
end
elements
......
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