Module: ResourceTrees
- Defined in:
- backend/app/model/mixins/resource_trees.rb
Instance Method Summary collapse
-
#build_node_query ⇒ Object
-
#load_node_properties(node, properties, ids_of_interest = :all) ⇒ Object
If we’re being asked to load an entire tree, don’t bother loading all of the instances that go with each node.
-
#load_root_properties(properties, ids_of_interest = :all) ⇒ Object
-
#set_node_instances(node, properties) ⇒ Object
-
#set_node_level(node, properties) ⇒ Object
Instance Method Details
#build_node_query ⇒ Object
3 4 5 6 |
# File 'backend/app/model/mixins/resource_trees.rb', line 3 def build_node_query node_query = super node_query.eager(:instance => :sub_container) end |
#load_node_properties(node, properties, ids_of_interest = :all) ⇒ Object
If we’re being asked to load an entire tree, don’t bother loading all of the instances that go with each node. This is a performance optimisation, since there can be tens of thousands of instances. The only place that pulls down the entire tree is the indexer, and it doesn’t need instance/container information from the tree anyway.
59 60 61 62 63 64 65 66 67 |
# File 'backend/app/model/mixins/resource_trees.rb', line 59 def load_node_properties(node, properties, ids_of_interest = :all) super properties[node.id][:title] = node.display_string properties[node.id][:component_id] = node.component_id if node.component_id set_node_level(node, properties[node.id]) set_node_instances(node, properties[node.id]) #if ids_of_interest != :all end |
#load_root_properties(properties, ids_of_interest = :all) ⇒ Object
70 71 72 73 74 75 |
# File 'backend/app/model/mixins/resource_trees.rb', line 70 def load_root_properties(properties, ids_of_interest = :all) super set_node_level(self, properties) set_node_instances(self, properties) if ids_of_interest != :all end |
#set_node_instances(node, properties) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'backend/app/model/mixins/resource_trees.rb', line 18 def set_node_instances(node, properties) if node.instance.length > 0 properties[:instance_types] = node.instance.map {|instance| instance.values[:instance_type] } properties[:containers] = node.instance.collect {|instance| instance.sub_container }.flatten.compact.map {|sub_container| properties = {} top_container = sub_container.(:top_container_link) if (top_container) properties["type_1"] = top_container.type || "Container" properties["indicator_1"] = top_container.indicator if top_container. properties["indicator_1"] += " [#{top_container.barcode}]" end end properties["type_2"] = BackendEnumSource.value_for_id("container_type", sub_container.type_2_id) properties["indicator_2"] = sub_container.indicator_2 properties["barcode_2"] = sub_container. properties["type_3"] = BackendEnumSource.value_for_id("container_type", sub_container.type_3_id) properties["indicator_3"] = sub_container.indicator_3 properties } end end |
#set_node_level(node, properties) ⇒ Object
9 10 11 12 13 14 15 |
# File 'backend/app/model/mixins/resource_trees.rb', line 9 def set_node_level(node, properties) if node.level === 'otherlevel' properties[:level] = node.other_level else properties[:level] = node.level end end |