changeset 460:72dbe801338e

Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
author Akash Sinha <akash2607@gmail.com>
date Sat, 04 Jun 2011 03:24:49 +0530
parents a4afec9ff526
children be9511c527b0
files MoinMoin/apps/frontend/views.py MoinMoin/templates/global_history.html MoinMoin/themes/modernized/static/css/common.css
diffstat 3 files changed, 133 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sat Jun 04 03:14:15 2011 +0530
+++ b/MoinMoin/apps/frontend/views.py	Sat Jun 04 03:24:49 2011 +0530
@@ -18,6 +18,7 @@
 from flaskext.babel import format_date
 from datetime import datetime
 from itertools import chain
+from  collections import OrderedDict
 
 from flask import request, url_for, flash, Response, redirect, session, abort, jsonify
 from flask import current_app as app
@@ -36,12 +37,12 @@
 logging = log.getLogger(__name__)
 
 from MoinMoin.i18n import _, L_, N_
-from MoinMoin.themes import render_template
+from MoinMoin.themes import render_template, get_editor_info
 from MoinMoin.apps.frontend import frontend
 from MoinMoin.items import Item, NonExistent
 from MoinMoin.items import ROWS_META, COLS, ROWS_DATA
 from MoinMoin import config, user, wikiutil
-from MoinMoin.config import CONTENTTYPE, ITEMLINKS, ITEMTRANSCLUSIONS
+from MoinMoin.config import ACTION, COMMENT, CONTENTTYPE, ITEMLINKS, ITEMTRANSCLUSIONS, NAME
 from MoinMoin.util.forms import make_generator
 from MoinMoin.util import crypto
 from MoinMoin.security.textcha import TextCha, TextChaizedForm, TextChaValid
@@ -546,22 +547,86 @@
 @frontend.route('/+history')
 def global_history():
     history = flaskg.storage.history(item_name='')
+    item_dict = OrderedDict()
+    for rev in history:
+        current_item_name = rev.item.name
+        if current_item_name in item_dict:
+            item_dict[current_item_name].append(rev)
+        else:
+           item_dict[current_item_name] = [rev]
+
+    # Got the item dict, now doing grouping inside them
+    for  key, value in item_dict.items():
+        editors_dict = OrderedDict()
+        editors = []
+        revnos = []
+        comments = []
+        current_rev = value[0]
+        item_timestamp = current_rev.timestamp
+        item_contenttype = current_rev.get(CONTENTTYPE)
+        action = current_rev.get(ACTION)
+        name = current_rev.get(NAME)
+
+        # Aggregating comments,authors and revno
+        item_num = 1
+        for rev in value:
+            revnos.append(rev.revno)
+            comment = rev.get(COMMENT)
+            if comment:
+                comment = "#"+str(item_num)+" "+comment
+                comments.append(comment)
+            editor = get_editor_info(rev, external=True)
+            editor_name = editor["name"]
+            if editor_name in editors_dict:
+               editors_dict[editor_name][1].append(item_num)
+            else:
+                editors_dict[editor_name] = (editor, [item_num])
+            item_num = item_num + 1
+
+        if item_num == 2: # there is only one revision for that item
+            editor_tuple = (editors_dict.values())[0]
+            info = editor_tuple[0]
+            info_tuple = (info, "")
+            editors.append(info_tuple)
+        else:
+            # Find the revision number for each editor
+            for editor_tuple in editors_dict.values():
+                positions = editor_tuple[1]
+                pos_str = str(positions[0])
+                i = 0
+                for position in positions[1:]:
+                    i = i + 1
+                    if position == (positions[i-1]+1):
+                        if i < (len(positions)-1) and  position == (positions[i+1]-1):
+                            continue
+                        else:
+                            pos_str += "-"+str(position)
+                    else:
+                        pos_str += ","+str(position)
+                pos_str = "["+pos_str+"]"
+                info = editor_tuple[0]
+                info_tuple = (info, pos_str)
+                editors.append(info_tuple)
+        item_dict[key]= (key, item_timestamp, action, name, item_contenttype, revnos, editors, comments)
+
+    # Grouping on the date basis
     history_list = []
     prev_date = '0000-00-00'
-    temp_list = []
-    for rev in history:
-        tm = datetime.utcfromtimestamp(rev.timestamp)
+    item_list = []
+    for item in item_dict.values():
+        tm = datetime.utcfromtimestamp(item[1])
         rev_date = format_date(tm)
         if rev_date == prev_date:
-            temp_list.append(rev)
+            item_list.append(item)
         else:
-            history_list.append(temp_list)
-            temp_list = []
-            temp_list.append(rev_date)
-            temp_list.append(rev)
+            history_list.append(item_list)
+            item_list = []
+            item_list.append(rev_date)
+            item_list.append(item)
             prev_date = rev_date
-    history_list.append(temp_list)
-    del history_list[0]  # First item will be a empty one
+    history_list.append(item_list)
+    del history_list[0]  # First item will be a empty one 
+
     item_name = request.values.get('item_name', '') # actions menu puts it into qs
     return render_template('global_history.html',
                            item_name=item_name, # XXX no item
--- a/MoinMoin/templates/global_history.html	Sat Jun 04 03:14:15 2011 +0530
+++ b/MoinMoin/templates/global_history.html	Sat Jun 04 03:24:49 2011 +0530
@@ -18,14 +18,53 @@
                     <table>
                     {% for rev in revs %}
                      <tr>
-                         <td class="moin-action moin-history-{{ rev.action|lower }}" title="{{ rev.action }}">&nbsp;</td>
-                         <td class="moin-history-item"><a href="{{ url_for('frontend.show_item', item_name=rev.item.name) }}">{{ rev.item.name }}</a>
-                             {% if rev.item.name != rev.name %} ({{ rev.name }}){% endif %}</td>
-                         <td class="moin-history-time">{{ rev.timestamp|timeformat }}</td>
-                         <td class="moin-integer">{{ rev.revno }}</td>
-                         <td class="moin-wordbreak moin-history-contenttype">{{ rev.contenttype }}</td>
-                         <td class="moin-wordbreak moin-history-editorinfo">{{ utils.editor_info(rev) }}</td>
-                         <td class="moin-wordbreak moin-history-comment">{{ rev.comment }}</td>
+                        {% set item_name = rev[0] %}
+                        {% set timestamp = rev[1] %}
+                        {% set action = rev[2] %}
+                        {% set contenttype = rev[4] %}
+                         <td class="moin-action moin-history-{{ rev[2]|lower }}" title="{{ rev[2] }}">&nbsp;</td>
+                         <td class="moin-history-item"><a href="{{ url_for('frontend.show_item', item_name=rev[0]) }}">{{ rev[0] }}</a>
+                         <td class="moin-history-time">{{ rev[1]|timeformat }}</td>
+                         <td class="moin-wordbreak moin-history-contenttype">{{ rev[4] }}</td>
+                         <td class="moin-history-links">
+                             {% set revnos = rev[5] %}
+                             {% for revno in revnos %}
+                                 {% if revno - 1 > -1 %}
+                                     <a href="{{ url_for('frontend.diff', item_name=rev[0],rev1=revno,rev2=revno-1) }}">{{ _("[%(revno)s]", revno=(revno-1)) }}</a>
+                                 {% else %}
+                                     <span>{{ _("None") }}</span>
+                                 {% endif %}
+                             {% endfor %}
+                         </td>
+                         <td class="moin-wordbreak moin-history-editorinfo">
+                             {% set editors = rev[6] %}
+                             {% for editor in editors %}
+			         <span class="moin-history-editortext">
+                                 {% set info = editor[0] %}
+                                 {% set position = editor[1] %}
+			         {% if "uri" in info %}
+			             <a href="{{ info["uri"] }}" class="{{ info["css"] }}" title="{{ info["title"] }}">
+			         {% elif "email" in info %}
+			             <a href="mailto:{{ info["email"] }}" class="{{ info["css"] }}" title="{{ info["title"] }}">
+			         {% else %}
+			             <span class="{{ info["css"] }}" title="{{ info["title"] }}">
+			         {% endif %}
+			         {{ info["text"] }}
+			         {% if ("uri" in info)  or ("email" in info) %}
+			             </a>
+			         {% else %}
+			             </span>
+			         {% endif %}
+			         {{ _("%(position)s",position=position) }}
+			         </span>
+			     {% endfor %}
+                         </td>
+                         <td class="moin-wordbreak moin-history-comment">
+                             {% set comments = rev[7] %}
+                             {% for comment in comments %}
+                                 <span>{{ comment }}</span>
+			     {% endfor %}
+                        </td>
                      </tr>
                     {% endfor %}
                     </table>
--- a/MoinMoin/themes/modernized/static/css/common.css	Sat Jun 04 03:14:15 2011 +0530
+++ b/MoinMoin/themes/modernized/static/css/common.css	Sat Jun 04 03:24:49 2011 +0530
@@ -216,17 +216,23 @@
 .moin-wordbreak { word-break: break-all;  word-wrap: break-word; } /* Firefox needs javascript assistance within tables */
 .moin-history-time { width: 10%; }
 .moin-history-contenttype { width: 18%; }
-.moin-history-editorinfo { width: 10%; }
-.moin-history-comment { width: 18%; }
+.moin-history-editorinfo { width: 17%; }
+.moin-history-comment { width: 25%; }
 .moin-action { width: 2%; }
 .moin-history-container { border: 1px solid #4D7DA9; }
 .moin-history-container-header { background: #81BBF2; margin: 0px; padding: 3px; color: #3b3131; border-bottom: 1px solid #4D7DA9; }
-.moin-history-container-body { padding: 4px; }
+.moin-history-container-body { padding: 4px; font-size: 14px; }
 .moin-history-save:before { content: url('../img/moin-edit.png'); }
 .moin-history-trash:before { content: url('../img/moin-deleted.png'); }
 .moin-history-rename:before { content: url('../img/moin-renamed.png'); }
 .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-editortext,
+.moin-history-links span,
+.moin-history-comment span { color:#544E4F;  display:block; margin-bottom: 5px; }
+
 
 /* diffs */
 .moin-diff { width:99%; table-layout: fixed; }