Module: Trees::ClassMethods
- Defined in:
 - backend/app/model/mixins/trees.rb
 
Instance Method Summary (collapse)
- 
  
    
      - (Object) assemble_tree(node, links, properties) 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      - (Object) calculate_object_graph(object_graph, opts = {}) 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      - (Object) node_model 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      - (Object) node_type 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      - (Object) root_type 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      - (Object) sequel_to_jsonmodel(objs, opts = {}) 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      - (Object) tree_of(root_type, node_type) 
    
    
  
  
  
  
  
  
  
  
  
    
 
Instance Method Details
- (Object) assemble_tree(node, links, properties)
      227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243  | 
    
      # File 'backend/app/model/mixins/trees.rb', line 227 def assemble_tree(node, links, properties) result = properties[node].clone if !result.has_key?('has_children') result['has_children'] = !!links[node] end if links[node] result['children'] = links[node].sort_by(&:first).map do |position, child_id| assemble_tree(child_id, links, properties) end else result['children'] = [] end result end  | 
  
- (Object) calculate_object_graph(object_graph, opts = {})
      257 258 259 260 261 262 263 264 265 266 267 268 269 270  | 
    
      # File 'backend/app/model/mixins/trees.rb', line 257 def calculate_object_graph(object_graph, opts = {}) object_graph.each do |model, id_list| next if self != model ids = node_model.any_repo.filter(:root_record_id => id_list). select(:id).map {|row| row[:id] } object_graph.add_objects(node_model, ids) end super end  | 
  
- (Object) node_model
      222 223 224  | 
    
      # File 'backend/app/model/mixins/trees.rb', line 222 def node_model Kernel.const_get(node_type.to_s.camelize) end  | 
  
- (Object) node_type
      217 218 219  | 
    
      # File 'backend/app/model/mixins/trees.rb', line 217 def node_type @node_type end  | 
  
- (Object) root_type
      212 213 214  | 
    
      # File 'backend/app/model/mixins/trees.rb', line 212 def root_type @root_type end  | 
  
- (Object) sequel_to_jsonmodel(objs, opts = {})
      246 247 248 249 250 251 252 253 254  | 
    
      # File 'backend/app/model/mixins/trees.rb', line 246 def sequel_to_jsonmodel(objs, opts = {}) jsons = super jsons.zip(objs).each do |json, obj| json['tree'] = {'ref' => obj.uri + '/tree'} end jsons end  | 
  
- (Object) tree_of(root_type, node_type)
      206 207 208 209  | 
    
      # File 'backend/app/model/mixins/trees.rb', line 206 def tree_of(root_type, node_type) @root_type = root_type @node_type = node_type end  |