Browse files

Add Options sections to the sidebar

Move JS init out of the body tag and use $(document).ready
  • Loading branch information...
1 parent 1eec585 commit b865ccd94940f105905e6bfb72ede91c25f1724b @tobami tobami committed May 9, 2012
View
2 kitchen/dashboard/graphs.py
@@ -63,7 +63,7 @@ def generate_node_map(nodes, roles, show_hostnames=True):
for node in nodes:
label = "\n".join([role for role in node['role'] \
if not role.startswith(REPO['EXCLUDE_ROLE_PREFIX'])])
- if show_hostnames not in [False, None, "false"]:
+ if show_hostnames:
label = node['name'] + "\n" + label
color = "lightyellow"
role_prefix = None
View
17 kitchen/dashboard/static/js/sidebar.js
@@ -1,3 +1,7 @@
+$(document).ready(function() {
+ setupClickHandlers();
+});
+
function setupClickHandlers() {
/**
* Assign click handlers to all sidebar entries.
@@ -8,12 +12,12 @@ function setupClickHandlers() {
if (active_buttons.index(this) > -1) {
active_buttons = active_buttons.not(this);
} else {
- //active_buttons.add(this);
+ // active_buttons.add(this);
active_buttons = $.fn.add.call(active_buttons, this);
}
var changed_environment = false;
- var changed_virt_environment = false;
- // add already selected buttons to the params
+ var changed_virt = false;
+ // Add already selected buttons to the params
for (var i=0; i < active_buttons.length; i++) {
var datatype = active_buttons[i].dataset['type'];
var dataname = active_buttons[i].dataset['name'];
@@ -27,8 +31,8 @@ function setupClickHandlers() {
} else if (datatype === 'virt') {
if (active_buttons[i] === this) {
parameters[datatype] = dataname;
- changed_virt_environment = true;
- } else if (!changed_virt_environment) {
+ changed_virt = true;
+ } else if (!changed_virt) {
parameters[datatype] = dataname;
}
} else {
@@ -42,9 +46,8 @@ function setupClickHandlers() {
// If there are no env or virt selections set parameter to an empty string
// to prevent server-side defaults from setting them
- var datatypes = ['env', 'roles'];
+ var datatypes = ['env', 'roles', 'options'];
if ( show_virt ) { datatypes.push('virt'); }
- console.log(datatypes);
for (var datatype in datatypes) {
if (!(datatypes[datatype] in parameters)) {
parameters[datatypes[datatype]] = "";
View
9 kitchen/dashboard/views.py
@@ -62,10 +62,17 @@ def graph(request):
data['nodes'] = []
messages.add_message(request,
messages.INFO, "Please select an environment")
+ options = request.GET.get('options', '').split(",")
+ if not options:
+ # Set defaults
+ options = []
+ if SHOW_HOST_NAMES:
+ options.append("show_hostnames")
+ data['show_hostnames'] = 'show_hostnames' in options
graphs.generate_node_map(
data['nodes'],
data.get('roles', []),
- request.GET.get('show_hostnames', SHOW_HOST_NAMES)
+ data['show_hostnames']
)
data['query_string'] = request.META['QUERY_STRING']
return render_to_response('graph.html',
View
5 kitchen/templates/base.html
@@ -19,7 +19,7 @@
{% block extrahead %}{% endblock %}
<title>{% block title %}Kitchen{% endblock %}</title>
</head>
- <body onload="setupClickHandlers();">
+ <body>
{% block bodyhead %}
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
@@ -55,7 +55,7 @@
</li>
{% for env in environments %}
<li {% if env.name == filter_env %} class="active" {% endif %}>
- <a href="#" data-type="env" data-name="{{env.name}}" class="sidebar_link">{{env.name}} <span class="badge badge-warning">{{env.count}}</span></a>
+ <a href="#" data-type="env" data-name="{{env.name}}" class="sidebar_link">{{env.name}} <span class="badge badge-warning">{{env.counts}}</span></a>
</li>
{% endfor %}
<li class="nav-header">
@@ -75,6 +75,7 @@
<a href="#" data-type="virt" data-name="{{virt_role}}" class="sidebar_link">{{ virt_role }}</a>
</li>
{% endfor %}{% endif %}
+ {% block extranav %}{% endblock %}
</ul>
</div>
<div class="span10">
View
11 kitchen/templates/graph.html
@@ -1,12 +1,21 @@
{% extends "base.html" %}
+{% block extranav %}
+<li class="nav-header">
+ Options
+</li>
+<li {% if show_hostnames %} class="active" {% endif %}>
+ <a href="#" data-type="options" data-name="show_hostnames" class="sidebar_link">Show Hostnames</a>
+</li>
+{% endblock %}
+
{% block bodycontent %}
{% if msg %}{{ msg }}{% else %}<img src="/static/img/node_map.png">{% endif %}
{% endblock %}
{% block topnav %}
<ul class="nav">
- <li><a href="/?{{query_string}}">List</a></li>
+ <li><a href="/?{{ query_string }}">List</a></li>
<li class="active"><a href="/graph">Graph</a></li>
</ul>
{% endblock %}

0 comments on commit b865ccd

Please sign in to comment.