Commits

Kenneth Love committed 620dc14

added ability to refresh keys

Comments (0)

Files changed (5)

     keys = r.keys()
     return render_template('index.html', keys=keys)
 
+@app.route('/keys')
+def keys():
+    """ Get available keys. """
+    if not session.has_key('redis_db'):
+        set_session_defaults(session)
+    r = get_redis_connection(session)
+
+    keys = r.keys()
+    return jsonify(keys=keys)
+
+
 @app.route('/key/<key>')
 def key(key):
     """ Info for the key. """
     elif rtype == 'string':
         r.set(key, value)
 
-    #flash(key + ' was saved successfully')
-
     return jsonify(
         flash=key + ' was saved successfully',
-        value=value + 'boobs'
+        value=value
     )
 
 if __name__ == '__main__':

static/css/style.css

     .filterform input[type=search] {
       width:250px;
     }
+    #refresh_keys {
+      background:url('../img/loop.png') center center no-repeat;
+      display:block;
+      float:left;
+      height:20px;
+      margin-right:10px;
+      width:12px;
+      text-indent:-99999px;
+    }
   #keylist {
     border:1px solid rgba(30,30,30,0.5);
     clear:both;
       #keylist li.current a { font-weight:bold; }
       #keylist li a {
         color:#333;
+        display:block;
         text-decoration:none;
       }
 

static/img/loop.png

Old
Old image
New
New image

static/js/redbeard.js

             'class': 'filterinput',
             'type': 'search',
             'placeholder': 'Filter'
-        });
+        }),
+        refresh = $('<a>').attr({
+            'href': '/keys',
+            'id': 'refresh_keys',
+            'title': 'refresh available keys'
+        }).text('refresh keys');
 
-    $(form).append(input).appendTo(header);
+
+    $(form).append(refresh).append(input).appendTo(header);
 
     $(input).change(function() {
         var filter = $(this).val();
 }
 
 jQuery(window).hashchange(function() {
-    var link = '/key/' + window.location.hash.replace('#', '');
-    $.get(link, function(data) {
-        $('#right').html(data);
-    });
+    var hash = window.location.hash.replace('#', '');
+    if (hash != '') {
+        var link = '/key/' + hash;
+        $.get(link, function(data) {
+            $('#right').html(data);
+        });
+    } else {
+        $('#right').empty();
+    }
 });
 
 $(function() {
     $('#id_redis_db').live('change', function() {
         $(this).parent().parent('form').submit();
     });
+
+    $('#refresh_keys').live('click', function(e) {
+        var link = $(this).attr('href');
+        e.preventDefault();
+        $.get(link, function(data) {
+            $('#keylist').empty();
+            keys = []
+            for (i in data['keys']) {
+                keys.push('<li><a href="/key/' + data['keys'][i] + '">' + data['keys'][i] + '</a></li>');
+            }
+            $('#keylist').append(keys.join(''));
+            window.location.hash = '';
+        });
+    });
+
 });

templates/layout.html

 </head>
 <body>
 	<header id="masthead">
-		{% block header %}
+	{% block header %}
 		<h1 id="logo">RedBeard</h1>
 		{% if session %}
 		<aside>
 			</dl>
 		</aside>
 		{% endif %}
-		{% endblock %}
+	{% endblock %}
 	</header>
 
 	<form action="{{ url_for('change_db') }}" method="post" id="switch_db">