Skip to content

Commit 60fb39b

Browse files
committed
Updating for ajax style json editing of nodes, simple as possible
1 parent dcfa654 commit 60fb39b

6 files changed

Lines changed: 95 additions & 18 deletions

File tree

chef-server/lib/controllers/nodes.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ def show
3535
rescue Net::HTTPServerException => e
3636
raise NotFound, "Cannot load node #{params[:id]}"
3737
end
38-
39-
display @node
38+
if params[:ajax] == "true"
39+
render JSON.pretty_generate(@node)
40+
else
41+
display @node
42+
end
4043
end
4144

4245
def create
@@ -51,11 +54,20 @@ def create
5154
end
5255

5356
def update
54-
@node = params.has_key?("inflated_object") ? params["inflated_object"] : nil
57+
if params[:ajax]
58+
@node = JSON.parse(params[:value])
59+
else
60+
@node = params.has_key?("inflated_object") ? params["inflated_object"] : nil
61+
end
62+
5563
if @node
5664
@status = 202
5765
@node.save
58-
display @node
66+
if params[:ajax]
67+
render partial("nodes/node", :node => @node)
68+
else
69+
display @node
70+
end
5971
else
6072
raise NotFound, "You must provide a Node to update"
6173
end

chef-server/lib/public/javascript/chef.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
// limitations under the License.
1717
//
1818

19-
// $(document).ready(function() {
20-
// $(".edit_area").editable(location.href + ".json", {
21-
// type : 'textarea',
22-
// cancel : 'Cancel',
23-
// submit : 'Save',
24-
// indicator : "<img src='/images/indicator.gif'>",
25-
// target : location.href + ".json",
26-
// loadtype : "GET",
27-
// loadurl : location.href + ".json?pretty=true",
28-
// tooltip : 'Click to edit...'
29-
// });
30-
// });
19+
$(document).ready(function() {
20+
$(".edit_area").editable(location.href + ".json", {
21+
type : 'textarea',
22+
cancel : 'Cancel',
23+
submit : 'Save',
24+
indicator : "<img src='/images/indicator.gif'>",
25+
target : location.href + ".json?ajax=true",
26+
loadtype : "GET",
27+
loadurl : location.href + ".json?ajax=true",
28+
tooltip : 'Click to edit...',
29+
method : "PUT"
30+
});
31+
});

chef-server/lib/views/nodes/_node.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.node
22
%h1
33
= "Node #{h node.name}"
4-
%div.edit_area#node{:to_update => node.name}
4+
.edit_area#node{:to_update => node.name}
55
%h2 Recipes
66
%ol
77
= recipe_list(node)

chef/Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- ruby -*-
22
require 'rubygems'
33
require 'rake/gempackagetask'
4+
require 'rake/rdoctask'
45
require './tasks/rspec.rb'
56

67
GEM = "chef"
@@ -40,6 +41,10 @@ Rake::GemPackageTask.new(spec) do |pkg|
4041
pkg.gem_spec = spec
4142
end
4243

44+
Rake::RDocTask.new do |rd|
45+
rd.rdoc_files.include("lib/**/*.rb")
46+
end
47+
4348
task :install => [:package] do
4449
sh %{sudo gem install pkg/#{GEM}-#{VERSION} --no-rdoc --no-ri}
4550
end

chef/lib/chef/compile.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def initialize()
3333
# Chef::Node.find_file(name)
3434
#
3535
# The first step in compiling the catalog. Results available via the node accessor.
36+
#
37+
# === Returns
38+
# <Chef::Node>:: The loaded Chef Node
3639
def load_node(name)
3740
Chef::Log.debug("Loading Chef Node #{name} from CouchDB")
3841
@node = Chef::Node.load(name)
@@ -42,6 +45,9 @@ def load_node(name)
4245
end
4346

4447
# Load all the attributes, from every cookbook
48+
#
49+
# === Returns
50+
# true:: Always returns true
4551
def load_attributes()
4652
@cookbook_loader.each do |cookbook|
4753
cookbook.load_attributes(@node)
@@ -53,16 +59,22 @@ def load_attributes()
5359
# the recipes.
5460
#
5561
# Results available via the definitions accessor.
62+
#
63+
# === Returns
64+
# true:: Always returns true
5665
def load_definitions()
5766
@cookbook_loader.each do |cookbook|
5867
hash = cookbook.load_definitions
5968
@definitions.merge!(hash)
6069
end
70+
true
6171
end
6272

6373
# Load all the libraries, from every cookbook, so they are available when we process
6474
# the recipes.
6575
#
76+
# === Returns
77+
# true:: Always returns true
6678
def load_libraries()
6779
@cookbook_loader.each do |cookbook|
6880
cookbook.load_libraries
@@ -74,6 +86,9 @@ def load_libraries()
7486
#
7587
# The results are available via the collection accessor (which returns a Chef::ResourceCollection
7688
# object)
89+
#
90+
# === Returns
91+
# true:: Always returns true
7792
def load_recipes
7893
@node.recipes.each do |recipe|
7994
Chef::Log.debug("Loading Recipe #{recipe}")
@@ -86,6 +101,7 @@ def load_recipes
86101
cookbook.load_recipe("default", @node, @collection, @definitions, @cookbook_loader)
87102
end
88103
end
104+
true
89105
end
90106

91107
end

chef/lib/chef/config.rb

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,24 @@ class Config
6262
class << self
6363
include Chef::Mixin::FromFile
6464

65+
# Pass Chef::Config.configure() a block, and it will yield @configuration.
66+
#
67+
# === Parameters
68+
# <block>:: A block that takes @configure as it's argument
6569
def configure(&block)
6670
yield @configuration
6771
end
6872

73+
# Get the value of a configuration option
74+
#
75+
# === Parameters
76+
# config_option<Symbol>:: The configuration option to return
77+
#
78+
# === Returns
79+
# value:: The value of the configuration option
80+
#
81+
# === Raises
82+
# <ArgumentError>:: If the configuration option does not exist
6983
def [](config_option)
7084
if @configuration.has_key?(config_option.to_sym)
7185
@configuration[config_option.to_sym]
@@ -74,14 +88,43 @@ def [](config_option)
7488
end
7589
end
7690

91+
# Set the value of a configuration option
92+
#
93+
# === Parameters
94+
# config_option<Symbol>:: The configuration option to set (within the [])
95+
# value:: The value for the configuration option
96+
#
97+
# === Returns
98+
# value:: The new value of the configuration option
7799
def []=(config_option, value)
78100
@configuration[config_option.to_sym] = value
79101
end
80102

103+
# Check if Chef::Config has a configuration option.
104+
#
105+
# === Parameters
106+
# key<Symbol>:: The configuration option to check for
107+
#
108+
# === Returns
109+
# <True>:: If the configuration option exists
110+
# <False>:: If the configuration option does not exist
81111
def has_key?(key)
82112
@configuration.has_key?(key.to_sym)
83113
end
84-
114+
115+
# Allows for simple lookups and setting of configuration options via method calls
116+
# on Chef::Config. If there any arguments to the method, they are used to set
117+
# the value of the configuration option. Otherwise, it's a simple get operation.
118+
#
119+
# === Parameters
120+
# method_symbol<Symbol>:: The method called. Must match a configuration option.
121+
# *args:: Any arguments passed to the method
122+
#
123+
# === Returns
124+
# value:: The value of the configuration option.
125+
#
126+
# === Raises
127+
# <ArgumentError>:: If the method_symbol does not match a configuration option.
85128
def method_missing(method_symbol, *args)
86129
if @configuration.has_key?(method_symbol)
87130
if args.length == 1

0 commit comments

Comments
 (0)