Skip to content

Commit

Permalink
webui: cookbooks
Browse files Browse the repository at this point in the history
* fetch versions for ONE cookbook from API
* handle nil environment
  • Loading branch information
sdelano authored and Seth Falcon committed Feb 14, 2011
1 parent aefd31a commit 66ffa27
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions chef-server-webui/app/controllers/cookbooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ def params_helper
@cookbook_id = params[:id] || params[:cookbook_id]
end

def fetch_cookbook_versions(num_versions, use_envs=true)
def fetch_cookbook_versions(cookbook, num_versions, use_envs=true)
url = if use_envs
"environments/#{session[:environment]}/cookbooks"
env = session[:environment] || "_default"
"environments/#{env}/cookbooks"
else
"cookbooks"
end
# we want to display at most 5 versions, but we ask for 6. This
# tells us if we should display a show all button or not.
url += "/#{cookbook}" if cookbook
url += "?num_versions=#{num_versions}"
begin
result = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest(url)
Expand All @@ -60,13 +62,13 @@ def fetch_cookbook_versions(num_versions, use_envs=true)
end

def index
@cl = fetch_cookbook_versions(6)
@cl = fetch_cookbook_versions(nil, 6)
display @cl
end

def show
begin
all_books = fetch_cookbook_versions("all")
all_books = fetch_cookbook_versions(cookbook_id, "all")
versions = all_books[cookbook_id].map { |v| v["version"] }
# if version is not specified in the url, get the most recent
# version, otherwise get the specified version
Expand Down Expand Up @@ -97,7 +99,7 @@ def cb_versions
provides :json
use_envs = session[:environment] && !params[:ignore_environments]
num_versions = params[:num_versions] || "all"
all_books = fetch_cookbook_versions(num_versions, use_envs)
all_books = fetch_cookbook_versions(cookbook_id, num_versions, use_envs)
display({ cookbook_id => all_books[cookbook_id] })
end

Expand Down

0 comments on commit 66ffa27

Please sign in to comment.