changeset 477:72899d48db41

alphabetic listing of global index, with link to item index
author Akash Sinha <akash2607@gmail.com>
date Thu, 07 Jul 2011 03:36:08 +0530
parents a716e61ae9c7
children 20a940e54ffb
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py MoinMoin/templates/global_index.html MoinMoin/themes/modernized/static/css/common.css
diffstat 4 files changed, 79 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Wed Jun 29 02:25:05 2011 +0530
+++ b/MoinMoin/apps/frontend/views.py	Thu Jul 07 03:36:08 2011 +0530
@@ -486,11 +486,33 @@
 @frontend.route('/+index')
 def global_index():
     item = Item.create('') # XXX hack: item_name='' gives toplevel index
-    index = item.flat_index()
+    startswith = request.values.get('startswith', None)
+    index = item.flat_index(startswith)
+    if startswith:
+        initials = item.name_initial(item.flat_index())
+        # if startswith was set, we would get the filtered index above
+        # so inorder to get initial of all elements we need all index, not filtered one
+    else:
+        initials = item.name_initial(index)
+    initials = [initial.upper() for initial in initials]
+    initials = list(set(initials))
+    initials.sort()
+    index_more_links = []
+    for fullname, relname, contenttype in index:
+        test_item = item.create(fullname)
+        item_index = test_item.flat_index()
+        hassubitem = False
+        if item_index:
+            hassubitem = True
+        index_more_links.append((fullname, relname, contenttype, hassubitem))
+    index_more_links.sort()
+
     item_name = request.values.get('item_name', '') # actions menu puts it into qs
     return render_template('global_index.html',
                            item_name=item_name, # XXX no item
-                           index=index,
+                           index=index_more_links,
+                           initials=initials,
+                           startswith=startswith,
                           )
 
 
--- a/MoinMoin/items/__init__.py	Wed Jun 29 02:25:05 2011 +0530
+++ b/MoinMoin/items/__init__.py	Thu Jul 07 03:36:08 2011 +0530
@@ -575,15 +575,26 @@
                  for item in item_iterator]
         return sorted(items)
 
-    def flat_index(self):
+    def flat_index(self, startswith=None):
         index = self.get_index()
-        index = [(fullname, relname, contenttype)
-                 for fullname, relname, contenttype in index
-                 if u'/' not in relname]
+        if startswith:
+            startswith = (u'%s' % startswith, u'%s' % startswith.swapcase())
+            index = [(fullname, relname, contenttype)
+                     for fullname, relname, contenttype in index
+                     if u'/' not in relname and relname.startswith(startswith)]
+        else:
+            index = [(fullname, relname, contenttype)
+                     for fullname, relname, contenttype in index
+                     if u'/' not in relname]
+
         return index
 
     index_template = 'index.html'
 
+    def name_initial(self, names=None):
+        initials = [(name[1][0])
+                   for name in names]
+        return initials
 
 class NonExistent(Item):
     contenttype_groups = [
--- a/MoinMoin/templates/global_index.html	Wed Jun 29 02:25:05 2011 +0530
+++ b/MoinMoin/templates/global_index.html	Thu Jul 07 03:36:08 2011 +0530
@@ -3,15 +3,38 @@
 {% block item %}
     <h1>{{ _("Global Index") }}</h1>
     {% if index %}
-        <ul>
-        {% for fullname, relname, contenttype in index %}
-            <li>
-                <a href="{{ url_for('show_item', item_name=fullname) }}"
-                   class="{{ contenttype|contenttype_to_class }}">
-                    {{ relname }}
+    <div id="moin-letters">
+        {% if not startswith %}
+            <a class="selected" href="{{ url_for('frontend.global_index') }}">{{ _("All") }}</a>
+        {% else %}
+            <a href="{{ url_for('frontend.global_index') }}">{{ _("All") }}</a>
+        {% endif %}
+        {% for initial in initials %}
+            {% if startswith == initial %}
+                <a class="selected" href="{{ url_for('frontend.global_index', startswith=initial) }}">{{ initial }}</a>
+            {% else %}
+                <a  href="{{ url_for('frontend.global_index', startswith=initial) }}">{{ initial }}</a>
+            {% endif %}
+        {% endfor %}
+    </div>
+    <div id="moin-global-index">
+        {% set maxchars = 20 %}
+        {% for fullname, relname, contenttype, hassubitem in index %}
+            <div>
+                <a href="{{ url_for('show_item', item_name=fullname) }}" 
+                   class="{{ contenttype|contenttype_to_class }}"
+                   title="{{ relname }}">
+                   {{ relname|truncate(maxchars, true, '..') }}
                 </a>
-            </li>
+                {% if hassubitem %}
+                    <a href="{{ url_for('frontend.index', item_name=fullname) }}" 
+                       title="{{ _("More") }}"
+                       class="moin-more-index">
+                </a>
+                {% endif %}
+            </div>
         {% endfor %}
-        </ul>
+    </div>
+    <div class="moin-clr"></div>
     {% endif %}
 {% endblock %}
--- a/MoinMoin/themes/modernized/static/css/common.css	Wed Jun 29 02:25:05 2011 +0530
+++ b/MoinMoin/themes/modernized/static/css/common.css	Thu Jul 07 03:36:08 2011 +0530
@@ -240,6 +240,15 @@
 .moin-offset-links a:hover { box-shadow: 0px 0px 12px #81BBF2; }
 .moin-clr { clear: both; }
 
+/* global index page */
+#moin-letters { width: 90%; margin: 5px auto; text-align: center; }
+#moin-letters a { display: inline-block; margin: 0; padding: 4px 5px; }
+#moin-letters a:hover,
+#moin-letters a.selected { background: #4477FF; border-radius: 5px; color: #FFFFFF; text-decoration: none; }
+#moin-global-index { width: 100%; margin-left: 0.5em; }
+#moin-global-index div { float: left; width: 15em; }
+.moin-more-index:before { content: url("../img/moin-expand.png"); }
+
 /* diffs */
 .moin-diff { width:99%; table-layout: fixed; }
 .moin-diff-header { vertical-align: top; font-size: 92%; }