bcdc35f68d5d

web: add pagination
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 13 Jun 2010 14:37:52 -0400
parents 80d65cd81298
children 13b6260aed99
branches/tags (none)
files review/static/style.css review/static/style.less review/templates/index.html review/web_ui.py

Changes

--- a/review/static/style.css	Sun Jun 13 13:39:58 2010 -0400
+++ b/review/static/style.css	Sun Jun 13 14:37:52 2010 -0400
@@ -203,6 +203,7 @@
 }
 #index .content table tr td.node {
   padding-left: 0px;
+  width: 110px;
 }
 #index .content table tr td.node .rev {
   font-weight: bold;
@@ -247,6 +248,9 @@
 #index .content table tr td.stats .badge:hover {
   text-decoration: none;
 }
+#index .content .pagination a.older {
+  float: right;
+}
 #changeset .content .fulldesc {
   font-size: 18px;
   line-height: 1.25;
--- a/review/static/style.less	Sun Jun 13 13:39:58 2010 -0400
+++ b/review/static/style.less	Sun Jun 13 14:37:52 2010 -0400
@@ -240,6 +240,7 @@
                 }
                 &.node {
                     padding-left: 0px;
+                    width: 110px;
 
                     .rev {
                         font-weight: bold;
@@ -289,6 +290,11 @@
             }
         }
     }
+    .pagination {
+        a.older {
+            float: right;
+        }
+    }
 }
 #changeset .content {
     .fulldesc {
--- a/review/templates/index.html	Sun Jun 13 13:39:58 2010 -0400
+++ b/review/templates/index.html	Sun Jun 13 14:37:52 2010 -0400
@@ -39,4 +39,13 @@
             </tr>
         {% endfor %}
     </table>
+
+    <div class="pagination group">
+        {% if not older < 0 %}
+            <a class="older" href="/{{ older }}/">Older Changesets &rArr;</a>
+        {% endif %}
+        {% if not newer < 0 %}
+            <a class="newer" href="/{{ newer }}/">&lArr; Newer Changesets</a>
+        {% endif %}
+    </div>
 {% endblock %}
--- a/review/web_ui.py	Sun Jun 13 13:39:58 2010 -0400
+++ b/review/web_ui.py	Sun Jun 13 14:37:52 2010 -0400
@@ -33,7 +33,7 @@
 from flask import abort, redirect, render_template, request
 app = Flask(__name__)
 
-LOG_PAGE_LEN = 1000000
+LOG_PAGE_LEN = 15
 
 def _item_gravatar(item):
     return 'http://www.gravatar.com/avatar/%s?s=30' % md5(email(item.author)).hexdigest()
@@ -66,11 +66,27 @@
 
 
 @app.route('/')
-def index():
-    rev_max = app.datastore.target['tip'].rev()
+def index_newest():
+    return index(-1)
+
+@app.route('/<int:rev_max>/')
+def index(rev_max):
+    tip = app.datastore.target['tip'].rev()
+
+    if rev_max > tip or rev_max < 0:
+        rev_max = tip
+
     rev_min = rev_max - LOG_PAGE_LEN if rev_max >= LOG_PAGE_LEN else 0
-    rcsets = [app.datastore[r] for r in xrange(rev_max, rev_min, -1)]
-    return _render('index.html', rcsets=rcsets)
+    if rev_min < 0:
+        rev_min = 0
+
+    older = rev_min - 1 if rev_min > 0 else -1
+    newer = rev_max + LOG_PAGE_LEN + 1 if rev_max < tip else -1
+    if newer > tip:
+        newer = tip
+
+    rcsets = [app.datastore[r] for r in xrange(rev_max, rev_min - 1, -1)]
+    return _render('index.html', rcsets=rcsets, newer=newer, older=older)
 
 
 def _handle_signoff(revhash):