Group and class view pages now show the nodes which are members of that group or class via inherited groups, along with which groups provide the membership.
Signed-off-by: Nick Lewis <[email protected]> --- app/models/node_class.rb | 15 +++++++++++++++ app/models/node_group.rb | 13 +++++++++++++ app/views/node_classes/show.html.haml | 2 +- app/views/node_groups/show.html.haml | 3 +-- app/views/nodes/_nodes.html.haml | 4 +++- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/models/node_class.rb b/app/models/node_class.rb index ca7ed48..661bf3c 100644 --- a/app/models/node_class.rb +++ b/app/models/node_class.rb @@ -1,6 +1,8 @@ class NodeClass < ActiveRecord::Base def self.per_page; 50 end # Pagination + include NodeGroupGraph + has_many :node_group_class_memberships, :dependent => :destroy has_many :node_class_memberships, :dependent => :destroy @@ -30,4 +32,17 @@ class NodeClass < ActiveRecord::Base def self.find_from_form_ids(*ids) ids.map{|entry| entry.to_s.split(/[ ,]/)}.flatten.reject(&:blank?).uniq.map{|id| self.find(id)} end + + def node_list + return @node_list if @node_list + all = {} + self.walk(:node_groups,:loops => false) do |group,_| + group.nodes.each do |node| + all[node] ||= Set.new + all[node] << group + end + group + end + @node_list = all + end end diff --git a/app/models/node_group.rb b/app/models/node_group.rb index b82e86d..9bbbd7e 100644 --- a/app/models/node_group.rb +++ b/app/models/node_group.rb @@ -92,4 +92,17 @@ class NodeGroup < ActiveRecord::Base end @node_group_child_list = all end + + def node_list + return @node_list if @node_list + all = {} + self.walk(:node_group_children,:loops => false) do |group,_| + group.nodes.each do |node| + all[node] ||= Set.new + all[node] << group + end + group + end + @node_list = all + end end diff --git a/app/views/node_classes/show.html.haml b/app/views/node_classes/show.html.haml index b6a035c..f2c91ab 100644 --- a/app/views/node_classes/show.html.haml +++ b/app/views/node_classes/show.html.haml @@ -15,6 +15,6 @@ .section %h3 Nodes in this class - if @node_class.nodes.present? - = render 'nodes/nodes', :nodes => @node_class.nodes + = render 'nodes/nodes', :nodes => @node_class.node_list.map(&:first) - else = describe_no_matches_for :nodes, :class diff --git a/app/views/node_groups/show.html.haml b/app/views/node_groups/show.html.haml index 4f7ba7b..187b9a6 100644 --- a/app/views/node_groups/show.html.haml +++ b/app/views/node_groups/show.html.haml @@ -28,7 +28,6 @@ = " via #{parents.map{|p| link_to(p.name,p)}.to_sentence}" unless parents.include?(resource) - else = describe_no_matches_as 'No child groups' - .item - if @node_group.nodes.present? .section @@ -36,6 +35,6 @@ .section %h3 Nodes for this group - if @node_group.nodes.present? - = render 'nodes/nodes', :nodes => @node_group.nodes + = render 'nodes/nodes', :nodes => @node_group.node_list.map(&:first) - else = describe_no_matches_for :nodes, :group diff --git a/app/views/nodes/_nodes.html.haml b/app/views/nodes/_nodes.html.haml index 3d8b8b2..333e9ab 100644 --- a/app/views/nodes/_nodes.html.haml +++ b/app/views/nodes/_nodes.html.haml @@ -13,7 +13,8 @@ ↓ Latest report %tbody - if nodes.present? - - for node in nodes + - nodes.each do |node| + - sources = resource.node_list[node] rescue nil %tr[node]{:class => "#{'active' if node == @node}"} -# %td.check -# = check_box_tag dom_id(node) @@ -22,6 +23,7 @@ = node_status_icon(node) %td.hostname = link_to h(node.name), node + = " via #{sources.map{|s| link_to(s.name,s)}.to_sentence}" unless sources.nil? or sources.include?(resource) %td.latest_report = node.last_report ? node.last_report.time : "Has not reported" = pagination_for nodes, more_link -- 1.7.2.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
