Class: SectionNode
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SectionNode
- Defined in:
- app/models/section_node.rb
Instance Method Summary collapse
- #ancestors ⇒ Object
- #live_node ⇒ Object
- #move_after(section_node) ⇒ Object
- #move_before(section_node) ⇒ Object
- #move_to(sec, pos) ⇒ Object
- #move_to_beginning(sec) ⇒ Object
- #move_to_end(sec) ⇒ Object
- #orphaned? ⇒ Boolean
-
#page? ⇒ Boolean
Is this node a page.
-
#section? ⇒ Boolean
Is this node a section.
- #visible? ⇒ Boolean
Instance Method Details
#ancestors ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/section_node.rb', line 89 def ancestors() ancestors = [] fn = lambda do |sn| ancestors << sn.section if sn.section && !sn.section.root? fn.call(sn.section.node) end end fn.call(self) ancestors.reverse end |
#live_node ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/models/section_node.rb', line 17 def live_node @live_node ||= if node node.class.versioned? ? node.live_version : node else nil end end |
#move_after(section_node) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'app/models/section_node.rb', line 71 def move_after(section_node) if section == section_node.section && position < section_node.position pos = section_node.position else pos = section_node.position + 1 end move_to(section_node.section, pos) end |
#move_before(section_node) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'app/models/section_node.rb', line 62 def move_before(section_node) if section == section_node.section && position < section_node.position pos = section_node.position - 1 else pos = section_node.position end move_to(section_node.section, pos) end |
#move_to(sec, pos) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/section_node.rb', line 39 def move_to(sec, pos) #logger.info "Moving Section Node ##{id} to Section ##{sec.id} Position #{pos}" transaction do if section != sec remove_from_list self.section = sec save end if pos < 0 pos = 0 else #This helps prevent the position from getting out of whack #If you pass in a really high number for position, #this just corrects it to the right number node_count = SectionNode.count(:conditions => {:section_id => section_id}) pos = node_count if pos > node_count end insert_at_position(pos) end end |
#move_to_beginning(sec) ⇒ Object
80 81 82 |
# File 'app/models/section_node.rb', line 80 def move_to_beginning(sec) move_to(sec, 0) end |
#move_to_end(sec) ⇒ Object
84 85 86 87 |
# File 'app/models/section_node.rb', line 84 def move_to_end(sec) #1.0/0 == Infinity move_to(sec, 1.0/0) end |
#orphaned? ⇒ Boolean
25 26 27 |
# File 'app/models/section_node.rb', line 25 def orphaned? !node || (node.class.uses_soft_delete? && node.deleted?) end |
#page? ⇒ Boolean
Is this node a page
35 36 37 |
# File 'app/models/section_node.rb', line 35 def page? node_type == 'Page' end |
#section? ⇒ Boolean
Is this node a section
30 31 32 |
# File 'app/models/section_node.rb', line 30 def section? node_type == 'Section' end |
#visible? ⇒ Boolean
9 10 11 12 13 14 15 |
# File 'app/models/section_node.rb', line 9 def visible? return false unless live_node return false if(live_node.respond_to?(:hidden?) && live_node.hidden?) return false if(live_node.respond_to?(:archived?) && live_node.archived?) return false if(live_node.respond_to?(:published?) && !live_node.published?) true end |