You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2012/12/14 23:43:10 UTC

git commit: [#4957] WIP - tool grouping

Updated Branches:
  refs/heads/tv/4957 [created] 27e8ee92c


[#4957] WIP - tool grouping


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/27e8ee92
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/27e8ee92
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/27e8ee92

Branch: refs/heads/tv/4957
Commit: 27e8ee92c655b417d69e9522fdedfad0750c7dc1
Parents: 60a070d
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Fri Dec 14 22:42:50 2012 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Dec 14 22:42:50 2012 +0000

----------------------------------------------------------------------
 Allura/allura/app.py                              |    4 ++-
 Allura/allura/controllers/project.py              |    8 ++++++
 Allura/allura/model/project.py                    |   17 ++++++++++++-
 Allura/allura/templates/jinja_master/top_nav.html |    2 +-
 Allura/allura/templates/tool_list.html            |   21 ++++++++++++++++
 5 files changed, 49 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/27e8ee92/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 613e88d..0d6f64f 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -33,7 +33,8 @@ class ConfigOption(object):
 
 class SitemapEntry(object):
 
-    def __init__(self, label, url=None, children=None, className=None, ui_icon=None, small=None):
+    def __init__(self, label, url=None, children=None, className=None,
+            ui_icon=None, small=None, tool_name=None):
         self.label = label
         self.className = className
         if url is not None:
@@ -44,6 +45,7 @@ class SitemapEntry(object):
         if children is None:
             children = []
         self.children = children
+        self.tool_name = tool_name
 
     def __getitem__(self, x):
         """

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/27e8ee92/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 9c3c5c5..85cde3a 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -254,6 +254,13 @@ class HostNeighborhoodController(WsgiDispatchController, NeighborhoodController)
     nf = NewForgeController()
     search = SearchController()
 
+class ToolListController(object):
+    @expose('jinja:allura:templates/tool_list.html')
+    def _default(self, tool_name, *args, **kw):
+        tool_name = tool_name.lower()
+        entries = [e for e in c.project.sitemap() if e.tool_name.lower() == tool_name]
+        return dict(entries=entries, type=entries[0].tool_name if entries else None)
+
 class ProjectController(object):
 
     def __init__(self):
@@ -261,6 +268,7 @@ class ProjectController(object):
         setattr(self, 'feed.atom', self.feed)
         setattr(self, '_nav.json', self._nav)
         self.screenshot = ScreenshotsController()
+        self._list = ToolListController()
 
     @expose('json:')
     def _nav(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/27e8ee92/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index c3ac033..6cec12e 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -418,7 +418,8 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             if app.is_visible_to(c.user):
                 for sm in app.main_menu():
                     entry = sm.bind_app(app)
-                    entry.ui_icon='tool-%s' % ac.tool_name.lower()
+                    entry.tool_name = ac.tool_name
+                    entry.ui_icon = 'tool-%s' % entry.tool_name.lower()
                     ordinal = int(ac.options.get('ordinal', 0)) + delta_ordinal
                     if ordinal > max_ordinal:
                         max_ordinal = ordinal
@@ -431,6 +432,20 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         entries = sorted(entries, key=lambda e: e['ordinal'])
         return [e['entry'] for e in entries]
 
+    def grouped_sitemap(self):
+        from collections import Counter
+        sitemap = self.sitemap()
+        seen_types = set()
+        counts = Counter([e.tool_name.lower() for e in sitemap])
+        for e in sitemap:
+            tool_name = e.tool_name.lower()
+            if tool_name not in seen_types:
+                if counts.get(tool_name, 1) > 1:
+                    e.label = e.tool_name
+                    e.url = self.url() + '_list/' + tool_name
+                yield e
+            seen_types.add(tool_name)
+
     def parent_iter(self):
         yield self
         pp = self.parent_project

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/27e8ee92/Allura/allura/templates/jinja_master/top_nav.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/top_nav.html b/Allura/allura/templates/jinja_master/top_nav.html
index dfa288a..ff33995 100644
--- a/Allura/allura/templates/jinja_master/top_nav.html
+++ b/Allura/allura/templates/jinja_master/top_nav.html
@@ -1,5 +1,5 @@
 {% if c.project %}
-  {% for s in c.project.sitemap() %}
+  {% for s in c.project.grouped_sitemap() %}
     <a href="{{s.url}}" class="ui-icon-{{s.ui_icon or 'admin'}}">
       {{s.label}}
       {% if s.label == 'Home' %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/27e8ee92/Allura/allura/templates/tool_list.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/tool_list.html b/Allura/allura/templates/tool_list.html
new file mode 100644
index 0000000..53dda66
--- /dev/null
+++ b/Allura/allura/templates/tool_list.html
@@ -0,0 +1,21 @@
+{% set hide_left_bar = True %}
+{% extends g.theme.master %}
+
+{% block title %}{{c.project.name}} / {{type}} tools{% endblock %}
+
+{% block extra_css %}
+{% endblock %}
+
+{% block inner_grid %}{% endblock %}
+{% block header_classes %} colored{% endblock %}
+{% block header %}{{type}} tools{% endblock %}
+
+{% block content %}
+<div>
+  <ul>
+  {% for e in entries %}
+    <li><a href="{{e.url}}">{{e.label}}</a></li>
+  {% endfor %}
+  </ul>
+</div>
+{% endblock %}