From 70ba60c8516254066472a8fbe1315dc6b17a8fbf Mon Sep 17 00:00:00 2001 From: sdelano Date: Wed, 25 Aug 2010 12:34:01 -0700 Subject: filter nodes by environment in webui --- chef-server-webui/app/controllers/nodes.rb | 9 ++++++--- chef-server-webui/app/views/cookbooks/index.html.haml | 2 +- chef-server-webui/app/views/nodes/index.html.haml | 15 +++++++++++++-- chef-server-webui/config/router.rb | 2 ++ 4 files changed, 22 insertions(+), 6 deletions(-) (limited to 'chef-server-webui') diff --git a/chef-server-webui/app/controllers/nodes.rb b/chef-server-webui/app/controllers/nodes.rb index f2b9cbb30e..9cbcc11555 100644 --- a/chef-server-webui/app/controllers/nodes.rb +++ b/chef-server-webui/app/controllers/nodes.rb @@ -28,10 +28,13 @@ class Nodes < Application before :require_admin, :only => [:destroy] def index + @environments = Chef::Environment.list.keys.sort begin - node_hash = Chef::Node.list - require 'pp' - pp node_hash + if params[:environment_id] + node_hash = Chef::Node.list_by_environment(params[:environment_id]) + else + node_hash = Chef::Node.list + end @node_list = node_hash.keys.sort rescue => e Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}") diff --git a/chef-server-webui/app/views/cookbooks/index.html.haml b/chef-server-webui/app/views/cookbooks/index.html.haml index 39cee76d2c..f4139cb927 100644 --- a/chef-server-webui/app/views/cookbooks/index.html.haml +++ b/chef-server-webui/app/views/cookbooks/index.html.haml @@ -2,7 +2,7 @@ .block#block-tables .content %h2.title - = Cookbooks + Cookbooks %select{:name => "choice", :onchange => "jump(this)", :size => "1"} %option{:value => ""} Environments %option{:value => ""} ------------ diff --git a/chef-server-webui/app/views/nodes/index.html.haml b/chef-server-webui/app/views/nodes/index.html.haml index 021993af59..ef2708d612 100644 --- a/chef-server-webui/app/views/nodes/index.html.haml +++ b/chef-server-webui/app/views/nodes/index.html.haml @@ -1,6 +1,14 @@ +%script{:type=>"text/javascript", :src => "/javascripts/drop_down_menu.js"} .block#block-tables .content - %h2.title Node List + %h2.title + Node List + %select{:name => "choice", :onchange => "jump(this)", :size => "1"} + %option{:value => ""} Environments + %option{:value => ""} ------------ + %option{:value => url(:nodes)} All + - @environments.each do |environment| + %option{:value => url(:nodes_by_environment, :environment_id => environment), :selected => params[:environment_id] == environment}= environment .inner = partial('navigation', :active => 'index') .content @@ -12,7 +20,10 @@ %th.last   - even = false - if @node_list.empty? - %td{:colspan => 4}= "You appear to have no nodes - try connecting one, or creating or editing a #{link_to('client', url(:clients))}" + - if params[:environment_id] + %td{:colspan => 4}= "The environment #{params[:environment_id]} has no nodes" + - else + %td{:colspan => 4}= "You have no nodes - try connecting one, or creating or editing a #{link_to('node', url(:nodes))}" - else - @node_list.each do |node| %tr{:class => even ? "even": "odd" } diff --git a/chef-server-webui/config/router.rb b/chef-server-webui/config/router.rb index beb304f4a3..845364c9c5 100644 --- a/chef-server-webui/config/router.rb +++ b/chef-server-webui/config/router.rb @@ -19,6 +19,8 @@ Merb::Router.prepare do resources :nodes, :id => /[^\/]+/ + match("/nodes/_environments/:environment_id").to(:controller => "nodes", :action => "index").name(:nodes_by_environment) + resources :clients, :id => /[^\/]+/ resources :roles resources :environments do |e| -- cgit v1.2.1