Skip to content

Commit b51177d

Browse files
author
Seth Falcon
committed
Fixup cookbook constraint control for new data format
1 parent f986803 commit b51177d

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ class Cookbooks < Application
3131
attr_reader :cookbook_id
3232
def params_helper
3333
@cookbook_id = params[:id] || params[:cookbook_id]
34-
@num_versions = params[:num_versions] || 6
3534
end
3635

37-
def fetch_cookbook_versions(num_versions=6)
38-
url = if session[:environment]
36+
def fetch_cookbook_versions(num_versions, use_envs=true)
37+
url = if use_envs
3938
"environments/#{session[:environment]}/cookbooks"
4039
else
4140
"cookbooks"
@@ -96,7 +95,9 @@ def show
9695
# provides :json, for the javascript on the environments web form.
9796
def cb_versions
9897
provides :json
99-
all_books = fetch_cookbook_versions(@num_versions)
98+
use_envs = session[:environment] && !params[:ignore_environments]
99+
num_versions = params[:num_versions] || "all"
100+
all_books = fetch_cookbook_versions(num_versions, use_envs)
100101
display({ cookbook_id => all_books[cookbook_id] })
101102
end
102103

‎chef-server-webui/public/javascripts/cookbook_constraint_ctrl.js‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,35 @@ function jQuerySuggest(timestamp){
55
}
66

77
function populateVersionBoxContent(timestamp, cb_name){
8-
$.getJSON('/cookbooks/'+cb_name, function(result){
9-
jQuery('#cookbook_version_'+timestamp).suggest(result[cb_name]);
8+
// Ignore environments when editing the environments constraints
9+
$.getJSON('/cookbooks/'+cb_name+'?num_versions=all&ignore_environments=true',
10+
function(result){
11+
console.log("result");
12+
console.log(result);
13+
var versions = $.map(result[cb_name],
14+
function(item, i) {
15+
return item["version"];
1016
});
17+
jQuery('#cookbook_version_'+timestamp).suggest(versions);
18+
});
1119
}
1220

1321
function clearVersionBox(box, timestamp){
1422
populateVersionBoxContent(timestamp, retrieveCbName(timestamp));
15-
//if (box.value == "0.0.0"){box.value = "";}
1623
error_message = document.getElementById('inline_error_message_' + timestamp);
1724
if (error_message != null)
1825
$(error_message).remove();
1926
}
2027

2128
function validateVersionBoxValue(box, timestamp){
22-
if (box.value.match(/^\d+\.\d+\.\d+$/) == null){
29+
setTimeout(function() {
30+
if (box.value.match(/^[0-9]+\.[0-9]+\.[0-9]+$/) == null){
2331
if (box.value.length != 0 && document.getElementById('inline_error_message_' + timestamp) == null)
24-
$(box).parent().append('<span class="inline_error_message" id="inline_error_message_' + timestamp + '" >Invalid version format. The version should be in the format of 0.0.0.</span>');
32+
$(box).parent().append('<span class="inline_error_message" id="inline_error_message_' + timestamp + '" >Invalid version format. The version should be in the format of x.y.z.</span>');
2533
if (box.value.length==0)
2634
box.value = "0.0.0";
2735
}
36+
}, 100);
2837
}
2938

3039
function buildCookbookList(cookbook_names, default_cookbook){
@@ -75,4 +84,4 @@ function addTableRow(default_cookbook, default_operator, default_version){
7584

7685
function removeTableRow(row){
7786
row.remove();
78-
}
87+
}

0 commit comments

Comments
 (0)