mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Small tweaks
This commit is contained in:
@@ -8,7 +8,7 @@ module OpenFoodNetwork
|
||||
|
||||
def build_tree(items, remaining_rules)
|
||||
rules = remaining_rules.clone
|
||||
unless rules.empty?
|
||||
if rules.any?
|
||||
rule = rules.delete_at(0) # Remove current rule for subsequent groupings
|
||||
group_and_sort(rule, rules, items)
|
||||
else
|
||||
@@ -20,7 +20,7 @@ module OpenFoodNetwork
|
||||
branch = {}
|
||||
groups = items.group_by { |item| rule[:group_by].call(item) }
|
||||
sorted_groups = groups.sort_by { |key, value| rule[:sort_by].call(key) }
|
||||
sorted_groups.each do |property,items_by_property|
|
||||
sorted_groups.each do |property, items_by_property|
|
||||
branch[property] = build_tree(items_by_property, remaining_rules)
|
||||
branch[property][:summary_row] = { items: items_by_property, columns: rule[:summary_columns] } unless rule[:summary_columns] == nil || is_leaf_node(branch[property])
|
||||
end
|
||||
@@ -44,15 +44,15 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def table(items)
|
||||
tree = build_tree(items,@rules)
|
||||
tree = build_tree(items, @rules)
|
||||
table = build_table(tree)
|
||||
table
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def is_leaf_node(node)
|
||||
node.is_a? Array
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user