Skip to content

Commit 5cd1858

Browse files
Nuo Yandanielsdeleo
authored andcommitted
cookbooks work for chef server webui
1 parent dc24a99 commit 5cd1858

4 files changed

Lines changed: 68 additions & 18 deletions

File tree

‎chef-server-webui/app/controllers/cookbooks.rb‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
class Cookbooks < Application
2424

2525
provides :html, :json
26-
before :login_required
26+
before :login_required
27+
before :params_helper
28+
29+
attr_reader :cookbook_id
30+
def params_helper
31+
@cookbook_id = params[:id] || params[:cookbook_id]
32+
end
2733

2834
def index
2935
@cl = begin
@@ -38,7 +44,19 @@ def index
3844

3945
def show
4046
begin
41-
@cookbook = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("cookbooks/#{params[:id]}")
47+
# array of versions, sorted from large to small e.g. ["0.20.0", "0.1.0"]
48+
versions = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("cookbooks/#{cookbook_id}")[cookbook_id].sort!{|x,y| y <=> x }
49+
# if version is not specified in the url, get the most recent version, otherwise get the specified version
50+
version = if params[:cb_version].nil? || params[:cb_version].empty?
51+
versions.first
52+
else
53+
params[:cb_version]
54+
end
55+
56+
@cookbook = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("cookbooks/#{cookbook_id}/#{version}")
57+
58+
# by default always show the largest version number (assuming largest means most recent)
59+
@other_versions = versions - [version]
4260
raise NotFound unless @cookbook
4361
display @cookbook
4462
rescue => e
Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
1+
%script{:type=>"text/javascript", :src => "/javascripts/drop_down_menu.js"}
12
.block#block-text
23
.content
3-
%h2.title= "Cookbook: #{h @cookbook["name"]}"
4+
%h2
5+
.title
6+
= "Cookbook: #{h @cookbook.manifest["name"]}"
7+
- unless @other_versions.nil? || @other_versions.empty?
8+
%select{:name => "choice", :onchange => "jump(this)", :size => "1"}
9+
%option{:value => ""} Other Versions
10+
%option{:value => ""} --------------
11+
- @other_versions.each do |v|
12+
%option{:value => url(:show_specific_version_cookbook, :cookbook_id => @cookbook_id, :cb_version => v)} "#{v}"
413
.inner
514
.accordion
6-
- unless @cookbook["libraries"].empty?
15+
- unless @cookbook.manifest["libraries"].empty?
716
%h2.head= link_to "Library Files", "JavaScript:void(0);"
817
.files
9-
- @cookbook["libraries"].each do |f|
18+
- @cookbook.manifest["libraries"].each do |f|
1019
.code
1120
%h4.head= link_to File.basename(f["name"]), "JavaScript:void(0);"
12-
%pre.ruby= syntax_highlight(f["uri"])
13-
- unless @cookbook["attributes"].empty?
21+
%pre.ruby= syntax_highlight(get_file(f["uri"]))
22+
- unless @cookbook.manifest["attributes"].empty?
1423
%h2.head= link_to "Attribute Files", "JavaScript:void(0);"
1524
.files
16-
- @cookbook["attributes"].each do |f|
25+
- @cookbook.manifest["attributes"].each do |f|
1726
.code
1827
%h4.head= link_to File.basename(f["name"]), "JavaScript:void(0);"
19-
%pre.ruby= syntax_highlight(f["uri"])
20-
- unless @cookbook["definitions"].empty?
28+
%pre.ruby= syntax_highlight(get_file(f["uri"]))
29+
- unless @cookbook.manifest["definitions"].empty?
2130
%h2.head= link_to "Definition Files", "JavaScript:void(0);"
2231
.files
23-
- @cookbook["definitions"].each do |f|
32+
- @cookbook.manifest["definitions"].each do |f|
2433
.code
2534
%h4.head= link_to File.basename(f["name"]), "JavaScript:void(0);"
26-
%pre.ruby= syntax_highlight(f["uri"])
27-
- unless @cookbook["recipes"].empty?
35+
%pre.ruby= syntax_highlight(get_file(f["uri"]))
36+
- unless @cookbook.manifest["recipes"].empty?
2837
%h2.head= link_to "Recipe Files", "JavaScript:void(0);"
2938
.files
30-
- @cookbook["recipes"].each do |f|
39+
- @cookbook.manifest["recipes"].each do |f|
3140
.code
3241
%h4.head= link_to File.basename(f["name"]), "JavaScript:void(0);"
33-
%pre.ruby= syntax_highlight(f["uri"])
34-
- unless @cookbook["templates"].empty?
42+
%pre.ruby= syntax_highlight(get_file(f["uri"]))
43+
- unless @cookbook.manifest["templates"].empty?
3544
%h2.head= link_to "Template Files", "JavaScript:void(0);"
3645
.files
37-
- @cookbook["templates"].each do |f|
46+
- @cookbook.manifest["templates"].each do |f|
3847
.code
3948
%h4.head= link_to File.basename(f["name"]), "JavaScript:void(0);"
40-
%pre.ruby= syntax_highlight(f["uri"])
49+
%pre.ruby= syntax_highlight(get_file(f["uri"]))

‎chef-server-webui/config/router.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
match("/cookbooks/:cookbook_id/attributes", :cookbook_id => /[\w\.]+/).to(:controller => "cookbook_attributes", :action => "index")
2626
match("/cookbooks/:cookbook_id/files", :cookbook_id => /[\w\.]+/).to(:controller => "cookbook_files", :action => "index")
2727

28+
match("/cookbooks/:cookbook_id/:cb_version", :cb_version => /[\w\.]+/, :method => 'get').to(:controller => "cookbooks", :action => "show").name(:show_specific_version_cookbook)
2829
resources :cookbooks
30+
2931
resources :clients
3032

3133
match("/databags/:databag_id/databag_items", :method => 'get').to(:controller => "databags", :action => "show", :id=>":databag_id")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function land(ref, target)
2+
{
3+
lowtarget=target.toLowerCase();
4+
if (lowtarget=="_self") {window.location=loc;}
5+
else {if (lowtarget=="_top") {top.location=loc;}
6+
else {if (lowtarget=="_blank") {window.open(loc);}
7+
else {if (lowtarget=="_parent") {parent.location=loc;}
8+
else {parent.frames[target].location=loc;};
9+
}}}
10+
}
11+
function jump(menu)
12+
{
13+
ref=menu.options[menu.selectedIndex].value;
14+
splitc=ref.lastIndexOf("*");
15+
target="";
16+
if (splitc!=-1)
17+
{loc=ref.substring(0,splitc);
18+
target=ref.substring(splitc+1,1000);}
19+
else {loc=ref; target="_self";};
20+
if (ref != "") {land(loc,target);}
21+
}

0 commit comments

Comments
 (0)