Commits

Kenneth Love committed 38ec8ba

added ability to load the rest of the keys

Comments (0)

Files changed (3)

     if not r:
         return redirect(url_for('setup'))
 
-    keys = r.keys()
-    if len(keys) > 500:
-        keys = keys[:500]
-    return render_template('index.html', keys=keys)
+    return render_template('index.html')
 
 @app.route('/keys')
-def keys():
+@app.route('/keys/<amount>')
+def keys(amount=None):
     """ Get available keys. """
     if not session.has_key('redis_db'):
         set_session_defaults(session)
     if not r:
         return redirect(url_for('setup'))
 
-    keys = r.keys()
-    return jsonify(keys=keys)
+    total_keys = len(r.keys())
+    if not amount:
+        initial_keys = r.keys()[:500]
+    else:
+        initial_keys = r.keys()
+    return jsonify(total_keys=total_keys, initial_keys=initial_keys)
 
 @app.route('/key/<key>')
 def key(key):

static/css/style.css

         text-decoration:none;
         word-break:break-all;
       }
+    #keylist li.paginator {
+      cursor:pointer;
+      font-style:italic;
+      text-align:center;
+    }
 
 #cancel {
   background:url('../img/cancel.png') center center no-repeat;

static/js/redbeard.js

     $(window).hashchange();
 }
 
+function load_keys(all) {
+    var keys_url = '/keys';
+
+    if (all) {
+        keys_url += '/all';
+    }
+
+    var jqxhr = $.getJSON(keys_url)
+        .success(function(data) {
+            var items = [];
+            $.each(data['initial_keys'], function(key, value) {
+                items.push('<li><a href="/key/' + value + '">' + value + '</a></li>');
+            });
+            $("#keylist").empty().html(items.join(''));
+            if (data['initial_keys'].length != data['total_keys']) {
+                $("#keylist")
+                    .append('<li class="paginator">' + data['initial_keys'].length + ' of ' + data['total_keys'] + '. Click to load the rest.</li>')
+                    .click(function() { load_keys(all=true); });
+            }
+        })
+        .error(function() {
+            $("#keylist").empty().html('<li>An error occurred. Make sure redis running and reload the page.</li>');
+        });
+}
+
 function listFilter(header, list) {
     var form = $('<form>').attr({'class': 'filterform', 'action': '#'}),
         input = $('<input>').attr({
         });
     });
 
+    load_keys();
     $(window).hashchange();
 
     $('#id_redis_db').live('change', function() {
         $.get(link, function(data) {
             $('#keylist').empty();
             keys = []
-            for (i in data['keys']) {
+            for (i in data['initial_keys']) {
                 keys.push('<li><a href="/key/' + data['keys'][i] + '">' + data['keys'][i] + '</a></li>');
             }
             $('#keylist').append(keys.join(''));