Skip to content

Commit

Permalink
tree builder reports - group folder logic together
Browse files Browse the repository at this point in the history
We fetch folders and report for the menu

Bring back all folders nodes as a hash (get_tree_roots)
Bring back report nodes (get_custom_kids)

Added a switch not display reports in the tree.
Fixed bug in tree_builder that would force all records to be downloaded
at once
  • Loading branch information
kbrock committed May 4, 2017
1 parent d84f42d commit 1c50bb5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
6 changes: 2 additions & 4 deletions app/presenters/tree_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,8 @@ def x_build_tree(options)
# [Object, {Object1 => {}, Object2 => {Object2a => {}}}]
#
def object_from_ancestry(object)
if object.kind_of?(Array) && object.size == 2 && object[1].kind_of?(Hash)
obj = object.first
children = object.last
[obj, children]
if object.kind_of?(Array) && object.size == 2 && (object[1].kind_of?(Hash) || object[1].kind_of?(Array))
object
else
[object, nil]
end
Expand Down
43 changes: 22 additions & 21 deletions app/presenters/tree_builder_report_reports.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class TreeBuilderReportReports < TreeBuilderReportReportsClass
REPORTS_IN_TREE = true
private

def initialize(name, type, sandbox, build = true)
Expand Down Expand Up @@ -26,39 +27,39 @@ def root_options
}
end

# Get root nodes count/array for explorer tree
# Get root node and all children report folders. (will call get_tree_custom_kids to get report details)
def x_get_tree_roots(count_only, options)
objects = @rpt_menu.each_with_index.map do |r, i|
return @rpt_menu.size if count_only
@rpt_menu.each_with_index.each_with_object({}) do |(r, node_id), a|
# load next level of folders when building the tree
@tree_state.x_tree(options[:tree])[:open_nodes].push("xx-#{i}")
folder_hash(i.to_s, r[0], @grp_title == r[0])
@tree_state.x_tree(options[:tree])[:open_nodes].push("xx-#{node_id}")

root_node = folder_hash(node_id.to_s, r[0], @grp_title == r[0])
child_nodes = @rpt_menu[node_id][1].each_with_index.each.map do |child_r, child_id|
folder_hash("#{node_id}-#{child_id}", child_r[0], @grp_title == @rpt_menu[node_id][0])
end
# returning a child hash says "there are no children"
child_nodes = child_nodes.each_with_object({}) { |c, cn| cn[c] = {} } unless REPORTS_IN_TREE

a[root_node] = child_nodes
end
count_only_or_objects(count_only, objects)
end

def x_get_tree_custom_kids(object, count_only, _options)
nodes = object[:full_id] ? object[:full_id].split('-') : object[:id].to_s.split('-')
parent_id = nodes[-2].split('_').first.to_i
node_id = nodes.last.to_i
if nodes.length == 1 && @rpt_menu[node_id][1].kind_of?(Array)
child_names = @rpt_menu[node_id][1]
return child_names.size if count_only
child_names.each_with_index.map do |r, i|
folder_hash("#{node_id}-#{i}", r[0], @grp_title == @rpt_menu[node_id][0])
end
elsif nodes.length >= 2
el1 = nodes.length == 2 ? nodes[0].split('_').first.to_i : nodes[1].split('_').first.to_i
child_names = @rpt_menu[el1][1][node_id][1]
return child_names.size if count_only
MiqReport.where(:name => child_names)
end

child_names = @rpt_menu[parent_id][1][node_id][1]
count_only ? child_names.size : MiqReport.where(:name => child_names)
end

def folder_hash(id, text, blue)
{
:id => id,
:text => text,
:icon => "pficon #{blue ? 'pficon-folder-close-blue' : 'pficon-folder-close'}",
:tip => text
:id => id,
:text => text,
:icon => "pficon #{blue ? 'pficon-folder-close-blue' : 'pficon-folder-close'}",
:tip => text
}
end
end

0 comments on commit 1c50bb5

Please sign in to comment.