Module: TreeNodePatch::InstanceMethods
- Defined in:
- lib/redmine/menu_manager.rb
Instance Method Summary collapse
-
#add(child) ⇒ Object
Adds the specified child node to the receiver node.
-
#add_at(child, position) ⇒ Object
Adds the specified child node to the receiver node.
- #add_last(child) ⇒ Object
-
#position ⇒ Object
Will return the position (zero-based) of the current child in it’s parent.
-
#prepend(child) ⇒ Object
Adds the specified child node to the receiver node.
-
#remove!(child) ⇒ Object
Wrapp remove! making sure to decrement the last_items counter if the removed child was a last item.
Instance Method Details
#add(child) ⇒ Object
Adds the specified child node to the receiver node. The child node’s parent is set to be the receiver. The child is added as the last child in the current list of children for the receiver node.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/redmine/menu_manager.rb', line 76 def add(child) raise "Child already added" if @childrenHash.has_key?(child.name) @childrenHash[child.name] = child position = @children.size - @last_items_count @children.insert(position, child) child.parent = self return child end |
#add_at(child, position) ⇒ Object
Adds the specified child node to the receiver node. The child node’s parent is set to be the receiver. The child is added at the position into the current list of children for the receiver node.
52 53 54 55 56 57 58 59 60 |
# File 'lib/redmine/menu_manager.rb', line 52 def add_at(child, position) raise "Child already added" if @childrenHash.has_key?(child.name) @childrenHash[child.name] = child @children = @children.insert(position, child) child.parent = self return child end |
#add_last(child) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/redmine/menu_manager.rb', line 62 def add_last(child) raise "Child already added" if @childrenHash.has_key?(child.name) @childrenHash[child.name] = child @children << child @last_items_count += 1 child.parent = self return child end |
#position ⇒ Object
Will return the position (zero-based) of the current child in it’s parent
97 98 99 |
# File 'lib/redmine/menu_manager.rb', line 97 def position self.parent.children.index(self) end |
#prepend(child) ⇒ Object
Adds the specified child node to the receiver node. The child node’s parent is set to be the receiver. The child is added as the first child in the current list of children for the receiver node.
39 40 41 42 43 44 45 46 47 |
# File 'lib/redmine/menu_manager.rb', line 39 def prepend(child) raise "Child already added" if @childrenHash.has_key?(child.name) @childrenHash[child.name] = child @children = [child] + @children child.parent = self return child end |
#remove!(child) ⇒ Object
Wrapp remove! making sure to decrement the last_items counter if the removed child was a last item
89 90 91 92 |
# File 'lib/redmine/menu_manager.rb', line 89 def remove!(child) @last_items_count -= +1 if child && child.last super end |