changeset 468:511a2a2e9950

paging of history results, currently without the option of setting count per page
author Akash Sinha <akash2607@gmail.com>
date Mon, 20 Jun 2011 11:18:18 +0530
parents 71988ea0f53e
children 82261b274b68
files MoinMoin/apps/frontend/views.py MoinMoin/templates/global_history.html MoinMoin/themes/modernized/static/css/common.css
diffstat 3 files changed, 60 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Tue Jun 14 17:27:42 2011 +0530
+++ b/MoinMoin/apps/frontend/views.py	Mon Jun 20 11:18:18 2011 +0530
@@ -636,6 +636,14 @@
         item_groups[item_name] = item_info
 
     # Grouping on the date basis
+    offset = request.values.get('offset', 0)
+    offset = int(offset)
+
+    count = 50 # something default
+    day_count = OrderedDict()
+    revcount = 0
+    maxrev = count + offset
+    toappend = True
     grouped_history = []
     prev_date = '0000-00-00'
     rev_tuple = namedtuple('rev_tuple', ['rev_date', 'item_revs'])
@@ -643,15 +651,45 @@
     for item_group in item_groups.values():
         tm = datetime.utcfromtimestamp(item_group["timestamp"])
         rev_date = format_date(tm)
-        if rev_date == prev_date:
+        if revcount < offset:
+            revcount += len(item_group["revnos"])
+            if rev_date not in day_count:
+                day_count[rev_date] = 0
+            day_count[rev_date] += len(item_group["revnos"])
+        elif rev_date == prev_date:
             rev_tuples.item_revs.append(item_group)
+            revcount += len(item_group["revnos"])
         else:
             grouped_history.append(rev_tuples)
-            rev_tuples = rev_tuple(rev_date, [item_group])
-            prev_date = rev_date
-    grouped_history.append(rev_tuples)
+            if revcount < maxrev:
+                rev_tuples = rev_tuple(rev_date, [item_group])
+                prev_date = rev_date
+                revcount += len(item_group["revnos"])
+            else:
+                toappend = False
+                break
+    if toappend:
+        grouped_history.append(rev_tuples)
+        revcount = 0 # this is the last page, no next page present
     del grouped_history[0]  # First tuple will be a null one
 
+    # calculate offset for previous page link
+    previous_offset = 0
+    prev_rev_count = day_count.values()
+    prev_rev_count.reverse()
+    for numrev in prev_rev_count:
+        if previous_offset < count:
+            previous_offset += numrev
+        else:
+            break
+
+    if offset - previous_offset >= count:
+        previous_offset = offset - previous_offset
+    elif previous_offset:
+        previous_offset = 0
+    else:
+        previous_offset = -1 # no previous page
+
     item_name = request.values.get('item_name', '') # actions menu puts it into qs
     current_timestamp = int(time.time())
     return render_template('global_history.html',
@@ -659,6 +697,8 @@
                            history=grouped_history,
                            current_timestamp=current_timestamp,
                            bookmark_time=bookmark_time,
+                           offset=revcount,
+                           previous_offset=previous_offset,
                           )
 
 @frontend.route('/+wanteds')
--- a/MoinMoin/templates/global_history.html	Tue Jun 14 17:27:42 2011 +0530
+++ b/MoinMoin/templates/global_history.html	Mon Jun 20 11:18:18 2011 +0530
@@ -7,7 +7,16 @@
 {% endblock %}
 
 {% block content %}
+<div class='moin-offset-links'>
+    {% if previous_offset >= 0 %}
+        <a href="{{ url_for('frontend.global_history', offset=previous_offset) }}" title="{{ _("Previous") }}">&laquo;</a>
+    {% endif %}
+    {% if offset %}
+        <a href="{{ url_for('frontend.global_history', offset=offset) }}" title="{{ _("Next") }}">&raquo;</a>
+    {% endif %}
+</div>
 <h1>{{ _("Global History") }}</h1>
+<div class='moin-clr'></div>
     {% if user.valid  %}
     <div id="moin-set-bookmark">
         {% if bookmark_time %}
@@ -68,7 +77,7 @@
             </div>
         {% endfor %}
     </div>
-   {% if bookmark_time %}
+   {% if bookmark_time and not offset %}
        <div id="moin-bookmark-reached">{{ _("Bookmark reached") }}</div>
    {% endif %}
 {% endblock %}
--- a/MoinMoin/themes/modernized/static/css/common.css	Tue Jun 14 17:27:42 2011 +0530
+++ b/MoinMoin/themes/modernized/static/css/common.css	Mon Jun 20 11:18:18 2011 +0530
@@ -230,11 +230,14 @@
 .moin-history-copy:before { content: url('../img/moin-new.png'); }
 .moin-integer { width: 2%; }
 .moin-history-links { width: 5%; }
-.moin-history-links a { display:block; margin-bottom: 4px; }
+.moin-history-links a { display: block; margin-bottom: 4px; }
 .moin-history-editortext,
 .moin-history-links span,
-.moin-history-comment span { color:#544E4F;  display:block; margin-bottom: 5px; }
-
+.moin-history-comment span { color: #544E4F; display: block; margin-bottom: 5px; }
+.moin-offset-links { float: right; margin-right: 20px; }
+.moin-offset-links a { margin-right: 10px; padding: 3px 7px; font-size: 20px; background: #FFFFFF; border: 1px groove #DDD; border-radius: 5px; }
+.moin-offset-links a:hover { box-shadow: 0px 0px 12px #81BBF2; }
+.moin-clr { clear: both; }
 
 /* diffs */
 .moin-diff { width:99%; table-layout: fixed; }