Class: SectionNode

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/section_node.rb

Instance Method Summary collapse

Instance Method Details

#ancestorsObject



81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/section_node.rb', line 81

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

#move_after(section_node) ⇒ Object



63
64
65
66
67
68
69
70
# File 'app/models/section_node.rb', line 63

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



54
55
56
57
58
59
60
61
# File 'app/models/section_node.rb', line 54

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/section_node.rb', line 31

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



72
73
74
# File 'app/models/section_node.rb', line 72

def move_to_beginning(sec)
  move_to(sec, 0)
end

#move_to_end(sec) ⇒ Object



76
77
78
79
# File 'app/models/section_node.rb', line 76

def move_to_end(sec)
  #1.0/0 == Infinity
  move_to(sec, 1.0/0)
end

#orphaned?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/models/section_node.rb', line 17

def orphaned?
  !node || (node.class.uses_soft_delete? && node.deleted?)
end

#page?Boolean

Is this node a page

Returns:

  • (Boolean)


27
28
29
# File 'app/models/section_node.rb', line 27

def page?
  node_type == 'Page'
end

#section?Boolean

Is this node a section

Returns:

  • (Boolean)


22
23
24
# File 'app/models/section_node.rb', line 22

def section?
  node_type == 'Section'
end

#visible?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'app/models/section_node.rb', line 9

def visible?
  return false unless node
  return false if(node.respond_to?(:hidden?) && node.hidden?)
  return false if(node.respond_to?(:archived?) && node.archived?)
  return false if(node.respond_to?(:published?) && !node.published?)
  true
end