Skip to content

Commit 70ba60c

Browse files
sdelanoSeth Falcon
authored andcommitted
filter nodes by environment in webui
1 parent 0c73903 commit 70ba60c

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

chef-server-webui/app/controllers/nodes.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ class Nodes < Application
2828
before :require_admin, :only => [:destroy]
2929

3030
def index
31+
@environments = Chef::Environment.list.keys.sort
3132
begin
32-
node_hash = Chef::Node.list
33-
require 'pp'
34-
pp node_hash
33+
if params[:environment_id]
34+
node_hash = Chef::Node.list_by_environment(params[:environment_id])
35+
else
36+
node_hash = Chef::Node.list
37+
end
3538
@node_list = node_hash.keys.sort
3639
rescue => e
3740
Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")

chef-server-webui/app/views/cookbooks/index.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.block#block-tables
33
.content
44
%h2.title
5-
= Cookbooks
5+
Cookbooks
66
%select{:name => "choice", :onchange => "jump(this)", :size => "1"}
77
%option{:value => ""} Environments
88
%option{:value => ""} ------------

chef-server-webui/app/views/nodes/index.html.haml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
%script{:type=>"text/javascript", :src => "/javascripts/drop_down_menu.js"}
12
.block#block-tables
23
.content
3-
%h2.title Node List
4+
%h2.title
5+
Node List
6+
%select{:name => "choice", :onchange => "jump(this)", :size => "1"}
7+
%option{:value => ""} Environments
8+
%option{:value => ""} ------------
9+
%option{:value => url(:nodes)} All
10+
- @environments.each do |environment|
11+
%option{:value => url(:nodes_by_environment, :environment_id => environment), :selected => params[:environment_id] == environment}= environment
412
.inner
513
= partial('navigation', :active => 'index')
614
.content
@@ -12,7 +20,10 @@
1220
%th.last &nbsp;
1321
- even = false
1422
- if @node_list.empty?
15-
%td{:colspan => 4}= "You appear to have no nodes - try connecting one, or creating or editing a #{link_to('client', url(:clients))}"
23+
- if params[:environment_id]
24+
%td{:colspan => 4}= "The environment #{params[:environment_id]} has no nodes"
25+
- else
26+
%td{:colspan => 4}= "You have no nodes - try connecting one, or creating or editing a #{link_to('node', url(:nodes))}"
1627
- else
1728
- @node_list.each do |node|
1829
%tr{:class => even ? "even": "odd" }

chef-server-webui/config/router.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
Merb::Router.prepare do
2121
resources :nodes, :id => /[^\/]+/
22+
match("/nodes/_environments/:environment_id").to(:controller => "nodes", :action => "index").name(:nodes_by_environment)
23+
2224
resources :clients, :id => /[^\/]+/
2325
resources :roles
2426
resources :environments do |e|

0 commit comments

Comments
 (0)