Skip to content

Commit 4c9b872

Browse files
author
AJ Christensen
committed
Get the jeditable editor working again
1 parent 67009d2 commit 4c9b872

6 files changed

Lines changed: 45 additions & 40 deletions

File tree

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ def show
3838
rescue Net::HTTPServerException => e
3939
raise NotFound, "Cannot load node #{params[:id]}"
4040
end
41-
42-
display @node
41+
if request.xhr?
42+
render JSON.pretty_generate(@node), :layout => false
43+
else
44+
display @node
45+
end
4346
end
4447

4548
def create
@@ -63,11 +66,7 @@ def update
6366
if @node
6467
@status = 202
6568
@node.save
66-
if request.xhr?
67-
render JSON.pretty_generate(@node), :layout => false
68-
else
69-
display @node
70-
end
69+
partial :node, :node => @node
7170
else
7271
raise NotFound, "You must provide a Node to update"
7372
end
@@ -84,7 +83,7 @@ def destroy
8483
@status = 202
8584
display @node
8685
else
87-
redirect(absolute_slice_url(:nodes), {:message => { :notice => "Node #{params[:id]} deleted succesfully" }, :permanent => true})
86+
redirect(absolute_slice_url(:nodes), {:message => { :notice => "Node #{params[:id]} deleted succesfully" }, :permanent => false})
8887
end
8988
end
9089

chef-server-slice/app/helpers/nodes_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ module NodesHelper
2222
def recipe_list(node)
2323
response = ""
2424
node.recipes.each do |recipe|
25-
response << "<li>#{recipe}</li>"
25+
response << "<li>#{recipe}</li>\n"
2626
end
2727
response
2828
end
2929

3030
def attribute_list(node)
3131
response = ""
3232
node.each_attribute do |k,v|
33-
response << "<li><b>#{k}</b>: #{v}</li>"
33+
response << "<li><b>#{k}</b>: #{v}</li>\n"
3434
end
3535
response
3636
end
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
- if session[:level] == :admin
2-
.edit_area#node{:to_update => node.name}
3-
%h2 Recipes
4-
%ol
5-
= recipe_list(node)
6-
%h2 Attributes
7-
%ol
8-
= attribute_list(node)
9-
- else
10-
#node
11-
%h2 Recipes
12-
%ol
13-
= recipe_list(node)
14-
%h2 Attributes
15-
%ol
16-
= attribute_list(node)
1+
%div{ :id => 'node', :class => "#{session[:level] == :admin ? 'edit_area' : 'non_edit_area'}", :to_update => @node.name}
2+
%table.table
3+
%tr
4+
%th.first Recipes
5+
%th.last &nbsp
6+
- if @node.recipes.empty?
7+
%tr
8+
%td{:colspan => 2} This node has no recipes applied, double click to add one.
9+
- else
10+
- @node.recipes.each_with_index do |recipe, index|
11+
%tr{:class => "#{index % 2 == 1 ? 'odd' : 'even'}"}
12+
%td{:colspan => 2}= recipe
13+
%table.table
14+
%tr
15+
%th.first Attributes
16+
%th.last &nbps
17+
- if @node.attribute.empty?
18+
%tr
19+
%td{:colspan => 2} This node has no attributes, double click to add one.
20+
- else
21+
- @node.attribute.each_with_index do |attrib, index|
22+
%tr{:class => "#{index % 2 == 1 ? 'odd' : 'even'}"}
23+
%td{:colspan => 2, :style => 'overflow: auto'}= "<b>#{attrib[0]}</b>: #{attrib[1]}"

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
.inner
55
%table.table
66
%tr
7-
%th.first Node Name
8-
%th &nbsp
7+
%th.first{:colspan => 2} Node Name
98
%th Control
109
%th.last &nbsp
11-
- if @node_list.empty?
12-
%tr
13-
%td{:colspan => 4}= "You appear to have no nodes - try connecting one, or validating an existing #{link_to('registration', slice_url(:registrations))}"
14-
- else
15-
- @node_list.each_with_index do |node, index|
16-
%tr{:class => "#{index % 2 == 1 ? 'odd' : 'even'}"}
17-
%td{:colspan => 2}= link_to node, slice_url(:node, { :id => node.gsub(/\./, "_" ) } )
18-
%td= link_to "Delete", slice_url(:node, { :id => node.gsub(/\./, "_") }), :method => "delete", :confirm => "Are you sure? There is no undo."
10+
- if @node_list.empty?
11+
%tr
12+
%td{:colspan => 4}= "You appear to have no nodes - try connecting one, or validating an existing #{link_to('registration', slice_url(:registrations))}"
13+
- else
14+
- @node_list.each_with_index do |node, index|
15+
%tr{:class => "#{index % 2 == 1 ? 'odd' : 'even'}"}
16+
%td{:colspan => 2}= link_to node, slice_url(:node, { :id => node.gsub(/\./, "_" ) } )
17+
%td= link_to "Delete", slice_url(:node, { :id => node.gsub(/\./, "_") }), :method => "delete", :confirm => "Are you sure? There is no undo."
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
.block#block-text
1+
.block#block-tables
22
.content
33
%h2.title= "Node #{h @node.name}"
44
.inner
5-
%textarea#attrib_json_edit= JSON.pretty_generate(@node.attribute)
6-
%textarea#recipe_json_edit= JSON.pretty_generate(@node.recipes)
5+
= partial :node, :node => @node

chef-server-slice/public/javascripts/chef.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ $(document).ready(function(){
4949
submit : "Save",
5050
cancel : "Cancel",
5151
indicator : "Saving..",
52-
loadurl : location.href + ".json",
52+
loadurl : location.href,
53+
tooltip : "Click to edit",
5354
type : "textarea",
5455
height : 300
5556
});

0 commit comments

Comments
 (0)