Skip to content

Commit c883ef3

Browse files
author
AJ Christensen
committed
CHEF-129: Implement pilu's web-app-theme
Also add the Futon JSON visualizer.
1 parent 434c50f commit c883ef3

6 files changed

Lines changed: 67 additions & 5 deletions

File tree

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# Author:: Adam Jacob (<adam@opscode.com>)
3+
# Author:: AJ Christensen (<aj@junglist.gen.nz>)
34
# Copyright:: Copyright (c) 2008 Opscode, Inc.
45
# License:: Apache License, Version 2.0
56
#
@@ -34,7 +35,31 @@ def attribute_list(node)
3435
end
3536
response
3637
end
38+
39+
# Recursively build a tree of lists.
40+
def build_tree(node)
41+
list = "<dl>"
42+
list << "\n<!-- Beginning of Node Tree -->"
43+
walk = lambda do |key,value|
44+
case value
45+
when Hash, Array
46+
list << "\n<!-- Beginning of Enumerable obj -->"
47+
list << "\n<dt>#{key}</dt>"
48+
list << "<dd>"
49+
list << "\t<dl>\n"
50+
value.each(&walk)
51+
list << "\t</dl>\n"
52+
list << "</dd>"
53+
list << "\n<!-- End of Enumerable obj -->"
54+
55+
else
56+
list << "\n<dt>#{key}</dt>"
57+
list << "<dd>#{value}</dd>"
58+
end
59+
end
60+
node.attribute.each(&walk)
61+
list << "</dl>"
62+
end
3763
end
38-
3964
end
4065
end

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
%table.table
1414
%tr
1515
%th.first Attributes
16-
%th.last &nbps
16+
%th.last &nbsp
1717
- if @node.attribute.empty?
1818
%tr
1919
%td{:colspan => 2} This node has no attributes, double click to add one.
2020
- 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]}"
21+
%tr
22+
%td{:colspan => 2}= build_tree(@node)
176 Bytes
Loading
181 Bytes
Loading

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ $(document).ready(function(){
4242
});
4343
});
4444

45+
$("dd:has(dl)").livequery(function(){
46+
$(this).hide().prev("dt").addClass("collapsed");
47+
});
48+
$("dd:not(:has(dl))").livequery(function(){
49+
$(this).addClass("inline").prev().addClass("inline");
50+
});
51+
$("dt.collapsed").livequery(function(){
52+
$(this).click(function() {
53+
$(this).toggleClass("collapsed").next().toggle();
54+
});
55+
});
56+
4557
// editable table for the node show view
4658
$(".edit_area").editable(location.href + ".json", {
4759
target : location.href,
@@ -52,9 +64,15 @@ $(document).ready(function(){
5264
loadurl : location.href,
5365
tooltip : "Click to edit",
5466
type : "textarea",
67+
event : "dblclick",
5568
height : 300
5669
});
5770

71+
72+
//alert("blah" + $('#json_tree_source').text());
73+
//var json = $('#json_tree_source').text();
74+
//$('#attribute_tree_view').append(TreeView($('#json_tree_source').text()));
75+
5876
// accordion for the cookbooks show view
5977
$('.accordion .head').click(function() {
6078
$(this).next().toggle('slow');
@@ -64,6 +82,7 @@ $(document).ready(function(){
6482
// global facebox callback
6583
$('a[rel*=facebox]').facebox();
6684

85+
/*
6786
JSONEditor.prototype.ADD_IMG = '/images/add.png';
6887
JSONEditor.prototype.DELETE_IMG = '/images/delete.png';
6988
var attrib_editor = new JSONEditor($("#attrib_json_edit"), 400, 300);
@@ -73,4 +92,5 @@ $(document).ready(function(){
7392
var recipe_editor = new JSONEditor($("#recipe_json_edit"), 400, 300);
7493
recipe_editor.doTruncation(true);
7594
recipe_editor.showFunctionButtons();
95+
*/
7696
});

chef-server-slice/public/stylesheets/chef.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,22 @@
2929
.search td {
3030
/*overflow: auto;*/
3131
font-size: 0.8em;
32+
}
33+
34+
dl dt { font-weight: bold; }
35+
.content td dl { margin: 0; padding: 0; }
36+
.content td dt {
37+
background: transparent url(/images/toggle-collapse.gif) 0 3px no-repeat;
38+
clear: left; color: #333; cursor: pointer; line-height: 1em;
39+
margin-left: -12px; padding-left: 14px;
40+
}
41+
.content td dd { margin: 0;
42+
padding: 0 0 0 1em;
43+
}
44+
.content td dt.collapsed {
45+
background-image: url(/images/toggle-expand.gif);
46+
}
47+
.content td dt.inline { background-image: none; cursor: default;
48+
float: left; margin-left: 0; padding-left: 2px; padding-right: .5em;
49+
padding-top: 2px;
3250
}

0 commit comments

Comments
 (0)